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