Advertisement
Guest User

Untitled

a guest
Jan 12th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.59 KB | None | 0 0
  1. import random
  2. import re
  3.  
  4. import discord
  5. from discord.ext.commands import Bot
  6.  
  7. bad_word_bot = Bot(command_prefix='!')
  8.  
  9. # To add words to the bad_words list please add an element to the list like ('BADWORDHERE', ['POSSIBLE', 'REPLIES'])
  10. # 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
  11. # THE BOT DETECTS THESE FIRST AND DOESNT GIVE YOU A WEIRD OUTPUT!!!!
  12. # This list can ONLY contain words that are LOWERCASE so the bot finds the word even if it has fucked up cases
  13. bad_words_tuple_list = [('nigger', ['good friend']), ('fuck', ['heck', 'frick']), ('trinidadian', ['indian']),
  14.                         ('gay', ['cute']), ('trinidad', ['india']),
  15.                         ('thai', ['racist']), ('hollowpoint', ['bullets are mean']), ('aryan', ['inferior']),
  16.                         ('trinidad', ['india']), ('racist', ['mean']),
  17.                         ('racism', ['hurtful']), ('pussy', ['smelly']), ('retarded', ['super nice']),
  18.                         ('retard', ['nice dude']), ('faggots', ['happy men']),
  19.                         ('faggot', ['happy man']), ('michael cera', ['nice french man']), ('sperg', ['being a weirdo'])]
  20.  
  21.  
  22. @bad_word_bot.event
  23. async def on_ready():
  24.     await bad_word_bot.change_presence(game=discord.Game(name='If you say a bad word I will fuck you up', type=1))
  25.     print("Ready to do stuff")
  26.  
  27.  
  28. @bad_word_bot.event
  29. async def on_message(message):
  30.     stripped_message = re.sub('[\s+]', '', message.content).lower()
  31.     if 'pottymouth' in (' '.join([str(role.name).lower() for role in message.author.roles])) and any(
  32.                     bad_word[0] in stripped_message for bad_word in bad_words_tuple_list):
  33.         await bad_word_bot.delete_message(message)
  34.         await bad_word_bot.change_nickname(message.server.me, await get_nickname(message))
  35.         await bad_word_bot.send_message(message.channel, '{0}'.format(await filter_message(message.content.lower())))
  36.  
  37. #This is a pain in the ass to do... (403 Errors when uploading...)
  38. # async def get_image(message):
  39. #     url = 'https://cdn.discordapp.com/avatars/{0.author.id}/{0.author.avatar}.jpg'.format(message)
  40. #     im = Image.open(requests.get(url, stream=True).raw)
  41. #     im
  42.  
  43. async def get_nickname(message):
  44.     nick = message.author.nick
  45.     if nick:
  46.         return nick
  47.     return message.author.name
  48.  
  49. async def filter_message(message):
  50.     filterable_words = get_filterable_words(message)
  51.     replace_list = get_replace_list(filterable_words)
  52.     for i in range(0, len(filterable_words)):
  53.         message = message.replace(filterable_words[i],
  54.                                   random.choice(replace_list[i]))
  55.     return message
  56.  
  57.  
  58. def get_filterable_words(message):
  59.     words_list = message.split()
  60.     filterable_words_list = []
  61.     for i in range(0, len(words_list)):
  62.         for j in range(0, len(bad_words_tuple_list)):
  63.             if words_list[i] == bad_words_tuple_list[j][0]:
  64.                 filterable_words_list.append(words_list[i])
  65.                 continue
  66.     return remove_duplicates(filterable_words_list)
  67.  
  68.  
  69. def get_replace_list(filterable_words):
  70.     replace_list = []
  71.     for i in range(0, len(filterable_words)):
  72.         for j in range(0, len(bad_words_tuple_list)):
  73.             if filterable_words[i] == bad_words_tuple_list[j][0]:
  74.                 replace_list.append(bad_words_tuple_list[j][1])
  75.                 break
  76.     return replace_list
  77.  
  78. def remove_duplicates(list):
  79.     unique = []
  80.     [unique.append(item) for item in list if item not in unique]
  81.     return unique
  82.  
  83. bad_word_bot.run('''TOKEN''')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement