-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
2867 lines (2457 loc) · 98.9 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
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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import asyncio
import secrets
import shutil
import time
from collections import defaultdict
from crypt import methods
from typing import cast
import pyotp
import discord
import pytz
import wavelink
from bs4 import BeautifulSoup
from discord import Guild, TextChannel, Interaction, app_commands, ui
from discord.ext import commands, tasks
from quart import session, Markup
from quart_cors import cors
from assets.api.dash.save import *
from assets.api.dash.load import *
from assets.api.dash.oauth import *
from assets.api.public.oauth import *
from assets.api.public.security import *
from assets.api.public.endpoints import *
from assets.general.message.counting import *
from assets.general.message.guessing import *
from assets.general.message.suggestion import *
from assets.general.routine_events import *
from assets.general.get_saves import *
from assets.general.bot_events import *
from assets.dc.embed.embeds import *
from assets.dc.embed.buttons import *
from assets.dc.embed.ticket_buttons import *
from assets.general.message.security_check import *
from assets.general.message.globalchat import *
from assets.general.message.logging import *
from assets.sec_requests import Check
logger = Logger()
logger.working("Preparing to load the configuration files...")
logger.working("General configuration file is being loaded...")
config = configparser.ConfigParser()
config.read("config/runtime.conf")
logger.success("General configuration file has been loaded successfully!")
logger.working("Authentication configuration file is being loaded...")
auth0 = configparser.ConfigParser()
auth0.read("config/auth0.conf")
logger.success("Authentication configuration file has been loaded!")
logger.info("All config files have been applied.")
class PersistentViewBot(commands.AutoShardedBot):
def __init__(self):
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
super().__init__(
command_prefix=str(commands.when_mentioned_or(config["BOT"]["prefix"])),
intents=intents,
shard_count=config.getint("BOT", "shard_count"),
)
async def setup_hook(self) -> None:
self.add_view(VerifyButton())
self.add_view(TicketMenuButtons())
self.add_view(TicketChannelButtons())
self.add_view(TicketChannelDeleteButtons())
bot = PersistentViewBot()
check_api = Check()
logger.info("Booting...")
logger.info("Setting Boot Variables...")
icons_url = config["WEB"]["icon_url"]
top_gg_api = config["TOP_GG"]["url"]
top_gg_key = auth0["TOP_GG"]["api_key"]
# bot.wavelink = wavelink.Client(bot=bot)
app = Quart(
__name__,
template_folder=str(config["FLASK"]["template_folder"]),
static_folder=str(config["FLASK"]["static_folder"]),
)
app = cors(app)
app.secret_key = auth0["FLASK"]["secret"]
# *********************************************************************************************************************
boot_time = datetime.datetime.now()
server_count: int = len(bot.guilds)
api_requests: int = 0
emergency_mode: bool = config.getboolean("ADMINISTRATION", "sys_lockdown")
booted: bool = False
embedColor = discord.Color.from_rgb(
int(config["BOT"]["embed_color_red"]),
int(config["BOT"]["embed_color_green"]),
int(config["BOT"]["embed_color_blue"]),
) # FF5733
botadmin = list(map(int, auth0["DISCORD"]["admins"].split(",")))
encryption_key = auth0["FLASK"]["key"]
action_counts = defaultdict(lambda: defaultdict(lambda: {"actions": 0, "timestamp": 0}))
logger.success("Success!")
logger.waiting("Waiting for boot to finish...")
# *********************************************************************************************************************
app.secret_key = os.urandom(24)
CLIENT_ID = auth0["DISCORD"]["client_id"]
CLIENT_SECRET = auth0["DISCORD"]["client_secret"]
REDIRECT_URI = config["DASH"]["callback_url"]
API_ENDPOINT = "https://discord.com/api/v10"
AUTH_URL = "https://discord.com/api/oauth2/authorize"
TOKEN_URL = "https://discord.com/api/oauth2/token"
BOT_TOKEN = auth0["DISCORD"]["token"]
@app.route("/api/oauth/get/data/baxi")
async def update_guild_tokens():
guild = bot.get_guild(1175803684567908402)
channel = guild.get_channel(1262552071731675249)
return await sync_baxi_data(request=request, channel=channel, bot=bot)
# @app.before_request
# async def app_before_request():
# if request.endpoint != 'update_guild_tokens' or 'hello':
@app.route("/api/dash/get/active_systems/<int:guild_id>", methods=["GET"])
async def get_active_systems_dash_api(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/get/active_systems/ - Access authorized : ")
return await get_active_systems(request=request, guild=bot.get_guild(guild_id))
@app.route("/api/dash/settings/load/anti_raid/<int:guild_id>", methods=["GET"])
async def get_antiraid_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/load/anti_raid/ - Access authorized : ")
return await load_antiraid_settings(
request=request, guild=bot.get_guild(guild_id)
)
# noinspection PyBroadException
@app.route("/api/dash/settings/save/anti_raid/<int:guild_id>", methods=["POST"])
async def save_antiraid_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/save/anti_raid/ - Access authorized : ")
return await save_antiraid_settings(
request=request, guild=bot.get_guild(guild_id)
)
@app.route("/api/dash/settings/load/gc/<int:guild_id>", methods=["GET"])
async def get_gc_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/load/gc/ - Access authorized : ")
return await load_globalchat_settings(
request=request, guild=bot.get_guild(guild_id)
)
@app.route("/api/dash/settings/save/gc/<int:guild_id>", methods=["POST"])
async def save_gc_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/save/gc/ - Access authorized : ")
return await save_globalchat_settings(
request=request, guild=bot.get_guild(guild_id)
)
@app.route("/api/dash/settings/load/mgg/<int:guild_id>", methods=["GET"])
async def get_mgg_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/load/mgg/ - Access authorized : ")
return await load_minigame_guessing_settings(
request=request, guild=bot.get_guild(guild_id)
)
@app.route("/api/dash/settings/save/mgg/<int:guild_id>", methods=["POST"])
async def save_mgg_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/save/mgg/ - Access authorized : ")
return await save_minigame_guessing_settings(
request=request, guild=bot.get_guild(guild_id)
)
@app.route("/api/dash/settings/load/mgc/<int:guild_id>", methods=["GET"])
async def load_mgc_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/load/mgc/ - Access authorized : ")
return await load_minigame_counting_game(
request=request, guild=bot.get_guild(guild_id)
)
@app.route("/api/dash/settings/save/mgc/<int:guild_id>", methods=["POST"])
async def save_mgc_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/save/mgc/ - Access authorized : ")
return await save_minigame_counting_settings(
request=request, guild=bot.get_guild(guild_id)
)
@app.route("/api/dash/settings/load/sec/<int:guild_id>", methods=["GET"])
async def load_sec_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/load/sec/ - Access authorized : ")
return await load_security_settings(
request=request, guild=bot.get_guild(guild_id)
)
@app.route("/api/dash/settings/save/sec/<int:guild_id>", methods=["POST"])
async def save_sec_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/save/sec/ - Access authorized : ")
return await save_security_settings(
request=request, guild=bot.get_guild(guild_id)
)
@app.route("/api/dash/settings/load/welc/<int:guild_id>", methods=["GET"])
async def load_welc_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/load/welc/ - Access authorized : ")
return await load_welcome_settings(
request=request, guild=bot.get_guild(guild_id)
)
@app.route("/api/dash/settings/save/welc/<int:guild_id>", methods=["POST"])
async def save_welc_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/save/welc/ - Access authorized : ")
return await save_welcome_settings(
request=request, guild=bot.get_guild(guild_id)
)
@app.route("/api/dash/settings/load/verify/<int:guild_id>", methods=["GET"])
async def load_verify_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/load/verify/ - Access authorized : ")
return await load_verify_settings(
request=request, guild=bot.get_guild(guild_id)
)
# noinspection PyDunderSlots,PyUnresolvedReferences
@app.route("/api/dash/settings/save/verify/<int:guild_id>", methods=["POST"])
async def save_verify_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/save/verify/ - Access authorized : ")
return await save_verify_settings(
request=request, guild=bot.get_guild(guild_id)
)
@app.route("/api/dash/settings/load/sugg/<int:guild_id>", methods=["GET"])
async def load_sugg_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/load/sugg/ - Access authorized : ")
return await load_sugg_settings(request=request, guild=bot.get_guild(guild_id))
@app.route("/api/dash/settings/save/sugg/<int:guild_id>", methods=["POST"])
async def save_sugg_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/save/sugg/ - Access authorized : ")
return await save_sugg_settings(request=request, guild=bot.get_guild(guild_id))
@app.route("/api/dash/settings/load/ticket/<int:guild_id>", methods=["GET"])
async def load_ticket_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/load/ticket/ - Access authorized : ")
return await load_ticket_settings(
request=request, guild=bot.get_guild(guild_id)
)
@app.route("/api/dash/settings/save/ticket/<int:guild_id>", methods=["POST"])
async def save_ticket_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/save/ticket/ - Access authorized : ")
return await save_ticket_settings(
request=request, guild=bot.get_guild(guild_id)
)
@app.route("/api/dash/settings/load/log/<int:guild_id>", methods=["GET"])
async def load_log_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/load/log/ - Access authorized : ")
return await load_log_settings(request=request, guild=bot.get_guild(guild_id))
@app.route("/api/dash/settings/save/log/<int:guild_id>", methods=["POST"])
async def save_log_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/save/log/ - Access authorized : ")
return await save_log_settings(request=request, guild=bot.get_guild(guild_id))
@app.route("/api/dash/settings/load/auto_roles/<int:guild_id>", methods=["GET"])
async def load_autoroles_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/load/auto_roles/ - Access authorized : ")
return await load_autoroles_guild(
request=request, guild=bot.get_guild(guild_id)
)
@app.route("/api/dash/settings/save/auto_roles/<int:guild_id>", methods=["POST"])
async def save_autoroles_guild_settings(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/settings/save/auto_roles/ - Access authorized : ")
return await save_autoroles_guild(
request=request, guild=bot.get_guild(guild_id)
)
@app.route("/api/dash/msg/send/load/<int:guild_id>")
async def load_guild_channels_dash(guild_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/msg/send/load/ - Access authorized : ")
return await load_send_channels(request=request, guild=bot.get_guild(guild_id))
@app.route("/api/dash/msg/send/<int:guild_id>/<int:channel_id>")
async def send_guild_msg_dash(guild_id: int, channel_id: int):
data = await request.get_json()
code_check = verify_one_time_code(
one_time_code=data["otc"], secret_key=auth0["FLASK"]["secret"]
)
if not code_check:
logger.debug.info("Illegal access attempt")
return (
jsonify(
{
"error": "Illegal access attempt! The attempt to carry out this action was denied. Access token (otc) invalid."
}
),
401,
)
else:
logger.debug.info("/api/dash/msg/send/ - Access authorized : ")
return await send_guild_msg(
request=request, channel=bot.get_guild(guild_id).get_channel(channel_id)
)
async def send_message_on_settings_save(
guild: discord.Guild,
channel: discord.TextChannel,
button: str,
embed: discord.Embed,
):
try:
language = load_language_model(guild.id)
logger.debug.info(guild.name)
logger.debug.info(channel.name)
logger.debug.info(button)
if button == "verify":
await channel.send(embed=embed, view=VerifyButton())
elif button == "ticket":
await channel.send(embed=embed, view=TicketMenuButtons())
logger.debug.success("Message sent successfully")
return "sent", 200
except Exception as e:
logger.debug.warn("Error sending message: %s", e)
return "ERROR: " + str(e), 500
@app.route("/api/dash/check/staff/user/perms/")
async def send_user_persm_staff():
users = load_data("json/staff_users.json")
return users
@app.route("/")
async def hello():
return await load_homepage()
# noinspection PyUnresolvedReferences
@app.route("/api/check_api_key", methods=["GET"])
async def check_apikey():
id = request.args.get("requestid")
return await check_api_key(id=id)
def highlight_word(message:str, word:str):
if not message or not word:
return message
highlighted = message.lower().replace(
word.lower(),
f'<span style="color: crimson;"><b>{word.lower()}</b></span>'
)
return Markup(highlighted)
app.jinja_env.filters['highlight_word'] = highlight_word
@app.route("/chatfilterinfo")
async def show_info():
id = request.args.get("requestid")
return await load_chatfilterrequest_info(bot=bot, id=id)
@app.route("/userinfo")
async def userinfo():
id = request.args.get("idInput")
return await load_user_info(bot=bot, id=id)
@app.route("/welcome_img/<filename>")
async def serve_welcome_image(filename):
return await send_from_directory(app.config["welcome_img_folder"], filename)
@app.route("/v1/create-banner", methods=["POST"])
async def create_banner():
data = request.json
return await create_welcome_banner(data=data)
@app.route("/v1/chatfilter_event_data", methods=["POST"])
async def chatfilter_event_data():
data = request.json
return await get_chatfilter_data(data=data)
@app.errorhandler(404)
async def page_not_found(e): # noqa
return await load_error_page()
# ****************************************************************************************************************
logger.info("Quart is up and running!")
logger.waiting("Waiting for bot to login...")
@bot.event
async def on_ready():
logger.info("Logging in as {0.user}".format(bot))
logger.info("Bot Version:" + config["BOT"]["version"])
await bot.change_presence(
activity=discord.Activity(
type=discord.ActivityType.watching, name="dem Server beim Starten zu..."
)
)
try:
if not hasattr(bot, "synced"):
bot.synced = True
await bot.tree.sync()
logger.info("Bot synced with discord!")
else:
logger.info("Sync skipped. (No changes)")
logger.info(f"Bot started with {bot.shard_count} shards!")
await bot.change_presence(
activity=discord.Activity(
type=discord.ActivityType.playing,
name=f"on {len(bot.guilds)} Worlds! - v{config["BOT"]["version"]}",
)
)
except Exception as e: # noqa
await bot.change_presence(
activity=discord.Activity(
type=discord.ActivityType.watching,
name=f"die Crash logs durch... - Server start Fehler",
)
)
logger.error("ERROR SYNCING! " + str(e))
bot.loop.create_task(node_connet()) # noqa
check_actions.start()
global booted
booted = True
logger.success("ready!")
@bot.event
async def on_shard_ready(shard_id):
logger.info(f"Shard {shard_id} ready!")
async def node_connet():
try:
logger.waiting("Connecting to Lavalink node...")
node = wavelink.Node(
uri="http://lavalink.avocloud.net:2333",
resume_timeout=80,
password="jompo",
client=bot,
retries=3,
identifier="SoundNode1",
)
await wavelink.Pool.connect(nodes=[node], client=bot)
logger.success("Successfully connected to Lavalink!")
except TimeoutError:
logger.error("Timeout connecting to Node")
except Exception as e:
logger.error(f"Unknown error: {e}")
class GuidelinesButton(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
self.add_item(
discord.ui.Button(
style=discord.ButtonStyle.url,
label="Guidelines",
url="https://pyropixle.com/gtc/",
)
)
class DiscordButton(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
self.add_item(
discord.ui.Button(
style=discord.ButtonStyle.url,
label="Discord",
url="https://link.pyropixle.com/discord/",
)
)
class InviteButton(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
self.add_item(
discord.ui.Button(
style=discord.ButtonStyle.url,
label="Add me",
url="https://link.pyropixle.com/baxi/",
)
)
class InviteUndWebButton(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
self.add_item(
discord.ui.Button(
style=discord.ButtonStyle.url,
label="Add me",
url="https://link.pyropixle.com/baxi/",
)
)
self.add_item(
discord.ui.Button(
style=discord.ButtonStyle.url,
label="Website",
url="https://pyropixle.com/",
)
)
class InviteUndWebUndDiscordButton(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
self.add_item(
discord.ui.Button(
style=discord.ButtonStyle.url,
label="Add me",
url="https://link.pyropixle.com/baxi/",
)
)
self.add_item(
discord.ui.Button(
style=discord.ButtonStyle.url,
label="Website",
url="https://pyropixle.com/",
)
)
self.add_item(
discord.ui.Button(
style=discord.ButtonStyle.url,
label="Discord",
url="https://link.pyropixle.com/discord/",
)
)
self.add_item(
discord.ui.Button(
style=discord.ButtonStyle.url,
label="Privacy",
url="https://pyropixle.com/privacy/",
)
)
self.add_item(
discord.ui.Button(
style=discord.ButtonStyle.url,
label="GTC",
url="https://pyropixle.com/gtc/",
)
)
# noinspection SpellCheckingInspection
class InviteUndWebUndDiscordundDocsButton(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
self.add_item(
discord.ui.Button(
style=discord.ButtonStyle.url,
label="Add me",
url="https://link.pyropixle.com/baxi/",
)
)
self.add_item(
discord.ui.Button(
style=discord.ButtonStyle.url,
label="Website",
url="https://pyropixle.com/",
)
)
self.add_item(
discord.ui.Button(
style=discord.ButtonStyle.url,
label="Discord",
url="https://link.pyropixle.com/discord/",
)
)
self.add_item(
discord.ui.Button(
style=discord.ButtonStyle.url,
label="Docs",
url="https://docs.pyropixle.com/",
)
)
self.add_item(
discord.ui.Button(
style=discord.ButtonStyle.url,
label="Privacy",
url="https://pyropixle.com/privacy/",
)
)
self.add_item(
discord.ui.Button(
style=discord.ButtonStyle.url,
label="GTC",
url="https://pyropixle.com/gtc/",