-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFiltering.py
More file actions
474 lines (401 loc) · 25.8 KB
/
Filtering.py
File metadata and controls
474 lines (401 loc) · 25.8 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
import discord
from discord.ext import commands
from datetime import date
#Import from bot
import config
# Storing the channel id
channel_id = []
post_id = []
# Each user id gets added into this list in the create section
user = []
# Simple function to return all user ids in a list
def getUsers():
return user
# Create a whitelist
# !!ATTENTION IT IS NOT IN USE, THERE WILL BE WHITELISTS BUT YOU ARE UNABLE TO ADD OR REMOVE SOMETHING!!
wlist = []
def getWhitelist():
return wlist
# Create a blacklist
blist = []
def getBlacklist():
return blist
# Create a Keywordlist
klist = []
def getKeywordlist():
return klist
# Create a space for key value pairs
pairs = {}
def getPairs():
return pairs
class Filtering(commands.Cog):
def __init__(self, client):
self.client = client
# Add Function for whitelists
# reacts to !add_w 'Test' and adds Test to the whitelist
# checks if the user already has a whitelist
# Author: Sven
"""
The idea of the whitelist was to use it to filter for the courses from the feed in the case we get the whole ISIS-RSS-Feed.
Because of privacy reasons we dont get the whole feed. We still want to let the code inside if something changes in the futrue!
The Whitelist ist not implemented in the Listen function this has to be done if it is enabled!
@client.command()
async def add_w(ctx, message):
if ctx.channel.id in channel_id:
if ctx.author.id in pairs:
wlist[pairs.get(ctx.author.id)].append(message)
whitelist = discord.Embed(title="Whitelist", color=0x990000)
whitelist.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
whitelist.add_field(name="Your Whitelist now contains:",
value=wlist[pairs.get(ctx.author.id)],
inline=False)
whitelist.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"), icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=whitelist)
else:
createfirst = discord.Embed(title="Filter Lists", color=0x990000)
createfirst.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
createfirst.add_field(name="No filter lists yet!",
value="Filter lists will be created automatically after you have read the data security notice and agreed by reacting with the green checkmark emoji.",
inline=False)
createfirst.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"), icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=createfirst)
else:
notstarted = discord.Embed(title="Start me!", color=0x990000)
notstarted.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
notstarted.add_field(name="I am not started yet or i am not set up for this channel!",
value="Please start me with !start in this channel to access this command!",
inline=False)
notstarted.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"),
icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=notstarted)
# Remove Function for whitelists
# reacts to !remove_w 'Test' and removes Test from the whitelist
# Ignors the ValueError if 'Test' is not in whitelist (=nothing happens)
# checks if the user already has a whitelist
# Author: Sven
@client.command()
async def remove_w(ctx, message):
if ctx.channel.id in channel_id:
if ctx.author.id in pairs:
try:
wlist[pairs.get(ctx.author.id)].remove(message)
except ValueError:
pass
whitelist = discord.Embed(title="Whitelist", color=0x990000)
whitelist.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
whitelist.add_field(name="Your Whitelist now contains:",
value=wlist[pairs.get(ctx.author.id)],
inline=False)
whitelist.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"), icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=whitelist)
else:
createfirst = discord.Embed(title="Filter Lists", color=0x990000)
createfirst.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
createfirst.add_field(name="No filter lists yet!",
value="Filter lists will be created automatically after you have read the data security notice and agreed by reacting with the green checkmark emoji.",
inline=False)
createfirst.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"), icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=createfirst)
else:
notstarted = discord.Embed(title="Start me!", color=0x990000)
notstarted.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
notstarted.add_field(name="I am not started yet or i am not set up for this channel!",
value="Please start me with !start in this channel to access this command!",
inline=False)
notstarted.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"),
icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=notstarted)
"""
# Add Function for blacklists
# reacts to !add_b 'Test' and adds Test to the blacklist
# checks if the user already has a blacklist
# Author: Sven
@client.command()
async def add_b(ctx, message):
if ctx.channel.id in channel_id:
if ctx.author.id in pairs:
blist[pairs.get(ctx.author.id)].append(message)
blacklist = discord.Embed(title="Blacklist", color=0x990000)
blacklist.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
blacklist.add_field(name="Your Blacklist now contains:",
value=blist[pairs.get(ctx.author.id)],
inline=False)
blacklist.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"), icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=blacklist)
else:
createfirst = discord.Embed(title="Filter Lists", color=0x990000)
createfirst.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
createfirst.add_field(name="No filter lists yet!",
value="Filter lists will be created automatically after you have read the data security notice and agreed by reacting with the green checkmark emoji.",
inline=False)
createfirst.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"), icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=createfirst)
else:
notstarted = discord.Embed(title="Start me!", color=0x990000)
notstarted.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
notstarted.add_field(name="I am not started yet or i am not set up for this channel!",
value="Please start me with !start in this channel to access this command!",
inline=False)
notstarted.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"),
icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=notstarted)
# Remove Function for blacklists
# reacts to !remove_b 'Test' and removes Test from the blacklist
# Ignors the ValueError if 'Test' is not in blacklist (=nothing happens)
# checks if the user already has a blacklist
# Author: Sven
@client.command()
async def remove_b(ctx, message):
if ctx.channel.id in channel_id:
if ctx.author.id in pairs:
try:
blist[pairs.get(ctx.author.id)].remove(message)
except ValueError:
pass
blacklist = discord.Embed(title="Blacklist", color=0x990000)
blacklist.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
blacklist.add_field(name="Your Blacklist now contains:",
value=blist[pairs.get(ctx.author.id)],
inline=False)
blacklist.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"), icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=blacklist)
else:
createfirst = discord.Embed(title="Filter Lists", color=0x990000)
createfirst.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
createfirst.add_field(name="No filter lists yet!",
value="Filter lists will be created automatically after you have read the data security notice and agreed by reacting with the green checkmark emoji.",
inline=False)
createfirst.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"), icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=createfirst)
else:
notstarted = discord.Embed(title="Start me!", color=0x990000)
notstarted.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
notstarted.add_field(name="I am not started yet or i am not set up for this channel!",
value="Please start me with !start in this channel to access this command!",
inline=False)
notstarted.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"),
icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=notstarted)
# Add Function for Keywords
# reacts to !add_k 'Test' and adds Test to Keywords
# checks if the user already has a Keywordlist
# Author: Sven
@client.command()
async def add_k(ctx, message):
if ctx.channel.id in channel_id:
if ctx.author.id in pairs:
klist[pairs.get(ctx.author.id)].append(message)
keyword = discord.Embed(title="Keyword List", color=0x990000)
keyword.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
keyword.add_field(name="Your Keyword list now contains:",
value=klist[pairs.get(ctx.author.id)],
inline=False)
keyword.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"),
icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=keyword)
else:
createfirst = discord.Embed(title="Filter Lists", color=0x990000)
createfirst.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
createfirst.add_field(name="No filter lists yet!",
value="Filter lists will be created automatically after you have read the data security notice and agreed by reacting with the green checkmark emoji.",
inline=False)
createfirst.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"),
icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=createfirst)
else:
notstarted = discord.Embed(title="Start me!", color=0x990000)
notstarted.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
notstarted.add_field(name="I am not started yet or i am not set up for this channel!",
value="Please start me with !start in this channel to access this command!",
inline=False)
notstarted.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"),
icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=notstarted)
# Remove Function for Keywords
# reacts to !remove_k 'Test' and removes Test from the Keywords
# Ignors the ValueError if 'Test' is not in Keywords (=nothing happens)
# checks if the user already has a Keywordlist
# Author: Sven
@client.command()
async def remove_k(ctx, message):
if ctx.channel.id in channel_id:
if ctx.author.id in pairs:
try:
klist[pairs.get(ctx.author.id)].remove(message)
except ValueError:
pass
keyword = discord.Embed(title="Keyword List", color=0x990000)
keyword.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
keyword.add_field(name="Your Keyword list now contains:",
value=klist[pairs.get(ctx.author.id)],
inline=False)
keyword.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"),
icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=keyword)
else:
createfirst = discord.Embed(title="Filter Lists", color=0x990000)
createfirst.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
createfirst.add_field(name="No filter lists yet!",
value="Filter lists will be created automatically after you have read the data security notice and agreed by reacting with the green checkmark emoji.",
inline=False)
createfirst.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"),
icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=createfirst)
else:
notstarted = discord.Embed(title="Start me!", color=0x990000)
notstarted.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
notstarted.add_field(name="I am not started yet or i am not set up for this channel!",
value="Please start me with !start in this channel to access this command!",
inline=False)
notstarted.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"),
icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=notstarted)
# Shows current Filterlisten
# reacts to !show to show all lists but also reacts to !show_w , !show_b and !show_k
# these will only show one of the three lists. (if only !show is used it will show all)
# Checks which command is used
# Checks if the user already has Filterlisten
# Author: Sven
@client.command(aliases=["show_b", "show_k"]) #show_w removed from aliases
async def show(ctx):
if ctx.channel.id in channel_id:
if ctx.author.id in pairs:
current = discord.Embed(title="Filter Lists", color=0x990000)
current.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
""" Not used since Whitelist ist not implemented!
if ctx.invoked_with.lower() == "show_w":
current.add_field(name="Your Whitelist currently contains:",
value=wlist[pairs.get(ctx.author.id)],
inline=False)
When used change next if to elif!
"""
if ctx.invoked_with.lower() == "show_b":
current.add_field(name="Your Blacklist currently contains:",
value=blist[pairs.get(ctx.author.id)],
inline=False)
elif ctx.invoked_with.lower() == "show_k":
current.add_field(name="Your Keyword list currently contains:",
value=klist[pairs.get(ctx.author.id)],
inline=False)
else:
""" Not used since Whitelist ist not implemented!
current.add_field(name="Your Whitelist currently contains:",
value=wlist[pairs.get(ctx.author.id)],
inline=False)
"""
current.add_field(name="Your Blacklist currently contains:",
value=blist[pairs.get(ctx.author.id)],
inline=False)
current.add_field(name="Your Keyword list currently contains::",
value=klist[pairs.get(ctx.author.id)],
inline=False)
current.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"), icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=current)
else:
createfirst = discord.Embed(title="Filter lists", color=0x990000)
createfirst.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
createfirst.add_field(name="No filter lists yet!",
value="Filter lists will be created automatically after you have read the data security notice and agreed by reacting with the green checkmark emoji.",
inline=False)
createfirst.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"), icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=createfirst)
else:
notstarted = discord.Embed(title="Start me!", color=0x990000)
notstarted.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
notstarted.add_field(name="I am not started yet or i am not set up for this channel!",
value="Please start me with !start in this channel to access this command!",
inline=False)
notstarted.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"), icon_url="https://i.imgur.com/s8Ni2X1.png")
await ctx.author.send(embed=notstarted)
# waits for Reacts to the Datenschutz message
# Checks if the user reacted to the right message in the right channel
# CREATE USER LISTS AFTER REACTING
# If its the initial post it will also set the channel id
# It also removes the reaction after creating or removing the user
# Author Sven
@client.event
async def on_raw_reaction_add(payload):
if not channel_id:
channel_id.append(payload.channel_id)
if not post_id:
post_id.append(payload.message_id)
if payload.user_id not in config.Bot_Id:
if payload.channel_id in channel_id and payload.message_id in post_id:
if payload.emoji.name == '✅':
await create(payload.user_id)
channel = client.get_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
await message.remove_reaction(payload.emoji, payload.member)
elif payload.emoji.name == '❌':
await remove(payload.user_id)
channel = client.get_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
await message.remove_reaction(payload.emoji, payload.member)
# Creates the lists for Whitelist, Blacklist and Keywords
# Gives the user a key-value pair so each user has own lists
# checks if the user already has lists
# Author: Sven
async def create(id):
author = await client.fetch_user(id)
if id not in pairs:
pairs[id] = len(klist)
user.append(id)
wlist.append([])
blist.append([])
klist.append([])
create = discord.Embed(title="Filter lists", color=0x990000)
create.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
create.add_field(name="You have agreed to the data security statement and Filter lists were created:",
value="Add entries to your Blacklist with !add_b \n"
"Add entries to your Keyowrd list with !add_k \n"
"Get information about you Filter lists with !show \n"
"e.g. \"!add_k Klausur\" will add Klausur to your keywordlist \n",
inline=False)
create.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"), icon_url="https://i.imgur.com/s8Ni2X1.png")
await author.send(embed=create)
elif id not in user:
user.append(id)
create = discord.Embed(title="Filter lists", color=0x990000)
create.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
create.add_field(name="You agree to the Datenschutz again!",
value="Add entries to your Blacklist with !add_b \n"
"Add entries to your Keyowrd list with !add_k \n"
"Get information about you Filter lists with !show \n"
"e.g. \"!add_k Klausur\" will add Klausur to your keywordlist \n",
inline=False)
create.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"), icon_url="https://i.imgur.com/s8Ni2X1.png")
await author.send(embed=create)
else:
create = discord.Embed(title="Date security", color=0x990000)
create.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
create.add_field(name="You already agreed to the data security statement!",
value="Add entries to your Blacklist with !add_b \n"
"Add entries to your Keyowrd list with !add_k \n"
"Get information about you Filter lists with !show \n"
"e.g. \"!add_k Klausur\" will add Klausur to your keywordlist \n",
inline=False)
create.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"), icon_url="https://i.imgur.com/s8Ni2X1.png")
await author.send(embed=create)
# Same as create but remove
# Author: Sven
async def remove(id):
author = await client.fetch_user(id)
if id in user:
user.remove(id)
remove = discord.Embed(title="Data security", color=0x990000)
remove.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
remove.add_field(name="You don't agree to the data security statement anymore!",
value="Your filter lists will be saved for if you ever change your mind.",
inline=False)
remove.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"), icon_url="https://i.imgur.com/s8Ni2X1.png")
await author.send(embed=remove)
else:
remove = discord.Embed(title="Data security", color=0x990000)
remove.set_thumbnail(url="https://i.imgur.com/TBr8R7L.png")
remove.add_field(name="You haven't agreed to the data security statement!",
value="Nothing has changed, you can't use the bot.",
inline=False)
remove.set_footer(text="ISIS Bot v0.1 • " + date.today().strftime("%d/%m/%y"), icon_url="https://i.imgur.com/s8Ni2X1.png")
await author.send(embed=remove)
def setup(client):
client.add_cog(Filtering(client))