If banned, don't bother with message check

This commit is contained in:
Stan James 2018-02-10 08:55:10 -07:00
parent 9fabbc6e3b
commit e812f33d9e
2 changed files with 21 additions and 23 deletions

41
bot.py
View File

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

View File

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