Oreborous

sterke-woorden-app

Dec 5th, 2018
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.94 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import sys
  5. import discord
  6. import asyncio
  7.  
  8. client = discord.Client()
  9.  
  10. react = True
  11. reply = True
  12.  
  13. strippable_chars = ',.?!:;\"\''
  14. blacklist_file = 'blacklist.txt'
  15.  
  16.  
  17. def read_blacklist():
  18.     with open(blacklist_file, 'r') as f:
  19.         return set(line.strip().upper() for line in f)
  20.  
  21.  
  22. def message_contains_strong_words(message: str):
  23.     words = message.split(' ')
  24.  
  25.     i = 0
  26.     for word in words:
  27.         if word.strip(strippable_chars).upper() in blacklist:
  28.             return True
  29.         if len(words) >= 2 and i > 0:
  30.             composition = words[i - 1].strip(strippable_chars).upper() + ' ' + word.strip(strippable_chars).upper()
  31.             if composition in blacklist:
  32.                 return True
  33.         if len(words) >= 3 and i > 1:
  34.             composition = words[i - 2].strip(strippable_chars).upper() + ' ' + words[i - 1].strip(strippable_chars).upper() + ' ' + word.strip(strippable_chars).upper()
  35.             if composition in blacklist:
  36.                 return True
  37.         if len(words) >= 4 and i > 2:
  38.             composition = words[i - 3].strip(strippable_chars).upper() + ' ' + words[i - 2].strip(strippable_chars).upper() + ' ' + words[i - 1].strip(strippable_chars).upper() + ' ' + word.strip(strippable_chars).upper()
  39.             if composition in blacklist:
  40.                 return True
  41.         i = i + 1
  42.  
  43.  
  44. @client.event
  45. async def on_ready():
  46.     print('Succesfully logged in')
  47.  
  48.  
  49. @client.event
  50. async def on_message(message):
  51.     if message_contains_strong_words(message.content):
  52.         if react:
  53.             await client.add_reaction(message, u'\U0001F6AB')
  54.  
  55.         if reply:
  56.             await client.send_message(message.channel, 'Hey, zulke sterke woorden gebruiken wij hier niet!')
  57.  
  58.  
  59. # Start
  60. if len(sys.argv) is 1:
  61.     print('Missing token parameter')
  62.     exit(1)
  63.  
  64. token = sys.argv[1]
  65.  
  66. blacklist = read_blacklist()
  67. client.run(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment