From 5acdd5e4337c1a4f7b7d74ba54cfdb9694953a04 Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 15 May 2020 22:56:59 -0400 Subject: [PATCH] use regexes instead of simple string matching --- club-penguin.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/club-penguin.py b/club-penguin.py index 0cf30f2..c099cd5 100644 --- a/club-penguin.py +++ b/club-penguin.py @@ -1,11 +1,17 @@ import asyncio import discord +import re import sys client = discord.Client() +RUDE_WORDS_PREFIXONLY = [ + 'ass', + 'hell', + 'sex' +] + RUDE_WORDS = [ - 'asshole', 'bastard', 'bitch', 'boob', @@ -16,10 +22,8 @@ RUDE_WORDS = [ 'dick', 'dildo', 'fuck', - 'hell', 'penis', 'porn', - 'sex', 'shit', 'slut', 'tiddy', @@ -30,6 +34,9 @@ RUDE_WORDS = [ 'vagina' ] +REGEX_STR = '|'.join(['+'.join(list(w)) for w in RUDE_WORDS] + [r'\b' + '+'.join(list(w)) for w in RUDE_WORDS_PREFIXONLY]) +RUDE_WORDS_REGEX = re.compile(REGEX_STR, re.IGNORECASE) + @client.event async def on_ready(): print('logged in as {0.user}'.format(client), file=sys.stderr) @@ -39,7 +46,7 @@ async def on_message(message): if message.author == client.user: return - if any(w in message.content for w in RUDE_WORDS): + if RUDE_WORDS_REGEX.search(message.content): await message.channel.send('Your Club Penguin account has been deactivated for inappropriate language.') oldnick = message.author.nick try: