Added in regex to remove non alphanumeric and non spaces from message string

This commit is contained in:
Sean Wang
2019-03-22 03:39:43 -04:00
parent cea7b21452
commit 5db30f369b

View File

@@ -139,9 +139,18 @@ async def on_message(message):
', may you rot in heck!', ', may you rot in heck!',
', may Gosh have mercy on your soul...' ', may Gosh have mercy on your soul...'
] ]
message_string = message.content
# regex pattern for stripping out non-alphanumeric and non-spaces
pattern = re.compile(r"([^\s\w]|_)+")
# Initialize bad word count
bad_word_count = 0 bad_word_count = 0
words_in_message = message.content.split() # Take out everything except alpha-numeric and spaces
message_string = pattern.sub('', message_string)
# Split string into individual words
words_in_message = message_string.split()
# Set to lowercase
words_in_message = [word.lower() for word in words_in_message] words_in_message = [word.lower() for word in words_in_message]
# Don't respond to yourself
if message.author.bot: if message.author.bot:
return return
for key in bad_words.keys(): for key in bad_words.keys():