From 0079ae2aec84fa99c7fde4d00e3618592b0132e0 Mon Sep 17 00:00:00 2001 From: Stan James Date: Thu, 1 Feb 2018 16:04:18 -0700 Subject: [PATCH] Ignores accents on characters now --- bot.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bot.py b/bot.py index 7248efd..3fcf457 100644 --- a/bot.py +++ b/bot.py @@ -16,6 +16,7 @@ import os from model import User, Message, session from time import strftime import re +import unidecode # Define a few command handlers. These usually take the two arguments bot and # update. Error handlers also receive the raised TelegramError object in error. @@ -24,9 +25,18 @@ import re def security_check_message(bot, update): """ Test message for security violations """ - r = re.compile(r'FART') - if r.match(update.message.text): - print("Matched!") + ban_patterns = [ + '[0-9a-fA-F]{40,40}', + 'Fart', + ] + + # Remove accents from letters + message = unidecode.unidecode(update.message.text) + + regexp_pattern = "|".join(ban_patterns) + r = re.compile(regexp_pattern, re.IGNORECASE) + if r.search(message): + print("Bannable match: {}".format(update.message.text.encode('utf-8'))) # Delete the message update.message.delete()