-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
204 lines (165 loc) · 7.13 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import discord
import os
import requests
import json
import yaml
import wikipedia
import warnings
warnings.filterwarnings("ignore") # This ignores the stupid wikipedia warning no one likes or even cares about that isn't actually from wikipedia but only shows because the wikipedia module doesn't ignore so we need to do it with this two liner that is way too long because of this stupid comment but I am pretty mad at the devs of the wikipedia module for this that's why I am writing so much k thx bye
from wikipedia.exceptions import PageError
from wikipedia.exceptions import DisambiguationError
client = discord.Client()
MESSAGE_PATH = "messages.yml"
message_file = open(MESSAGE_PATH, "r")
MESSAGES = yaml.safe_load(message_file)
message_file.close()
HELLO_WORLD_STRING = MESSAGES["helloWorld"]
BAD_WORD_PATH = "badWords.yml"
bad_word_file = open(BAD_WORD_PATH, "r")
BAD_WORDS_DATA = yaml.safe_load(bad_word_file)
bad_word_file.close()
BAD_WORDS = BAD_WORDS_DATA["badWords"]
role_msg_id = 795005876112326683
def get_quote():
response = requests.get("https://zenquotes.io/api/random")
json_data = json.loads(response.text)
quote = json_data[0] ["q"] + " -" + json_data[0] ["a"]
return(quote)
@client.event
async def on_reaction_add(reaction, reactor, message):
# https://discordpy.readthedocs.io/en/latest/api.html#reaction
message_reacted_on = reaction.message
message_id = message_reacted_on.id
reaction_emoji = reaction.emoji
reacted_by_me = reaction.me
if reacted_by_me:
return
if message_id == role_msg_id:
print("Die Nachricht mit command wurde erfolgreich erkannt")
print(message_reacted_on.id)
print(reaction_emoji)
print(reactor)
@client.event
async def on_reaction_remove(reaction, reactor):
message_reacted_on = reaction.message
reaction_emoji = reaction.emoji
reacted_by_me = reaction.me
print("hello")
@client.event
async def on_ready():
wikipedia.set_lang("de")
print(f'We have logged in as {client.user}')
@client.event
async def on_message(message):
msg_text = message.content.lower()
if message.author == client.user:
return
if msg_text.startswith('!hello'):
await message.channel.send(HELLO_WORLD_STRING)
elif msg_text.startswith("!inspiration"):
quote = get_quote()
await message.channel.send(quote)
elif msg_text.startswith("!poll"):
msg_parts = msg_text.split(" ")
number_of_options = int(msg_parts[1])
if number_of_options in [2, 3, 4, 5, 6, 7, 8, 9, 10]:
await message.add_reaction("1️⃣")
await message.add_reaction("2️⃣")
if number_of_options >= 3:
await message.add_reaction("3️⃣")
if number_of_options >= 4:
await message.add_reaction("4️⃣")
if number_of_options >= 5:
await message.add_reaction("5️⃣")
if number_of_options >= 6:
await message.add_reaction("6️⃣")
if number_of_options >= 7:
await message.add_reaction("7️⃣")
if number_of_options >= 8:
await message.add_reaction("8️⃣")
if number_of_options >= 9:
await message.add_reaction("9️⃣")
if number_of_options >= 10:
await message.add_reaction("🔟")
else:
await message.channel.send("Du kannst 2-10 Optionen erstellen: `!poll <mengeAnOptionen>`")
if allow_abstain_vote:
await message.add_reaction("😶") # Emoji can be changed, but I thougt the lack of expression on the face fits to abstaining ~kiriDevs
elif any(word in msg_text for word in BAD_WORDS):
await message.channel.send(MESSAGES["wortwahl"])
elif msg_text.startswith("!machterfehler?"):
await message.channel.send("Ich mache keine Fehler, " + message.author.mention)
elif msg_text.startswith("!quit"):
if message.author.id in [323196084413267974, 277159146565009408]:
await message.channel.send(f"Tschüß, {message.author.mention}!")
await client.close()
exit(0)
else:
await message.channel.send(f"Das darfst du nicht, {message.author.mention}!")
elif msg_text.startswith("!info"):
await message.channel.send("Hier sind Informationen über mich, du minderwertiges Stück Kohlenstoff:")
await message.channel.send("https://wiki.coldmirror.net/wiki/A.R.S.C.H_9000")
elif msg_text.startswith("!kiri"):
oauth = os.getenv("TWITCH_OAUTH_TOKEN")
parameters = { "query": "kirimctwitch" }
headers = {
"client-id": os.getenv("TWITCH_CLIENT_ID"),
"Authorization": f"Bearer {oauth}"
}
request = requests.get("https://api.twitch.tv/helix/search/channels", params=parameters, headers=headers)
top_hit = request.json()["data"][0]
await message.channel.send(f"""Top Hit on Twitch:
```
{top_hit}
```""")
elif msg_text.startswith("!istkirilive?"):
oauth = os.getenv("TWITCH_OAUTH_TOKEN")
parameters = { "query": "kirimctwitch" }
headers = {
"client-id": os.getenv("TWITCH_CLIENT_ID"),
"Authorization": f"Bearer {oauth}"
}
request = requests.get("https://api.twitch.tv/helix/search/channels", params=parameters, headers=headers)
top_hit = request.json()["data"][0]
if not top_hit["is_live"]:
await message.channel.send("kiron ist nicht live")
await message.channel.send("Wenn Kiron streamt, kannst du ihn hier finden:")
await message.channel.send("https://twitch.tv/kirimctwitch")
else:
await message.channel.send("kiron ist live → https://kirimcplay.tv/twitch")
elif msg_text.startswith("!wannwarderersteweltkrieg?"):
await message.channel.send("Der erste Weltkrieg ging vom 28. Juli 1914 bis zum 11. November 1918")
elif msg_text.startswith("!wissen") and (len(msg_text.split(" ")) == 2):
try:
search_term = msg_text.split(" ")[1]
summary = wikipedia.summary(search_term)
summary_parts = summary.split(". ")
if len(summary_parts) >= 3:
summary = f"{summary_parts[0]}. {summary_parts[1]}. {summary_parts[2]}."
elif len(summary_parts) == 2:
summary = f"{summary_parts[0]}. {summary_parts[1]}."
elif len(summary_parts) == 1:
summary = f"{summary_parts[0]}."
else:
message.channel.send("Tut mir leid, {message.author.mention}, dazu konnte ich keine Zusammenfassung finden")
if len(summary) > 2000:
link = f"https://lmgtfy.app/#gsc.tab=0&gsc.q={search_term}"
await message.channel.send(f"Entschuldige, {message.author.mention}, die ERSTEN DREI SÄTZE der Wikipedia-Zusammenfassung sind schon zu lang für eine Discord-Nachricht.\n{link}")
else:
await message.channel.send(
f"""\
\
**\
Hier hast du die Zusammenfassung des Wikipedia-Artikels für \
"{search_term}"!\
\
**\n\n{summary}""")
except PageError:
await message.channel.send(f"Tut mir leid, {message.author.mention}, dazu konnte ich keine Wikipedia-Seite finden.")
except DisambiguationError:
await message.channel.send(f"Tut mir leid, {message.author.mention}, dazu gibt es zu viele mögliche Einträge. Bitte versuche, dich etwas spezifischer auszudrücken.")
elif msg_text.startswith("!rollenzuteilung"):
message_with_command = message
role_msg_id = message_with_command.id
await message.channel.send(role_msg_id)
client.run(os.getenv('DISCORD_TOKEN'))