use regexes instead of simple string matching
This commit is contained in:
		
							parent
							
								
									a1e086ba2f
								
							
						
					
					
						commit
						5acdd5e433
					
				
					 1 changed files with 11 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -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:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue