diff --git a/bot.py b/bot.py index 2e7cd98..7248efd 100644 --- a/bot.py +++ b/bot.py @@ -15,10 +15,26 @@ from telegram.ext import Updater, CommandHandler, MessageHandler, Filters import os from model import User, Message, session from time import strftime +import re # Define a few command handlers. These usually take the two arguments bot and # update. Error handlers also receive the raised TelegramError object in error. + +def security_check_message(bot, update): + """ Test message for security violations """ + + r = re.compile(r'FART') + if r.match(update.message.text): + print("Matched!") + # Delete the message + update.message.delete() + + # # Ban the user + # kick_success = update.message.chat.kick_member(update.message.from_user.id) + # print(kick_success) + + def logger(bot, update): """Primary Logger. Handles incoming bot messages and saves them to DB""" @@ -43,8 +59,13 @@ def logger(bot, update): update.message.text.encode('utf-8')) ) -# DB queries + try: + security_check_message(bot, update) + except Exception as e: + print(e) + +# DB queries def id_exists(id_value): s = session() bool_set = False @@ -56,6 +77,7 @@ def id_exists(id_value): return bool_set + def log_message(user_id, user_message): try: @@ -68,6 +90,7 @@ def log_message(user_id, user_message): except Exception as e: print(e) + def add_user(user_id, first_name, last_name, username): try: s = session() @@ -91,7 +114,6 @@ def error(bot, update, error): print("Update '{}' caused error '{}'".format(update, error), file=sys.stderr) - def main(): """Start the bot.""" # Create the EventHandler and pass it your bot's token.