-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
80 lines (64 loc) · 1.73 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
import discord
import random
from trie.Trie import Trie
from dotenv import load_dotenv
from keep_alive import keep_alive
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()
trie = Trie()
table = {
"\"": None,
"'": None,
"-": None,
"`": None,
"~": None,
",": None,
".": None,
":": None,
";": None,
"_": None
}
def buildTrie():
file = open("trie/words.txt", 'r')
for line in file:
line = line.strip()
trie.insert(line)
def punish_user(user_id):
user_id = '<@' + str(user_id) + '>'
responses = [
"Hey {} shut up"
"You pray with that mouth, {}?",
"That's some colorful language, {}.",
"Come on now, {}. Did you really need to say that?",
"{} - It's not a good LANGUAGE!",
"Hey now {}, watch your mouth.",
"We don't use that kind of language here, {}."
"Please {}, don't use this kind of slang"
"Hey {}, Can you stop this"
"{} You are not allowed to use that words here"
]
choice = random.choice(responses)
choice = choice.format(user_id)
return choice
@client.event
async def on_ready():
buildTrie()
print("Trie is built. ready to read messages.")
@client.event
async def on_message(message):
text = message.content
text = text.translate(str.maketrans(table))
author_id = message.author.id
if author_id != 770954317926236160:
isClean = True
message_word_list = text.split()
for word in message_word_list:
if trie.search(word):
isClean = False
break
if not isClean:
await message.channel.send(punish_user(author_id))
keep_alive()
client.run(TOKEN)