use regexes instead of simple string matching
This commit is contained in:
parent
a1e086ba2f
commit
5acdd5e433
|
@ -1,11 +1,17 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import discord
|
import discord
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
client = discord.Client()
|
client = discord.Client()
|
||||||
|
|
||||||
|
RUDE_WORDS_PREFIXONLY = [
|
||||||
|
'ass',
|
||||||
|
'hell',
|
||||||
|
'sex'
|
||||||
|
]
|
||||||
|
|
||||||
RUDE_WORDS = [
|
RUDE_WORDS = [
|
||||||
'asshole',
|
|
||||||
'bastard',
|
'bastard',
|
||||||
'bitch',
|
'bitch',
|
||||||
'boob',
|
'boob',
|
||||||
|
@ -16,10 +22,8 @@ RUDE_WORDS = [
|
||||||
'dick',
|
'dick',
|
||||||
'dildo',
|
'dildo',
|
||||||
'fuck',
|
'fuck',
|
||||||
'hell',
|
|
||||||
'penis',
|
'penis',
|
||||||
'porn',
|
'porn',
|
||||||
'sex',
|
|
||||||
'shit',
|
'shit',
|
||||||
'slut',
|
'slut',
|
||||||
'tiddy',
|
'tiddy',
|
||||||
|
@ -30,6 +34,9 @@ RUDE_WORDS = [
|
||||||
'vagina'
|
'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
|
@client.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print('logged in as {0.user}'.format(client), file=sys.stderr)
|
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:
|
if message.author == client.user:
|
||||||
return
|
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.')
|
await message.channel.send('Your Club Penguin account has been deactivated for inappropriate language.')
|
||||||
oldnick = message.author.nick
|
oldnick = message.author.nick
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue