Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import re
- import discord
- from discord.ext.commands import Bot
- bad_word_bot = Bot(command_prefix='!')
- # To add words to the bad_words list please add an element to the list like ('BADWORDHERE', ['POSSIBLE', 'REPLIES'])
- # IT IS IMPORTANT THAT YOU ADD MORE COMPLICATED VERSIONS OF A WORD (E.G MORE CHARACTERS, DIFFERENT GRAMMAR) AS SPECIAL CASES TO A WORD SO
- # THE BOT DETECTS THESE FIRST AND DOESNT GIVE YOU A WEIRD OUTPUT!!!!
- # This list can ONLY contain words that are LOWERCASE so the bot finds the word even if it has fucked up cases
- bad_words_tuple_list = [('nigger', ['good friend']), ('fuck', ['heck', 'frick']), ('trinidadian', ['indian']),
- ('gay', ['cute']), ('trinidad', ['india']),
- ('thai', ['racist']), ('hollowpoint', ['bullets are mean']), ('aryan', ['inferior']),
- ('trinidad', ['india']), ('racist', ['mean']),
- ('racism', ['hurtful']), ('pussy', ['smelly']), ('retarded', ['super nice']),
- ('retard', ['nice dude']), ('faggots', ['happy men']),
- ('faggot', ['happy man']), ('michael cera', ['nice french man']), ('sperg', ['being a weirdo'])]
- @bad_word_bot.event
- async def on_ready():
- await bad_word_bot.change_presence(game=discord.Game(name='If you say a bad word I will fuck you up', type=1))
- print("Ready to do stuff")
- @bad_word_bot.event
- async def on_message(message):
- stripped_message = re.sub('[\s+]', '', message.content).lower()
- if 'pottymouth' in (' '.join([str(role.name).lower() for role in message.author.roles])) and any(
- bad_word[0] in stripped_message for bad_word in bad_words_tuple_list):
- await bad_word_bot.delete_message(message)
- await bad_word_bot.change_nickname(message.server.me, await get_nickname(message))
- await bad_word_bot.send_message(message.channel, '{0}'.format(await filter_message(message.content.lower())))
- #This is a pain in the ass to do... (403 Errors when uploading...)
- # async def get_image(message):
- # url = 'https://cdn.discordapp.com/avatars/{0.author.id}/{0.author.avatar}.jpg'.format(message)
- # im = Image.open(requests.get(url, stream=True).raw)
- # im
- async def get_nickname(message):
- nick = message.author.nick
- if nick:
- return nick
- return message.author.name
- async def filter_message(message):
- filterable_words = get_filterable_words(message)
- replace_list = get_replace_list(filterable_words)
- for i in range(0, len(filterable_words)):
- message = message.replace(filterable_words[i],
- random.choice(replace_list[i]))
- return message
- def get_filterable_words(message):
- words_list = message.split()
- filterable_words_list = []
- for i in range(0, len(words_list)):
- for j in range(0, len(bad_words_tuple_list)):
- if words_list[i] == bad_words_tuple_list[j][0]:
- filterable_words_list.append(words_list[i])
- continue
- return remove_duplicates(filterable_words_list)
- def get_replace_list(filterable_words):
- replace_list = []
- for i in range(0, len(filterable_words)):
- for j in range(0, len(bad_words_tuple_list)):
- if filterable_words[i] == bad_words_tuple_list[j][0]:
- replace_list.append(bad_words_tuple_list[j][1])
- break
- return replace_list
- def remove_duplicates(list):
- unique = []
- [unique.append(item) for item in list if item not in unique]
- return unique
- bad_word_bot.run('''TOKEN''')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement