MessageHandler filters are positive, not negative. Switch to excluding user IDs by configuration

This commit is contained in:
Mike Shultz 2020-05-11 14:09:05 -06:00
parent d82ef211cf
commit 26414ef39a
1 changed files with 15 additions and 1 deletions

16
bot.py
View File

@ -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)
))