Commit d9e5263
Changed files (10)
src/bridge/miaomiao.py → src/bridge/ocr.py
@@ -11,11 +11,11 @@ from config import ENABLE, PREFIX, cache
from message_utils import send2tg
from utils import i_am_bot
-BOT_NAME = "GLBetabot"
+OCR_BOT = "GLBetabot"
@cache.memoize(ttl=10)
-async def ocr_to_miaomiao(client: Client, message: Message, **kwargs):
+async def send_to_ocr_bridge(client: Client, message: Message, **kwargs):
"""Send photo to miaomiao bot for OCR.
See docs in `bridge/README.md` for details.
@@ -42,14 +42,14 @@ async def ocr_to_miaomiao(client: Client, message: Message, **kwargs):
cid = kwargs.get("target_chat", message.chat.id) # MSG-A's cid
mid = kwargs.get("reply_msg_id", message.id) # MSG-A's mid
msg += f" \n#ID=({cid},{mid})".replace("None", "0")
- logger.warning(f"OCR via 妙妙小工具 (@{BOT_NAME}): {msg!r}")
- await client.send_photo(chat_id=f"@{BOT_NAME}", photo=img, caption=msg)
+ logger.warning(f"OCR via 妙妙小工具 (@{OCR_BOT}): {msg!r}")
+ await client.send_photo(chat_id=f"@{OCR_BOT}", photo=img, caption=msg)
@cache.memoize(ttl=10)
-async def forward_results_from_miaomiao(client: Client, message: Message):
+async def forward_ocr_results(client: Client, message: Message):
"""See docs in `bridge/README.md` for details."""
- if message.from_user.username != BOT_NAME or not message.reply_to_message:
+ if message.from_user.username != OCR_BOT or not message.reply_to_message:
return
reply_msg = message.reply_to_message
reply_msg_text = reply_msg.text or reply_msg.caption or ""
@@ -60,5 +60,5 @@ async def forward_results_from_miaomiao(client: Client, message: Message):
target_mid = int(matched.group(2)) if int(matched.group(2)) != 0 else None # MSG-A's mid
cid = message.chat.id # result's cid
mid = message.id # result's mid
- logger.info(f"Forwarding chat=@{BOT_NAME}, id={mid} -> chat={target_cid}, id={target_mid}")
+ logger.info(f"Forwarding chat=@{OCR_BOT}, id={mid} -> chat={target_cid}, id={target_mid}")
await client.copy_message(chat_id=target_cid, from_chat_id=cid, message_id=mid, reply_parameters=ReplyParameters(message_id=target_mid)) # type: ignore
src/others/download_external.py
@@ -50,7 +50,7 @@ async def download_url_in_message(client: Client, message: Message, **kwargs):
Path(path).rename(Path(path).with_suffix(suffix))
path = Path(path).with_suffix(suffix)
if img := validate_img(path, delete=False):
- await modify_progress(text=f"🖼图片下载成功: {readable_size(path=img)}", force_update=True, **kwargs)
+ await modify_progress(text=f"🏞图片下载成功: {readable_size(path=img)}", force_update=True, **kwargs)
success = await send2tg(client, message, target_chat, reply_msg_id, texts=url, media=[{"photo": img}])
elif Path(path).suffix in [".m4a", ".mp3", ".wav", ".ogg", ".opus", ".flac", ".aac"]:
await modify_progress(text=f"🎧音频下载成功: {readable_size(path=path)}", force_update=True, **kwargs)
src/preview/douyin.py
@@ -8,7 +8,7 @@ from loguru import logger
from pyrogram.client import Client
from pyrogram.types import Message
-from bridge.parsehub import send_to_parsehub
+from bridge.social import send_to_socia_media_bridge
from config import API, DB, TOKEN, TZ, cache
from database import get_db
from message_utils import copy_messages_from_db, modify_progress, save_messages, send2tg, summay_media
@@ -73,7 +73,7 @@ async def preview_douyin(
logger.warning(f"{platform} API [tikhub] failed: {resp}")
if fallback:
await modify_progress(text="❌抖音解析失败, 尝试第三方Bot...", **kwargs)
- await send_to_parsehub(client, message, text=url, **kwargs)
+ await send_to_socia_media_bridge(client, message, text=url, **kwargs)
await modify_progress(del_status=True, **kwargs)
return
src/preview/instagram.py
@@ -10,7 +10,7 @@ from loguru import logger
from pyrogram.client import Client
from pyrogram.types import Message
-from bridge.parsehub import send_to_parsehub
+from bridge.social import send_to_socia_media_bridge
from config import API, DB, DOWNLOAD_DIR, TOKEN, TZ, UA, cache
from database import get_db
from message_utils import copy_messages_from_db, modify_progress, save_messages, send2tg, summay_media
@@ -117,7 +117,7 @@ async def preview_ddinstagram(client: Client, message: Message, url: str, post_t
resp = await hx_req(api_url, headers=headers)
if not resp.text:
if fallback:
- await send_to_parsehub(client, message, text=url, **kwargs)
+ await send_to_socia_media_bridge(client, message, text=url, **kwargs)
return
soup = BeautifulSoup(resp.text, "html.parser")
@@ -136,7 +136,7 @@ async def preview_ddinstagram(client: Client, message: Message, url: str, post_t
raw_url = f"{API.DDINSTAGRAM}{img_url}"
media["photo"] = await download_file(raw_url, path=f"{DOWNLOAD_DIR}/{post_id}.jpg", workers_proxy=True, **kwargs)
if not bool(validate_img(media["photo"])):
- await send_to_parsehub(client, message, text=url, **kwargs)
+ await send_to_socia_media_bridge(client, message, text=url, **kwargs)
return
if tag := soup.find("meta", attrs={"property": "og:video"}):
@@ -145,7 +145,7 @@ async def preview_ddinstagram(client: Client, message: Message, url: str, post_t
raw_url = f"{API.DDINSTAGRAM}{video_url}"
media["video"] = await download_file(raw_url, path=f"{DOWNLOAD_DIR}/{post_id}.mp4", workers_proxy=True, **kwargs)
if not is_valid_video(media["video"]):
- await send_to_parsehub(client, message, text=url, **kwargs)
+ await send_to_socia_media_bridge(client, message, text=url, **kwargs)
return
await send2tg(client, message, texts=texts, media=[media], **kwargs)
src/preview/twitter.py
@@ -119,7 +119,7 @@ async def preview_twitter(client: Client, message: Message, url: str = "", db_ke
if device := master_info.get("device"):
msg += f"📱{device}"
if part_strs["first"]:
- msg += f"\n🖼{part_strs['first']}属于主推"
+ msg += f"\n🏞{part_strs['first']}属于主推"
if texts := master_info.get("texts"):
msg += f"\n{texts}"
if comments := master_info.get("comments"):
@@ -150,7 +150,7 @@ async def preview_twitter(client: Client, message: Message, url: str = "", db_ke
if device := this_info.get("device"):
msg += f"📱{device}"
if part_strs["middle"] and (this_info["has_master"] or this_info["has_quote"]): # 当有supp_info时, 附加图片数量说明
- msg += f"\n🖼{part_strs['middle']}属于{this_tweet_type}"
+ msg += f"\n🏞{part_strs['middle']}属于{this_tweet_type}"
if texts := this_info.get("texts"):
msg += f"\n{texts}"
@@ -180,7 +180,7 @@ async def preview_twitter(client: Client, message: Message, url: str = "", db_ke
msg += f"📱{device}"
if part_strs["last"]:
- msg += f"\n🖼{part_strs['last']}属于引推"
+ msg += f"\n🏞{part_strs['last']}属于引推"
if texts := quote_info.get("texts"):
msg += f"\n{texts}"
src/preview/weibo.py
@@ -13,7 +13,7 @@ from loguru import logger
from pyrogram.client import Client
from pyrogram.types import Message
-from bridge.parsehub import send_to_parsehub
+from bridge.social import send_to_socia_media_bridge
from config import API, DB, DOWNLOAD_DIR, TOKEN, TZ, cache
from cookies import get_weibo_cookies
from database import get_db
@@ -52,7 +52,7 @@ async def preview_weibo(client: Client, message: Message, url: str, post_id: str
if error_msg := this_info.get("error_msg"):
if this_info.get("fallback", fallback):
await modify_progress(text=f"❌微博解析失败: {error_msg}\n\n尝试第三方Bot...", **kwargs)
- await send_to_parsehub(client, message, text=url, **kwargs)
+ await send_to_socia_media_bridge(client, message, text=url, **kwargs)
else:
await modify_progress(text=f"❌微博解析失败: {error_msg}", **kwargs)
await asyncio.sleep(3)
@@ -81,7 +81,7 @@ async def preview_weibo(client: Client, message: Message, url: str, post_id: str
if device := this_info.get("device"):
msg += f"\n📱{device}"
if part_strs["first"] and quote_info: # 当有quote_info时, 附加图片数量说明:
- msg += f"\n🖼{part_strs['first']}属于本帖"
+ msg += f"\n🏞{part_strs['first']}属于本帖"
if texts := this_info.get("texts"):
msg += f"\n{texts}"
@@ -102,7 +102,7 @@ async def preview_weibo(client: Client, message: Message, url: str, post_id: str
msg += f"\n📱{device}"
if part_strs["last"]:
- msg += f"\n🖼{part_strs['last']}属于转帖"
+ msg += f"\n🏞{part_strs['last']}属于转帖"
if texts := quote_info.get("texts"):
msg += f"\n{texts}"
src/preview/xiaohongshu.py
@@ -10,7 +10,7 @@ from loguru import logger
from pyrogram.client import Client
from pyrogram.types import Message
-from bridge.parsehub import send_to_parsehub
+from bridge.social import send_to_socia_media_bridge
from config import DB, PROXY, TZ, UA, cache
from database import get_db
from message_utils import copy_messages_from_db, modify_progress, save_messages, send2tg, summay_media
@@ -51,7 +51,7 @@ async def preview_xhs(client: Client, message: Message, url: str = "", db_key: s
if not note:
if fallback:
await modify_progress(text="❌小红书解析失败, 尝试第三方Bot...", **kwargs)
- await send_to_parsehub(client, message, text=url, **kwargs)
+ await send_to_socia_media_bridge(client, message, text=url, **kwargs)
await asyncio.sleep(3)
else:
await modify_progress(text="❌小红书解析失败, 请稍候再尝试", **kwargs)
src/handler.py
@@ -6,7 +6,7 @@ from pyrogram.client import Client
from pyrogram.types import Message
from asr.voice_recognition import voice_to_text
-from bridge.miaomiao import ocr_to_miaomiao
+from bridge.ocr import send_to_ocr_bridge
from config import ENABLE, PREFIX, PROXY, cache
from database import del_db
from message_utils import equal_prefix, parse_msg, send2tg, startswith_prefix
@@ -70,7 +70,7 @@ async def handle_utilities(
if wget:
await download_url_in_message(client, message, **kwargs) # /wget
if ocr:
- await ocr_to_miaomiao(client, message) # /ocr
+ await send_to_ocr_bridge(client, message) # /ocr
@cache.memoize(ttl=60)
@@ -188,21 +188,21 @@ def get_social_media_help(cmd_prefix: list[str] | None = None, ignore_prefix: li
msg += f"\n🔗命令前缀: {', '.join(prefixes)}"
msg += "\n🔄使用 `/retry` 回复消息强制重试"
if ENABLE.YOUTUBE:
- msg += "\n✅油管"
+ msg += "\n🔴油管"
if ENABLE.BILIBILI:
- msg += "\n✅哔哩哔哩"
+ msg += "\n🅱️哔哩哔哩"
if ENABLE.TWITTER:
- msg += "\n✅推特"
+ msg += "\n🕊推特"
if ENABLE.WEIBO:
- msg += "\n✅微博"
+ msg += "\n🧣微博"
if ENABLE.XHS:
- msg += "\n✅小红书"
+ msg += "\n🍠小红书"
if ENABLE.DOUYIN:
- msg += "\n✅抖音"
+ msg += "\n🎶抖音"
if ENABLE.TIKTOK:
- msg += "\n✅TikTok"
+ msg += "\n🎶TikTok"
if ENABLE.INSTAGRAM:
- msg += "\n✅Instagram"
+ msg += "\n🏞Instagram"
if ENABLE.ASR:
msg += f"\n🗣**语音转文字**: `{PREFIX.ASR}` 回复语音消息"
if ENABLE.AUDIO:
src/main.py
@@ -15,8 +15,8 @@ from pyrogram.client import Client
from pyrogram.sync import idle
from pyrogram.types import LinkPreviewOptions, Message
-from bridge.miaomiao import forward_results_from_miaomiao
-from bridge.parsehub import forward_results_from_parsehub
+from bridge.ocr import forward_ocr_results
+from bridge.social import forward_socia_media_results
from config import DEVICE_NAME, ENABLE, PROXY, TID, TOKEN, cache
from handler import handle_social_media, handle_utilities
from message_utils import parse_msg
@@ -68,8 +68,8 @@ async def main():
if not ENABLE.BOTS:
return
parse_msg(message, verbose=True)
- await forward_results_from_parsehub(client, message)
- await forward_results_from_miaomiao(client, message)
+ await forward_socia_media_results(client, message)
+ await forward_ocr_results(client, message)
await handle_utilities(client, message, detail_progress=True)
await handle_social_media(client, message, cmd_prefix=["/dl", "!dl", "!dl"], detail_progress=True)