Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import sys
- import discord
- import asyncio
- client = discord.Client()
- react = True
- reply = True
- strippable_chars = ',.?!:;\"\''
- blacklist_file = 'blacklist.txt'
- def read_blacklist():
- with open(blacklist_file, 'r') as f:
- return set(line.strip().upper() for line in f)
- def message_contains_strong_words(message: str):
- words = message.split(' ')
- i = 0
- for word in words:
- if word.strip(strippable_chars).upper() in blacklist:
- return True
- if len(words) >= 2 and i > 0:
- composition = words[i - 1].strip(strippable_chars).upper() + ' ' + word.strip(strippable_chars).upper()
- if composition in blacklist:
- return True
- if len(words) >= 3 and i > 1:
- composition = words[i - 2].strip(strippable_chars).upper() + ' ' + words[i - 1].strip(strippable_chars).upper() + ' ' + word.strip(strippable_chars).upper()
- if composition in blacklist:
- return True
- if len(words) >= 4 and i > 2:
- 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()
- if composition in blacklist:
- return True
- i = i + 1
- @client.event
- async def on_ready():
- print('Succesfully logged in')
- @client.event
- async def on_message(message):
- if message_contains_strong_words(message.content):
- if react:
- await client.add_reaction(message, u'\U0001F6AB')
- if reply:
- await client.send_message(message.channel, 'Hey, zulke sterke woorden gebruiken wij hier niet!')
- # Start
- if len(sys.argv) is 1:
- print('Missing token parameter')
- exit(1)
- token = sys.argv[1]
- blacklist = read_blacklist()
- client.run(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment