From e812f33d9e7502cc0e59042dffe5535f3f762f9d Mon Sep 17 00:00:00 2001 From: Stan James Date: Sat, 10 Feb 2018 08:55:10 -0700 Subject: [PATCH] If banned, don't bother with message check --- bot.py | 41 +++++++++++++++++++++-------------------- model.py | 3 --- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/bot.py b/bot.py index 05ac17e..d09d185 100644 --- a/bot.py +++ b/bot.py @@ -76,9 +76,28 @@ class TelegramMonitorBot: # Remove accents from letters (é->e, ñ->n, etc...) message = unidecode.unidecode(update.message.text) - # TODO: Replace lookalike unicode characters + # TODO: Replace lookalike unicode characters: + # https://github.com/wanderingstan/Confusables - if self.message_hide_re and self.message_hide_re.search(message): + if self.message_ban_re and self.message_ban_re.search(message): + # Ban the user + if self.debug: + update.message.reply_text("DEBUG: Ban message match: {}".format(update.message.text.encode('utf-8'))) + print("Ban message match: {}".format(update.message.text.encode('utf-8'))) + # Any message that causes a ban gets deleted + update.message.delete() + # Ban the user + self.ban_user(update) + # Log in database + s = session() + userBan = UserBan( + user_id=update.message.from_user.id, + reason=update.message.text) + s.add(userBan) + s.commit() + s.close() + + elif self.message_hide_re and self.message_hide_re.search(message): # Delete the message if self.debug: update.message.reply_text("DEBUG: Hide match: {}".format(update.message.text.encode('utf-8'))) @@ -93,24 +112,6 @@ class TelegramMonitorBot: s.commit() s.close() - if self.message_ban_re and self.message_ban_re.search(message): - # Ban the user - if self.debug: - update.message.reply_text("DEBUG: Ban message match: {}".format(update.message.text.encode('utf-8'))) - print("Ban message match: {}".format(update.message.text.encode('utf-8'))) - # Ban the user - self.ban_user(update) - # Any message that causes a ban gets deleted - update.message.delete() - # Log in database - s = session() - userBan = UserBan( - user_id=update.message.from_user.id, - reason=update.message.text) - s.add(userBan) - s.commit() - s.close() - def logger(self, bot, update): """Primary Logger. Handles incoming bot messages and saves them to DB""" diff --git a/model.py b/model.py index b87bfb4..7bbed81 100644 --- a/model.py +++ b/model.py @@ -48,12 +48,9 @@ class UserBan(Base): from sqlalchemy import create_engine engine = create_engine(postgres_url) -print (engine) - from sqlalchemy.orm import sessionmaker session = sessionmaker() session.configure(bind=engine) Base.metadata.create_all(engine) - print ("Created database model")