Ignores accents on characters now

This commit is contained in:
Stan James 2018-02-01 16:04:18 -07:00
parent cf81b03e8c
commit 0079ae2aec

16
bot.py
View File

@ -16,6 +16,7 @@ import os
from model import User, Message, session from model import User, Message, session
from time import strftime from time import strftime
import re import re
import unidecode
# 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.
@ -24,9 +25,18 @@ import re
def security_check_message(bot, update): def security_check_message(bot, update):
""" Test message for security violations """ """ Test message for security violations """
r = re.compile(r'FART') ban_patterns = [
if r.match(update.message.text): '[0-9a-fA-F]{40,40}',
print("Matched!") '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 # Delete the message
update.message.delete() update.message.delete()