From 26414ef39afcac57c24209d73b7321f331c9598d Mon Sep 17 00:00:00 2001 From: Mike Shultz Date: Mon, 11 May 2020 14:09:05 -0600 Subject: [PATCH] MessageHandler filters are positive, not negative. Switch to excluding user IDs by configuration --- bot.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 2b58657..f59cb47 100644 --- a/bot.py +++ b/bot.py @@ -229,10 +229,17 @@ class TelegramMonitorBot: print("🔵 MESSAGE_BAN_PATTERNS:\n", os.environ['MESSAGE_BAN_PATTERNS']) print("🔵 MESSAGE_HIDE_PATTERNS:\n", os.environ['MESSAGE_HIDE_PATTERNS']) print("🔵 NAME_BAN_PATTERNS:\n", os.environ['NAME_BAN_PATTERNS']) + print("🔵 IGNORE_USER_IDS:\n", os.environ.get('IGNORE_USER_IDS')) # Channel to notify of violoations, e.g. '@channelname' self.notify_chat = os.environ['NOTIFY_CHAT'] if 'NOTIFY_CHAT' in os.environ else None + # Ignore these user IDs + if not os.environ.get('IGNORE_USER_IDS'): + self.ignore_user_ids = [] + else: + self.ignore_user_ids = os.environ['IGNORE_USER_IDS'].split(',') + # List of chat ids that bot should monitor self.chat_ids = ( list(map(int, os.environ['CHAT_IDS'].split(','))) @@ -449,6 +456,13 @@ class TelegramMonitorBot: :param update: telegram.Update https://python-telegram-bot.readthedocs.io/en/stable/telegram.update.html """ + if ( + update.effective_user is None + or update.effective_user.id in self.ignore_user_ids + ): + print("Ignoring update.") + return + try: message = update.message @@ -703,7 +717,7 @@ class TelegramMonitorBot: # on noncommand i.e message - echo the message on Telegram dp.add_handler(MessageHandler( - Filters.user(777000), + Filters.all, lambda bot, update : self.logger(bot, update) ))