This repository was archived by the owner on Mar 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBot.py
More file actions
583 lines (333 loc) · 19.1 KB
/
Bot.py
File metadata and controls
583 lines (333 loc) · 19.1 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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
from json import load
from typing import *
from NewClass import AttrDict
import datetime
import discord
import Modules
import Utils
__version__ = "1.0.0"
client = discord.Client()
CONFIGS = AttrDict(load(open("Configs.json")))
TOKEN = CONFIGS.CONSTANTS.Token
Prefix = CONFIGS.CONSTANTS.Prefix
'''
You can see all the events in the following URL:
https://discordpy.readthedocs.io/en/latest/api.html#event-reference
'''
@client.event
async def on_connect():
for module in Modules.MODULES:
if Utils.EVENT.on_connect in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_connect)
@client.event
async def on_shard_connect(shard_id: int):
for module in Modules.MODULES:
if Utils.EVENT.on_shard_connect in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_shard_connect, shard_id)
@client.event
async def on_disconnect():
for module in Modules.MODULES:
if Utils.EVENT.on_disconnect in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_disconnect)
@client.event
async def on_shard_disconnect(shard_id: int):
for module in Modules.MODULES:
if Utils.EVENT.on_shard_disconnect in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_shard_disconnect, shard_id)
@client.event
async def on_ready():
for module in Modules.MODULES:
if Utils.EVENT.on_ready in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_ready)
@client.event
async def on_shard_ready(shard_id: int):
for module in Modules.MODULES:
if Utils.EVENT.on_shard_ready in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_shard_ready, shard_id)
@client.event
async def on_resumed():
for module in Modules.MODULES:
if Utils.EVENT.on_resumed in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_resumed)
@client.event
async def on_shard_resumed(shard_id: int):
for module in Modules.MODULES:
if Utils.EVENT.on_shard_resumed in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_shard_resumed, shard_id)
@client.event
async def on_error(event: str, *args, **kwargs):
print("ERROR BY DC!!!")
print(f"{event=}")
print(f"{args=}")
print(f"{kwargs=}")
for module in Modules.MODULES:
if Utils.EVENT.on_error in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_error, event, *args, **kwargs)
@client.event
async def on_socket_raw_receive(msg: Union[bytes, str]):
for module in Modules.MODULES:
if Utils.EVENT.on_socket_raw_receive in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_socket_raw_receive, msg)
@client.event
async def on_socket_raw_send(payload: Union[bytes, str]):
for module in Modules.MODULES:
if Utils.EVENT.on_socket_raw_send in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_socket_raw_send, payload)
@client.event
async def on_typing(channel: discord.abc.Messageable, user: Union[discord.User, discord.Member], when: datetime.datetime):
for module in Modules.MODULES:
if Utils.EVENT.on_typing in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_typing, channel, user, when)
@client.event
async def on_message(message: discord.Message):
if message.content.startswith(Prefix):
if message.content.split(" ")[0] == f"{Prefix}help":
embed = discord.Embed()
embed.title = "**__help__**"
embed.set_footer(text=f"requested by {message.author}", icon_url=message.author.avatar_url)
for module in Modules.MODULES:
if Utils.EVENT.on_message in Modules.libs[module].EVENTS:
if not Modules.libs[module].HELP.__str__() == "vanish":
embed.add_field(name=f"_{Prefix}{module}_", value=f"{Modules.libs[module].HELP}\n\n")
await message.channel.send(embed=embed)
else:
for module in Modules.MODULES:
if Utils.EVENT.on_message in Modules.libs[module].EVENTS:
if message.content.split(" ")[0] == f"{Prefix}{module}":
await Modules.libs[module].__main__(client, Utils.EVENT.on_message, message)
elif message.content.replace("!", "") == client.user.mention:
await message.channel.send(f"My Prefix is `{Prefix}`.")
else:
if "antispam" in list(Modules.libs.keys()):
await Modules.libs["antispam"].__main__(client, Utils.EVENT.on_message, message)
@client.event
async def on_message_delete(message: discord.Message):
for module in Modules.MODULES:
if Utils.EVENT.on_message_delete in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_message_delete, message)
@client.event
async def on_bulk_message_delete(messages: List[discord.Message]):
for module in Modules.MODULES:
if Utils.EVENT.on_bulk_message_delete in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_bulk_message_delete, messages)
@client.event
async def on_raw_message_delete(payload: discord.RawMessageDeleteEvent):
for module in Modules.MODULES:
if Utils.EVENT.on_raw_message_delete in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_raw_message_delete, payload)
@client.event
async def on_message_edit(before: discord.Message, after: discord.Message):
for module in Modules.MODULES:
if Utils.EVENT.on_message_edit in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_message_edit, before, after)
@client.event
async def on_raw_message_edit(payload: discord.RawMessageUpdateEvent):
for module in Modules.MODULES:
if Utils.EVENT.on_raw_message_edit in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_raw_message_edit, payload)
@client.event
async def on_reaction_add(reaction: discord.Reaction, user: Union[discord.Member, discord.User]):
for module in Modules.MODULES:
if Utils.EVENT.on_reaction_add in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_reaction_add, reaction, user)
@client.event
async def on_raw_reaction_add(payload: discord.RawReactionActionEvent):
for module in Modules.MODULES:
if Utils.EVENT.on_raw_reaction_add in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_raw_reaction_add, payload)
@client.event
async def on_reaction_remove(reaction: discord.Reaction, user: Union[discord.Member, discord.User]):
for module in Modules.MODULES:
if Utils.EVENT.on_reaction_remove in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_reaction_remove, reaction, user)
@client.event
async def on_raw_reaction_remove(payload: discord.RawReactionActionEvent):
for module in Modules.MODULES:
if Utils.EVENT.on_raw_reaction_remove in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_raw_reaction_remove, payload)
@client.event
async def on_reaction_clear(message: discord.Message, reactions: List[discord.Reaction]):
for module in Modules.MODULES:
if Utils.EVENT.on_reaction_clear in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_reaction_clear, message, reactions)
@client.event
async def on_raw_reaction_clear(payload: discord.RawReactionClearEvent):
for module in Modules.MODULES:
if Utils.EVENT.on_raw_reaction_clear in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_raw_reaction_clear, payload)
@client.event
async def on_reaction_clear_emoji(reaction: discord.Reaction):
for module in Modules.MODULES:
if Utils.EVENT.on_reaction_clear_emoji in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_reaction_clear_emoji, reaction)
@client.event
async def on_raw_reaction_clear_emoji(payload: discord.RawReactionClearEmojiEvent):
for module in Modules.MODULES:
if Utils.EVENT.on_raw_reaction_clear_emoji in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_raw_reaction_clear_emoji, payload)
@client.event
async def on_private_channel_delete(channel: discord.abc.PrivateChannel):
for module in Modules.MODULES:
if Utils.EVENT.on_private_channel_delete in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_private_channel_delete, channel)
@client.event
async def on_private_channel_create(channel: discord.abc.PrivateChannel):
for module in Modules.MODULES:
if Utils.EVENT.on_private_channel_create in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_private_channel_create, channel)
@client.event
async def on_private_channel_update(before: discord.GroupChannel, after: discord.GroupChannel):
for module in Modules.MODULES:
if Utils.EVENT.on_private_channel_update in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_private_channel_update, before, after)
@client.event
async def on_private_channel_pins_update(channel: discord.abc.PrivateChannel, last_pin: Optional[datetime.datetime]):
for module in Modules.MODULES:
if Utils.EVENT.on_private_channel_pins_update in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_private_channel_pins_update, channel, last_pin)
@client.event
async def on_guild_channel_delete(channel: discord.abc.GuildChannel):
for module in Modules.MODULES:
if Utils.EVENT.on_guild_channel_delete in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_guild_channel_delete, channel)
@client.event
async def on_guild_channel_create(channel: discord.abc.GuildChannel):
for module in Modules.MODULES:
if Utils.EVENT.on_guild_channel_create in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_guild_channel_create, channel)
@client.event
async def on_guild_channel_update(before: discord.GroupChannel, after: discord.GroupChannel):
for module in Modules.MODULES:
if Utils.EVENT.on_guild_channel_update in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_guild_channel_update, before, after)
@client.event
async def on_guild_channel_pins_update(channel: discord.abc.PrivateChannel, last_pin: Optional[datetime.datetime]):
for module in Modules.MODULES:
if Utils.EVENT.on_guild_channel_pins_update in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_guild_channel_pins_update, channel, last_pin)
@client.event
async def on_guild_integrations_update(guild: discord.Guild):
for module in Modules.MODULES:
if Utils.EVENT.on_guild_integrations_update in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_guild_integrations_update, guild)
@client.event
async def on_webhooks_update(channel: discord.abc.GuildChannel):
for module in Modules.MODULES:
if Utils.EVENT.on_webhooks_update in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_webhooks_update, channel)
@client.event
async def on_member_join(member: discord.Member):
for module in Modules.MODULES:
if Utils.EVENT.on_member_join in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_member_join, member)
@client.event
async def on_member_remove(member: discord.Member):
for module in Modules.MODULES:
if Utils.EVENT.on_member_remove in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_member_remove, member)
@client.event
async def on_member_update(before: discord.Member, after: discord.Member):
for module in Modules.MODULES:
if Utils.EVENT.on_member_update in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_member_update, before, after)
@client.event
async def on_user_update(before: discord.User, after: discord.User):
for module in Modules.MODULES:
if Utils.EVENT.on_user_update in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_user_update, before, after)
@client.event
async def on_guild_join(guild: discord.Guild):
for module in Modules.MODULES:
if Utils.EVENT.on_guild_join in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_guild_join, guild)
@client.event
async def on_guild_remove(guild: discord.Guild):
for module in Modules.MODULES:
if Utils.EVENT.on_guild_remove in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_guild_remove, guild)
@client.event
async def on_guild_update(before: discord.Guild, after: discord.Guild):
for module in Modules.MODULES:
if Utils.EVENT.on_guild_update in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_guild_update, before, after)
@client.event
async def on_guild_role_create(role: discord.Role):
for module in Modules.MODULES:
if Utils.EVENT.on_guild_role_create in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_guild_role_create, role)
@client.event
async def on_guild_role_delete(role: discord.Role):
for module in Modules.MODULES:
if Utils.EVENT.on_guild_role_delete in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_guild_role_delete, role)
@client.event
async def on_guild_role_update(before: discord.Role, after: discord.Role):
for module in Modules.MODULES:
if Utils.EVENT.on_guild_role_update in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_guild_role_update, before, after)
@client.event
async def on_guild_emojis_update(guild: discord.Guild, before: Sequence[discord.Emoji], after: Sequence[discord.Emoji]):
for module in Modules.MODULES:
if Utils.EVENT.on_guild_emojis_update in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_guild_emojis_update, guild, before, after)
@client.event
async def on_guild_available(guild: discord.Guild):
for module in Modules.MODULES:
if Utils.EVENT.on_guild_available in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_guild_available, guild)
@client.event
async def on_guild_unavailable(guild: discord.Guild):
for module in Modules.MODULES:
if Utils.EVENT.on_guild_unavailable in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_guild_unavailable, guild)
@client.event
async def on_voice_state_update(member: discord.Member, before: discord.VoiceState, after: discord.VoiceState):
for module in Modules.MODULES:
if Utils.EVENT.on_voice_state_update in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_voice_state_update, member, before, after)
@client.event
async def on_member_ban(guild: discord.Guild, user: Union[discord.User, discord.Member]):
for module in Modules.MODULES:
if Utils.EVENT.on_member_ban in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_member_ban, guild, user)
@client.event
async def on_member_unban(guild: discord.Guild, user: discord.User):
for module in Modules.MODULES:
if Utils.EVENT.on_member_unban in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_member_unban, guild, user)
@client.event
async def on_invite_create(invite: discord.Invite):
for module in Modules.MODULES:
if Utils.EVENT.on_invite_create in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_invite_create, invite)
@client.event
async def on_invite_delete(invite: discord.Invite):
for module in Modules.MODULES:
if Utils.EVENT.on_invite_delete in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_invite_delete, invite)
@client.event
async def on_group_join(channel: discord.GroupChannel, user: discord.User):
for module in Modules.MODULES:
if Utils.EVENT.on_group_join in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_group_join, channel, user)
@client.event
async def on_group_remove(channel: discord.GroupChannel, user: discord.User):
for module in Modules.MODULES:
if Utils.EVENT.on_group_remove in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_group_remove, channel, user)
@client.event
async def on_relationship_add(relationship: discord.Relationship):
for module in Modules.MODULES:
if Utils.EVENT.on_relationship_add in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_relationship_add, relationship)
@client.event
async def on_relationship_remove(relationship: discord.Relationship):
for module in Modules.MODULES:
if Utils.EVENT.on_relationship_remove in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_relationship_remove, relationship)
@client.event
async def on_relationship_update(before: discord.Relationship, after: discord.Relationship):
for module in Modules.MODULES:
if Utils.EVENT.on_relationship_update in Modules.libs[module].EVENTS:
await Modules.libs[module].__main__(client, Utils.EVENT.on_relationship_update, before, after)
client.run(TOKEN)