Commit 55ac784

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-02-08 03:25:39
fix(social): skip commands handled in `handle_utilities`
1 parent dd2bd3a
Changed files (1)
src/handler.py
@@ -83,7 +83,7 @@ async def handle_utilities(
     if audio:
         await extract_audio_file(client, message, **kwargs)  # /audio
     if combine:
-        await combine_history(client, message, **kwargs)  # /audio
+        await combine_history(client, message, **kwargs)  # /combine
     if subtitle:
         await get_subtitle(client, message, **kwargs)  # /subtitle
     if wget:
@@ -91,7 +91,7 @@ async def handle_utilities(
     if ocr:
         await send_to_ocr_bridge(client, message, **kwargs)  # /ocr
     if price:
-        await get_asset_price(client, message, **kwargs)  # /ocr
+        await get_asset_price(client, message, **kwargs)  # /price
     if summary:
         await ai_summary(client, message, **kwargs)  # /summary
     if raw_img:
@@ -144,18 +144,21 @@ async def handle_social_media(
     else:
         cmd_prefix.extend(PREFIX.MAIN)
     ignore_prefix = ignore_prefix or []
+    ignore_prefix.extend(["/ai", "/asr", "/audio", "/combine", "/subtitle", "/wget", "/ocr", "/price", "/summary"])  # these commands are handled in `handle_utilities`
     info = parse_msg(message)
     this_texts = info["text"]  # texts of the trigger message
-    if need_prefix and not startswith_prefix(this_texts, prefix=[*cmd_prefix, "/retry"], ignore_prefix=ignore_prefix):
+    if startswith_prefix(this_texts, prefix=ignore_prefix):
+        return
+    if need_prefix and not startswith_prefix(this_texts, prefix=[*cmd_prefix, "/retry"]):
         return
     kwargs |= params_from_msg_text(this_texts)  # merge the parameters from the message text
     if true(kwargs.get("target_chat")):
         kwargs["target_chat"] = to_int(kwargs["target_chat"])
     # message only contains prefix command
-    if equal_prefix(this_texts, prefix=[*cmd_prefix, "/retry"], ignore_prefix=ignore_prefix):
+    if equal_prefix(this_texts, prefix=[*cmd_prefix, "/retry"]):
         # without reply, send docs if message only contains prefix command
         if not message.reply_to_message:
-            help_msg = get_social_media_help(cmd_prefix=cmd_prefix, ignore_prefix=ignore_prefix)
+            help_msg = get_social_media_help(cmd_prefix)
             await send2tg(client, message, texts=help_msg, **kwargs)
             return
         # with reply, treat the reply_msg as the trigger to preview social media link
@@ -244,11 +247,9 @@ def params_from_msg_text(texts: str | None = None) -> dict:
     return params
 
 
-def get_social_media_help(cmd_prefix: list[str] | None = None, ignore_prefix: list[str] | None = None):
+def get_social_media_help(prefixes: list[str] | None = None):
     """Get the help message for social media preview."""
-    cmd_prefix = cmd_prefix or []
-    ignore_prefix = ignore_prefix or []
-    prefixes = set(cmd_prefix) - set(ignore_prefix)
+    prefixes = prefixes or []
     msg = "🔗**链接解析**"
     if prefixes:
         msg += f" 前缀: {', '.join(prefixes)}"