Commit 25a46f9

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-01-22 14:46:04
feat: can skip or limit to monitor specific chats via environment vars
1 parent 1300619
Changed files (2)
src/config.py
@@ -134,6 +134,14 @@ class TID:
     ADMIN_GROUP = os.getenv("TID_ADMIN_GROUP", "me")
     CHANNEL_YTDLP_BACKUP = os.getenv("TID_CHANNEL_YTDLP_BACKUP", "me")
     GROUP67373 = os.getenv("TID_GROUP67373", "")
+    SKIP_BOTS = os.getenv("TID_SKIP_BOTS", "")
+    SKIP_CHANNELS = os.getenv("TID_SKIP_CHANNELS", "")
+    SKIP_GROUPS = os.getenv("TID_SKIP_GROUPS", "")
+    SKIP_USERS = os.getenv("TID_SKIP_USERS", "")
+    ONLY_BOTS = os.getenv("TID_ONLY_BOTS", "")
+    ONLY_CHANNELS = os.getenv("TID_ONLY_CHANNELS", "")
+    ONLY_GROUPS = os.getenv("TID_ONLY_GROUPS", "")
+    ONLY_USERS = os.getenv("TID_ONLY_USERS", "")
 
 
 class DB:
src/main.py
@@ -46,6 +46,10 @@ async def main():
     async def groups(client: Client, message: Message):
         if not ENABLE.GROUPS:
             return
+        if TID.SKIP_GROUPS and message.chat.id in [int(x.strip()) for x in TID.SKIP_GROUPS.split(",")]:
+            return
+        if TID.ONLY_GROUPS and message.chat.id not in [int(x.strip()) for x in TID.ONLY_GROUPS.split(",")]:
+            return
         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)
@@ -58,7 +62,10 @@ async def main():
     async def channels(client: Client, message: Message):
         if not ENABLE.CHANNELS:
             return
-
+        if TID.SKIP_CHANNELS and message.chat.id in [int(x.strip()) for x in TID.SKIP_CHANNELS.split(",")]:
+            return
+        if TID.ONLY_CHANNELS and message.chat.id not in [int(x.strip()) for x in TID.ONLY_CHANNELS.split(",")]:
+            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)
@@ -67,6 +74,10 @@ async def main():
     async def bots(client: Client, message: Message):
         if not ENABLE.BOTS:
             return
+        if TID.SKIP_BOTS and message.chat.id in [int(x.strip()) for x in TID.SKIP_BOTS.split(",")]:
+            return
+        if TID.ONLY_BOTS and message.chat.id not in [int(x.strip()) for x in TID.ONLY_BOTS.split(",")]:
+            return
         parse_msg(message, verbose=True)
         await forward_social_media_results(client, message)
         await forward_ocr_results(client, message)
@@ -79,6 +90,10 @@ async def main():
     async def private(client: Client, message: Message):
         if not ENABLE.USERS or message.chat.type.name != "PRIVATE":
             return
+        if TID.SKIP_USERS and message.chat.id in [int(x.strip()) for x in TID.SKIP_USERS.split(",")]:
+            return
+        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)