Commit 85099ee

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-01-23 09:35:32
feat: support multile prefix
1 parent 6e388b2
Changed files (4)
src/others/raw_img_file.py
@@ -6,7 +6,7 @@ from loguru import logger
 from pyrogram.client import Client
 from pyrogram.types import Message
 
-from config import ENABLE, PREFIX
+from config import ENABLE
 from message_utils import parse_msg, send2tg
 from multimedia import split_long_img
 
@@ -26,8 +26,8 @@ async def convert_raw_img_file(client: Client, message: Message, **kwargs):
         media = [{"photo": photo.as_posix()} for photo in photos if photo.is_file()]
         # send splits
         if len(media) == 1:
-            await send2tg(client, message, media=media, texts=f"🔁【原图转换】已完成\n发送 **{PREFIX.MAIN}** 命令查看更多功能", **kwargs)
+            await send2tg(client, message, media=media, texts="🔁【原图转换】已完成", **kwargs)
         else:
-            await send2tg(client, message, media=media, texts=f"✂️【自动切原图】已完成\n发送 **{PREFIX.MAIN}** 命令查看更多功能", **kwargs)
+            await send2tg(client, message, media=media, texts="✂️【自动切长图】已完成 (使用【原图】发送才可触发切长图)", **kwargs)
     except Exception as e:
         logger.exception(e)
src/config.py
@@ -3,9 +3,11 @@
 import asyncio
 import os
 from pathlib import Path
+from typing import ClassVar
 
 from cacheout import Cache
 
+# ruff: noqa: RUF001
 cache = Cache(ttl=0, maxsize=2048)
 semaphore = asyncio.Semaphore(8)  # max 8 concurrent downloads
 
@@ -43,7 +45,7 @@ class ENABLE:
 
 
 class PREFIX:
-    MAIN = os.getenv("PREFIX_MAIN", "/benny").lower()
+    MAIN: ClassVar[list[str]] = [x.strip().lower() for x in os.getenv("PREFIX_MAIN", "/benny,/dl,!dl,!dl,!下载,!下载").split(",")]
     ASR = os.getenv("PREFIX_ASR", "/asr").lower()
     AUDIO = os.getenv("PREFIX_AUDIO", "/audio").lower()
     GPT = os.getenv("PREFIX_GPT", "/ai").lower()
src/handler.py
@@ -118,9 +118,9 @@ async def handle_social_media(
     """
     kwargs |= {"target_chat": target_chat, "reply_msg_id": reply_msg_id, "show_progress": show_progress, "detail_progress": detail_progress}
     if cmd_prefix is None:
-        cmd_prefix = [PREFIX.MAIN]
+        cmd_prefix = PREFIX.MAIN
     else:
-        cmd_prefix.append(PREFIX.MAIN)
+        cmd_prefix.extend(PREFIX.MAIN)
     ignore_prefix = ignore_prefix or []
     info = parse_msg(message)
     this_texts = message.text or message.caption or ""  # texts of the trigger message
src/main.py
@@ -56,10 +56,10 @@ async def main():
         parse_msg(message)
         if TID.GROUP67373 and message.chat.id in [int(x.strip()) for x in TID.GROUP67373.split(",")]:
             await handle_utilities(client, message, detail_progress=False)
-            await handle_social_media(client, message, cmd_prefix=["/dl", "!dl", "!dl", "!下载", "!下载"], ignore_prefix=["/dl4dw"], prepend_sender_user=True)
+            await handle_social_media(client, message, ignore_prefix=["/dl4dw"], prepend_sender_user=True)
         else:
             await handle_utilities(client, message, detail_progress=True)
-            await handle_social_media(client, message, cmd_prefix=["/dl", "!dl", "!dl"], detail_progress=True)
+            await handle_social_media(client, message, detail_progress=True)
 
     @app.on_message(filters.channel)
     async def channels(client: Client, message: Message):
@@ -71,7 +71,7 @@ async def main():
             return
         parse_msg(message)
         await handle_utilities(client, message, detail_progress=True)
-        await handle_social_media(client, message, cmd_prefix=["/dl", "!dl", "!dl"], detail_progress=True)
+        await handle_social_media(client, message, detail_progress=True)
 
     @app.on_message(filters.bot)
     async def bots(client: Client, message: Message):
@@ -85,7 +85,7 @@ async def main():
         await forward_social_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)
+        await handle_social_media(client, message, detail_progress=True)
 
     # filters.private = {user chats + bot chats}
     # so the private handler should be placed after the bot handler