Basic matching and banning working

This commit is contained in:
Stan James 2018-02-01 14:54:27 -07:00
parent 534f2cbd3e
commit cf81b03e8c

26
bot.py
View File

@ -15,10 +15,26 @@ from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import os import os
from model import User, Message, session from model import User, Message, session
from time import strftime from time import strftime
import re
# Define a few command handlers. These usually take the two arguments bot and # Define a few command handlers. These usually take the two arguments bot and
# update. Error handlers also receive the raised TelegramError object in error. # 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): def logger(bot, update):
"""Primary Logger. Handles incoming bot messages and saves them to DB""" """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')) 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): def id_exists(id_value):
s = session() s = session()
bool_set = False bool_set = False
@ -56,6 +77,7 @@ def id_exists(id_value):
return bool_set return bool_set
def log_message(user_id, user_message): def log_message(user_id, user_message):
try: try:
@ -68,6 +90,7 @@ def log_message(user_id, user_message):
except Exception as e: except Exception as e:
print(e) print(e)
def add_user(user_id, first_name, last_name, username): def add_user(user_id, first_name, last_name, username):
try: try:
s = session() s = session()
@ -91,7 +114,6 @@ def error(bot, update, error):
print("Update '{}' caused error '{}'".format(update, error), file=sys.stderr) print("Update '{}' caused error '{}'".format(update, error), file=sys.stderr)
def main(): def main():
"""Start the bot.""" """Start the bot."""
# Create the EventHandler and pass it your bot's token. # Create the EventHandler and pass it your bot's token.