Commit 1fbe0f9

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-01-23 14:39:25
feat: support enable/disable send as reply to the original message
1 parent c94cc26
Changed files (3)
src/config.py
@@ -42,6 +42,7 @@ class ENABLE:
     CHANNELS = os.getenv("ENABLE_CHANNELS", "1").lower() in ["1", "y", "yes", "t", "true", "on"]
     BOTS = os.getenv("ENABLE_BOTS", "1").lower() in ["1", "y", "yes", "t", "true", "on"]
     USERS = os.getenv("ENABLE_USERS", "1").lower() in ["1", "y", "yes", "t", "true", "on"]
+    SEND_AS_REPLY = os.getenv("ENABLE_SEND_AS_REPLY", "1").lower() in ["1", "y", "yes", "t", "true", "on"]  # Send as a reply to the original message
 
 
 class PREFIX:
src/handler.py
@@ -16,6 +16,7 @@ from networking import flatten_rediercts, match_social_media_link
 from others.download_external import download_url_in_message
 from others.extract_audio import extract_audio_file
 from others.gpt import gpt_response
+from others.raw_img_file import convert_raw_img_file
 from others.subtitle import get_subtitle
 from preview.douyin import preview_douyin
 from preview.instagram import preview_instagram
@@ -33,12 +34,13 @@ async def handle_utilities(
     target_chat: int | str | None = None,
     reply_msg_id: int = 0,
     *,
+    ai: bool = True,
     asr: bool = True,
     audio: bool = True,
-    ai: bool = True,
     subtitle: bool = True,
     wget: bool = True,
     ocr: bool = True,
+    raw_img: bool = False,
     show_progress: bool = True,
     detail_progress: bool = False,
     **kwargs,
@@ -52,28 +54,31 @@ async def handle_utilities(
         reply_msg_id (int, optional): If set to integer > 0, the result is sent as a reply message to this message_id.
                                              If set to 0, reply to the trigger message itself.
                                              If set to -1, do not send as a reply message.
+        ai (bool, optional): Enable GPT. Defaults to True.
         asr (bool, optional): Enable ASR. Defaults to True.
         audio (bool, optional): Enable Video -> Audio. Defaults to True.
-        ai (bool, optional): Enable GPT. Defaults to True.
         subtitle (bool, optional): Enable YouTube subtitle. Defaults to True.
         wget (bool, optional): Enable WGET. Defaults to True.
         ocr (bool, optional): Enable OCR. Defaults to True.
+        raw_img (bool, optional): Enable convert raw image. Defaults to False.
         show_progress (bool, optional): Show a progress message on Telegram. Defaults to True.
         detail_progress (bool, optional): Show detailed progress (Only if show_proress is set to True). Defaults to False.
     """
     kwargs |= {"target_chat": target_chat, "reply_msg_id": reply_msg_id, "show_progress": show_progress, "detail_progress": detail_progress}
+    if ai:
+        await gpt_response(client, message, **kwargs)  # /ai
     if asr:
         await voice_to_text(client, message, **kwargs)  # /asr
     if audio:
         await extract_audio_file(client, message, **kwargs)  # /audio
-    if ai:
-        await gpt_response(client, message, **kwargs)  # /ai
     if subtitle:
         await get_subtitle(client, message, **kwargs)  # /subtitle
     if wget:
         await download_url_in_message(client, message, **kwargs)  # /wget
     if ocr:
         await send_to_ocr_bridge(client, message)  # /ocr
+    if raw_img:
+        await convert_raw_img_file(client, message, **kwargs)
 
 
 @cache.memoize(ttl=60)
@@ -116,6 +121,8 @@ async def handle_social_media(
         detail_progress (bool, optional): Show detailed progress (Only if show_proress is set to True). Defaults to False.
     """
     kwargs |= {"target_chat": target_chat, "reply_msg_id": reply_msg_id, "show_progress": show_progress, "detail_progress": detail_progress}
+    if not ENABLE.SEND_AS_REPLY:
+        kwargs["reply_msg_id"] = -1
     if cmd_prefix is None:
         cmd_prefix = PREFIX.MAIN
     else:
src/main.py
@@ -23,7 +23,6 @@ from bridge.social import forward_social_media_results
 from config import DAILY_MESSAGES, DEVICE_NAME, ENABLE, PROXY, TID, TOKEN, TZ, cache
 from handler import handle_social_media, handle_utilities
 from message_utils import parse_msg
-from others.raw_img_file import convert_raw_img_file
 from utils import cleanup_old_files, nowdt, to_int
 
 # ruff: noqa: RUF001
@@ -98,8 +97,7 @@ async def main():
         if TID.ONLY_USERS and message.chat.id not in [int(x.strip()) for x in TID.ONLY_USERS.split(",")]:
             return
         parse_msg(message, verbose=True)
-        await convert_raw_img_file(client, message, show_progress=True, detail_progress=True)
-        await handle_utilities(client, message, detail_progress=True)
+        await handle_utilities(client, message, raw_img=True, detail_progress=True)
         await handle_social_media(client, message, need_prefix=False, detail_progress=True)
 
     if ENABLE.CRONTAB: