-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
1496 lines (1335 loc) · 46.2 KB
/
functions.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
from datetime import date, datetime, timedelta
from enum import Enum
from random import choice, randint, shuffle
import aiohttp
from humanfriendly import parse_timespan
from discord import (
Color,
Embed,
Guild,
Interaction,
Member,
Role,
SyncWebhook,
TextChannel,
User,
app_commands as Jeanne,
)
from discord.ext.commands import Bot, Context
from requests import get, post
from config import db, BB_WEBHOOK, CATBOX_HASH
from typing import Literal, Optional, List
current_time = date.today()
class Botban:
def __init__(self, user: User):
self.user = user
@property
def check_botbanned_user(self):
botbanned_data = db.execute(
"SELECT * FROM botbannedData WHERE user_id = ?", (self.user.id,)
).fetchone()
db.commit()
return botbanned_data is not None and self.user.id == botbanned_data[0]
async def add_botbanned_user(self, reason: str):
db.execute(
"INSERT OR IGNORE INTO botbannedData (user_id, reason) VALUES (?, ?)",
(
self.user.id,
reason,
),
)
db.execute("DELETE FROM serverxpData WHERE user_id = ?", (self.user.id,))
db.execute("DELETE FROM globalxpData WHERE user_id = ?", (self.user.id,))
db.execute(
"DELETE FROM userWallpaperInventory WHERE user_id = ?", (self.user.id,)
)
db.execute("DELETE FROM bankData WHERE user_id = ?", (self.user.id,))
db.commit()
botbanned = Embed(
title="User has been botbanned!",
description="They will no longer use Jeanne,permanently!",
)
botbanned.add_field(name="User", value=self.user)
botbanned.add_field(name="ID", value=self.user.id, inline=True)
botbanned.add_field(
name="Reason of ban",
value=reason,
inline=False,
)
botbanned.set_footer(
text="Due to this user botbanned, all data except warnings are immediately deleted from the database! They will have no chance of appealing their botban and all the commands executed by them are now rendered USELESS!"
)
botbanned.set_thumbnail(url=self.user.display_avatar)
webhook = SyncWebhook.from_url(BB_WEBHOOK)
webhook.send(embed=botbanned)
class Currency:
def __init__(self, user: User):
self.user = user
@property
def get_balance(self) -> int:
data = db.execute(
"SELECT amount FROM bankData WHERE user_id = ?", (self.user.id,)
).fetchone()
db.commit()
return 0 if data == None else data[0]
async def add_qp(self, amount: int):
cur = db.execute(
"INSERT OR IGNORE INTO bankData (user_id, amount, claimed_date) VALUES (?,?,?)",
(
self.user.id,
amount,
(current_time - timedelta(days=1)),
),
)
db.commit()
if cur.rowcount == 0:
db.execute(
"UPDATE bankData SET amount = amount + ? WHERE user_id = ?",
(
amount,
self.user.id,
),
)
db.commit()
async def remove_qp(self, amount: int):
db.execute(
"UPDATE bankData SET amount = amount - ? WHERE user_id = ?",
(
amount,
self.user.id,
),
)
db.commit()
async def give_daily(self):
next_claim = round((datetime.now() + timedelta(days=1)).timestamp())
qp = 200 if (datetime.today().weekday() > 4) else 100
cur = db.execute(
"INSERT OR IGNORE INTO bankData (user_id, amount, claimed_date) VALUES (?,?,?)",
(
self.user.id,
qp,
next_claim,
),
)
db.commit()
if cur.rowcount == 0:
db.execute(
"UPDATE bankData SET claimed_date = ?, amount = amount + ? WHERE user_id = ?",
(
next_claim,
qp,
self.user.id,
),
)
db.commit()
@property
def check_daily(self) -> int | Literal[True]:
data = db.execute(
"SELECT claimed_date FROM bankData WHERE user_id = ?", (self.user.id,)
).fetchone()
db.commit()
if (data == None) or (int(data[0]) < round(datetime.now().timestamp())):
return True
return int(data[0])
class Inventory:
def __init__(self, user: Optional[User] = None) -> None:
self.user = user
@staticmethod
def upload_to_catbox(image_url: str) -> str:
url = "https://catbox.moe/user/api.php"
userhash = CATBOX_HASH
data = {"reqtype": "urlupload", "userhash": userhash, "url": image_url}
response = post(url, data=data)
if response.status_code == 200:
return response.text
else:
return None
async def add_country(self, country: str):
db.execute(
"UPDATE userWallpaperInventory SET country = ? WHERE user_id = ?",
(
country,
self.user.id,
),
)
db.commit()
await Currency(self.user).remove_qp(500)
@property
def selected_country(self) -> str | None:
data = db.execute(
"SELECT country FROM userWallpaperInventory WHERE user_id = ? AND selected = ?",
(
self.user.id,
1,
),
).fetchone()
db.commit()
return None if data == None else data[0]
@staticmethod
def fetch_wallpapers() -> list:
data = db.execute("SELECT * FROM wallpapers").fetchall()
db.commit()
return data
@staticmethod
def get_wallpaper(name: str) -> tuple[str, str, str]:
wallpaper = db.execute(
"SELECT * FROM wallpapers WHERE name = ?", (name,)
).fetchone()
db.commit()
return str(wallpaper[0]), str(wallpaper[1]), str(wallpaper[2])
async def deselect_wallpaper(self) -> Literal[True] | None:
wallpaper = db.execute(
"SELECT wallpaper FROM userWallpaperInventory WHERE user_id = ? AND selected = ?",
(
self.user.id,
1,
),
).fetchone()
db.commit()
if wallpaper == None:
return None
db.execute(
"UPDATE userWallpaperInventory SET selected = ? WHERE user_id = ? AND wallpaper = ?",
(
0,
self.user.id,
wallpaper[0],
),
)
db.commit()
return True
async def add_user_wallpaper(self, name: str):
await self.deselect_wallpaper()
wallpaper = self.get_wallpaper(name)
db.execute(
"INSERT OR IGNORE INTO userWallpaperInventory (user_id, wallpaper, link, brightness, selected) VALUES (?,?,?,?,?)",
(
self.user.id,
wallpaper[1],
wallpaper[2],
100,
1,
),
)
db.commit()
await Currency(self.user).remove_qp(1000)
async def add_user_custom_wallpaper(self, name: str, url: str):
await self.deselect_wallpaper()
db.execute(
"INSERT OR IGNORE INTO userWallpaperInventory (user_id, wallpaper, link, brightness, selected) VALUES (?,?,?,?,?)",
(
self.user.id,
name,
url,
100,
1,
),
)
db.commit()
await Currency(self.user).remove_qp(1500)
@property
def selected_wallpaper(self) -> str | None:
wallpaper = db.execute(
"SELECT link FROM userWallpaperInventory WHERE user_id = ? and selected = ?",
(
self.user.id,
1,
),
).fetchone()
db.commit()
return None if (wallpaper == None) else str(wallpaper[0])
async def use_wallpaper(self, name: str):
await self.deselect_wallpaper()
db.execute(
"UPDATE userWallpaperInventory SET selected = ? WHERE wallpaper = ? AND user_id = ?",
(
1,
name,
self.user.id,
),
)
db.commit()
@property
def get_user_inventory(self) -> list | None:
wallpapers = db.execute(
"SELECT * FROM userWallpaperInventory WHERE user_id = ?", (self.user.id,)
).fetchall()
return wallpapers if wallpapers else None
@property
def get_brightness(self) -> int:
data = db.execute(
"SELECT brightness FROM userWallpaperInventory WHERE user_id = ? and selected = ?",
(
self.user.id,
1,
),
).fetchone()
return 100 if (data == None) else int(data[0])
async def set_brightness(self, brightness: int) -> Literal[False] | None:
try:
db.execute(
"UPDATE userWallpaperInventory SET brightness = ? WHERE user_id = ? AND selected = ?",
(
brightness,
self.user.id,
1,
),
)
db.commit()
except:
return False
async def set_bio(self, bio: str):
cur = db.execute(
"INSERT OR IGNORE INTO userBio (user_id, bio) VALUES (?,?)",
(
self.user.id,
bio,
),
)
db.commit()
if cur.rowcount == 0:
db.execute(
"UPDATE userBio SET bio = ? WHERE user_id = ?",
(
bio,
self.user.id,
),
)
db.commit()
@property
def get_bio(self) -> str | None:
data = db.execute(
"SELECT bio FROM userBio WHERE user_id = ?", (self.user.id,)
).fetchone()
db.commit()
return str(data[0]) if data else None
async def set_color(self, color: str):
cur = db.execute(
"INSERT OR IGNORE INTO userBio (user_id, color) VALUES (?,?)",
(
self.user.id,
color,
),
)
db.commit()
if cur.rowcount == 0:
db.execute(
"UPDATE userBio SET color = ? WHERE user_id = ?",
(
color,
self.user.id,
),
)
db.commit()
@property
def get_color(self) -> str | None:
data = db.execute(
"SELECT color FROM userBio WHERE user_id = ?", (self.user.id,)
).fetchone()
db.commit()
return str(data[0]) if data else None
class Levelling:
def __init__(
self, member: Optional[Member] = None, server: Optional[Guild] = None
) -> None:
self.member = member
self.server = server
@property
def get_member_xp(self) -> int:
xp = db.execute(
"SELECT exp FROM serverxpData WHERE user_id = ? AND guild_id = ?",
(self.member.id, self.server.id),
).fetchone()
db.commit()
return 0 if xp is None else int(xp[0])
@property
def get_user_xp(self) -> int:
xp = db.execute(
"SELECT exp FROM globalxpData WHERE user_id = ?", (self.member.id,)
).fetchone()
db.commit()
return 0 if xp is None else int(xp[0])
@property
def get_member_cumulated_xp(self) -> int:
cumulated_exp = db.execute(
"SELECT cumulative_exp FROM serverxpData WHERE user_id = ? AND guild_id = ?",
(self.member.id, self.server.id),
).fetchone()
db.commit()
return 0 if cumulated_exp is None else int(cumulated_exp[0])
@property
def get_user_cumulated_xp(self) -> int:
cumulated_exp = db.execute(
"SELECT cumulative_exp FROM globalxpData WHERE user_id = ?",
(self.member.id,),
).fetchone()
db.commit()
return 0 if cumulated_exp is None else int(cumulated_exp[0])
@property
def get_next_time_server(self) -> int:
next_time = db.execute(
"SELECT next_time FROM serverxpData WHERE user_id = ? AND guild_id = ?",
(self.member.id, self.server.id),
).fetchone()
db.commit()
return int(next_time[0]) if next_time is not None else 0
@property
def get_next_time_global(self) -> int:
next_time = db.execute(
"SELECT next_time FROM globalxpData WHERE user_id = ?", (self.member.id,)
).fetchone()
db.commit()
return int(next_time[0]) if next_time is not None else 0
@property
def get_member_level(self) -> int:
level = db.execute(
"SELECT lvl FROM serverxpData WHERE user_id = ? AND guild_id = ?",
(self.member.id, self.server.id),
).fetchone()
db.commit()
return int(level[0]) if level else 0
@property
def get_user_level(self) -> int:
level = db.execute(
"SELECT lvl FROM globalxpData WHERE user_id = ?", (self.member.id,)
).fetchone()
db.commit()
return int(level[0]) if level is not None else 0
async def add_xp(self, xp: int):
now_time = round(datetime.now().timestamp())
next_time = round((datetime.now() + timedelta(minutes=2)).timestamp())
global_cursor = db.execute(
"INSERT OR IGNORE INTO globalxpData (user_id, lvl, exp, next_time) VALUES (?, ?, ?, ?)",
(self.member.id, 0, xp, next_time),
)
db.commit()
if global_cursor.rowcount == 0:
if now_time >= self.get_next_time_global:
global_exp = self.get_user_xp
global_updated_exp = global_exp + xp
db.execute(
"UPDATE globalxpData SET exp = ?, next_time = ? WHERE user_id = ?",
(
global_updated_exp,
next_time,
self.member.id,
),
)
db.commit()
global_level = self.get_user_level
global_next_lvl_exp = (
(global_level * 50) + ((global_level - 1) * 25) + 50
)
if global_updated_exp >= global_next_lvl_exp:
db.execute(
"UPDATE globalxpData SET lvl = lvl + ?, exp = ? WHERE user_id = ?",
(1, 0, self.member.id),
)
db.commit()
server_cursor = db.execute(
"INSERT OR IGNORE INTO serverxpData (guild_id, user_id, lvl, exp, next_time) VALUES (?, ?, ?, ?, ?)",
(self.server.id, self.member.id, 0, xp, next_time),
)
db.commit()
if server_cursor.rowcount == 0:
if now_time > self.get_next_time_server:
server_exp = self.get_member_xp
server_updated_exp = server_exp + xp
db.execute(
"UPDATE serverxpData SET exp = ?, next_time = ? WHERE guild_id = ? AND user_id = ?",
(
server_updated_exp,
next_time,
self.server.id,
self.member.id,
),
)
db.commit()
server_level = self.get_member_level
server_next_lvl_exp = (
(server_level * 50) + ((server_level - 1) * 25) + 50
)
if server_updated_exp >= server_next_lvl_exp:
db.execute(
"UPDATE serverxpData SET lvl = lvl + ?, exp = ? WHERE guild_id = ? AND user_id = ?",
(
1,
0,
self.server.id,
self.member.id,
),
)
db.commit()
return self.get_level_channel
@property
def get_level_channel(
self,
) -> tuple[Optional[TextChannel], Optional[str], Optional[str]]:
return self.get_levelup_channel, self.get_levelup_msg, self.get_rank_up_update
@property
def get_levelup_msg(self) -> Optional[str]:
data = db.execute(
"SELECT levelup_message FROM serverData WHERE server = ?", (self.server.id,)
).fetchone()
return None if data is None else data[0]
@property
def get_levelup_channel(self) -> Optional[TextChannel]:
data = db.execute(
"SELECT levelup_channel FROM serverData WHERE server = ?", (self.server.id,)
).fetchone()
return None if data is None else self.server.get_channel(data[0])
@property
def get_rank_up_update(self) -> Optional[str]:
data = db.execute(
"SELECT rankup_message FROM serverData WHERE server = ?", (self.server.id,)
).fetchone()
return None if data is None else data[0]
@property
def get_role_reward(self) -> Optional[Role]:
data = db.execute(
"SELECT role FROM levelRewardData WHERE server = ? AND level = ?",
(self.server.id, self.get_member_level),
).fetchone()
return None if data is None else self.server.get_role(data[0])
@property
def get_server_rank(self) -> Optional[List]:
leaders_query = db.execute(
"SELECT * FROM serverxpData WHERE guild_id = ? ORDER BY lvl DESC LIMIT 15;",
(self.server.id,),
)
db.commit()
return leaders_query.fetchall()
@property
def get_global_rank(self) -> Optional[List]:
leaders_query = db.execute(
"SELECT * FROM globalxpData ORDER BY lvl DESC LIMIT 15;"
)
db.commit()
return leaders_query.fetchall()
def check_xpblacklist_channel(self, channel: TextChannel) -> Optional[TextChannel]:
data = db.execute(
"SELECT channel FROM xpChannelData WHERE server = ? AND channel = ?",
(self.server.id, channel.id),
).fetchone()
db.commit()
if data is None:
return None
return self.server.get_channel(data[0]) if data is not None else False
@property
def get_member_server_rank(self) -> Optional[int]:
result = db.execute(
"SELECT user_id FROM serverxpData WHERE guild_id = ? ORDER BY exp DESC",
(self.member.guild.id,),
).fetchall()
all_ids = [item[0] for item in result]
if self.member.id not in all_ids:
return None
rank = all_ids.index(self.member.id)
return rank + 1
@property
def get_user_global_rank(self) -> Optional[int]:
result = db.execute(
"SELECT user_id FROM globalxpData ORDER BY exp DESC"
).fetchall()
all_ids = [item[0] for item in result]
if self.member.id not in all_ids:
return None
rank = all_ids.index(self.member.id)
return rank + 1
@property
def get_blacklisted_channels(self) -> list[TextChannel] | None:
data = db.execute(
"SELECT channel FROM xpChannelData WHERE server = ?", (self.server.id,)
).fetchall()
db.commit()
return [self.server.get_channel(i[0]) for i in data] if data else None
@property
def list_all_roles(self) -> list | None:
data = db.execute(
"SELECT * FROM levelRewardData WHERE server = ? ORDER BY level ASC",
(self.server.id,),
).fetchall()
db.commit()
return [i for i in data] if data else None
class Manage:
def __init__(self, server: Guild) -> None:
self.server = server
async def remove_blacklist(self, channel: TextChannel):
db.execute(
"DELETE FROM xpChannelData WHERE server = ? AND channel = ?",
(
self.server.id,
channel.id,
),
)
db.commit()
async def add_level_channel(
self, channel: TextChannel, message: Optional[str] = None
) -> None:
message = message if message else "0"
cur = db.execute(
"INSERT OR IGNORE INTO serverData (server, levelup_channel, levelup_message) VALUES (?,?,?)",
(
self.server.id,
channel.id,
message,
),
)
db.commit()
if cur.rowcount == 0:
if channel:
db.execute(
"UPDATE serverData SET levelup_channel = ? WHERE server =?",
(
channel.id,
self.server.id,
),
)
db.commit()
if message:
db.execute(
"UPDATE serverData SET levelup_message = ? WHERE server =?",
(
message,
self.server.id,
),
)
db.commit()
async def add_rankup_rolereward(self, message: Optional[str] = None) -> None:
message = message if message else "0"
cur = db.execute(
"INSERT OR IGNORE INTO serverData (server, rankup_message) VALUES (?,?)",
(
self.server.id,
message,
),
)
db.commit()
if cur.rowcount == 0:
if message:
db.execute(
"UPDATE serverData SET rankup_message = ? WHERE server =?",
(
message,
self.server.id,
),
)
db.commit()
async def add_xpblacklist(self, channel: TextChannel):
db.execute(
"INSERT OR IGNORE INTO xpChannelData (server, channel) VALUES (?,?)",
(
self.server.id,
channel.id,
),
)
db.commit()
async def add_role_reward(self, role: Role, level: int):
data = db.execute(
"INSERT OR IGNORE INTO levelRewardData (server, role, level) VALUES (?,?,?)",
(
self.server.id,
role.id,
level,
),
)
db.commit()
if data.rowcount == 0:
db.execute(
"UPDATE levelRewardData SET level = ? WHERE server = ? AND role = ?",
(
level,
self.server.id,
role.id,
),
)
db.commit()
async def remove_role_reward(self, role: Role) -> Literal[True] | None:
data = db.execute(
"SELECT role FROM levelRewardData WHERE server = ?", (self.server.id,)
).fetchone()
db.commit()
if data == None:
return None
db.execute(
"DELETE FROM levelRewardData WHERE server = ? AND role = ?",
(
self.server.id,
role.id,
),
)
db.commit()
return True
async def set_welcomer_msg(self, json_script: str):
cur = db.execute(
"INSERT OR IGNORE INTO serverData (server, welcoming_message, leaving_message) VALUES (?,?,?)",
(
self.server.id,
json_script,
0,
),
)
db.commit()
if cur.rowcount == 0:
db.execute(
"UPDATE serverData SET welcoming_message = ? WHERE server = ?",
(
json_script,
self.server.id,
),
)
db.commit()
async def set_leaving_msg(self, json_script: str):
cur = db.execute(
"INSERT OR IGNORE INTO serverData (server, welcoming_message, leaving_message) VALUES (?,?,?)",
(
self.server.id,
0,
json_script,
),
)
db.commit()
if cur.rowcount == 0:
db.execute(
"UPDATE serverData SET leaving_message = ? WHERE server = ?",
(
json_script,
self.server.id,
),
)
db.commit()
async def set_welcomer(self, channel: TextChannel):
cursor = db.execute(
"INSERT OR IGNORE INTO serverData (server, welcoming_channel) VALUES (?,?)",
(
self.server.id,
channel.id,
),
)
db.commit()
if cursor.rowcount == 0:
db.execute(
f"UPDATE serverData SET welcoming_channel = ? WHERE server = ?",
(
channel.id,
self.server.id,
),
)
db.commit()
async def set_leaver(self, channel: TextChannel):
cursor = db.execute(
"INSERT OR IGNORE INTO serverData (server, leaving_channel) VALUES (?,?)",
(
self.server.id,
channel.id,
),
)
db.commit()
if cursor.rowcount == 0:
db.execute(
f"UPDATE serverData SET leaving_channel = ? WHERE server = ?",
(
channel.id,
self.server.id,
),
)
db.commit()
async def set_modloger(self, channel: TextChannel):
cursor = db.execute(
"INSERT OR IGNORE INTO serverData (server, modlog) VALUES (?,?)",
(
self.server.id,
channel.id,
),
)
db.commit()
if cursor.rowcount == 0:
db.execute(
f"UPDATE serverData SET modlog = ? WHERE server = ?",
(
channel.id,
self.server.id,
),
)
db.commit()
async def remove_welcomer(self):
db.execute(
"UPDATE serverData SET welcoming_channel = ? WHERE server = ?",
(
None,
self.server.id,
),
)
db.commit()
async def remove_leaver(self):
db.execute(
"UPDATE serverData SET leaving_channel = ? WHERE server = ?",
(
None,
self.server.id,
),
)
db.commit()
async def remove_modloger(self):
db.execute(
"UPDATE serverData SET modlog = ? WHERE server = ?",
(
None,
self.server.id,
),
)
db.commit()
async def remove_levelup(self):
db.execute(
"UPDATE serverData SET levelup_channel = ? WHERE server = ?",
(
None,
self.server.id,
),
)
db.commit()
async def remove_levelup_msg(self):
db.execute(
"UPDATE serverData SET levelup_message = ? WHERE server = ?",
(
None,
self.server.id,
),
)
db.commit()
async def remove_rolereward_msg(self):
db.execute(
"UPDATE serverData SET rankup_message = ? WHERE server = ?",
(
None,
self.server.id,
),
)
db.commit()
async def remove_welcomemsg(self):
db.execute(
"UPDATE serverData SET welcoming_message = ? WHERE server = ?",
(
None,
self.server.id,
),
)
db.commit()
async def remove_leavingmsg(self):
db.execute(
"UPDATE serverData SET leaving_message = ? WHERE server = ?",
(
None,
self.server.id,
),
)
db.commit()
async def add_confession_channel(self, channel: TextChannel):
db.execute(
"UPDATE serverData SET confess_channel = ? WHERE server = ?",
(
channel.id,
self.server.id,
),
)
db.commit()
@property
def get_confession_channel(self) -> TextChannel | None:
data = db.execute(
"SELECT confess_channel FROM serverData WHERE server = ?", (self.server.id,)
).fetchone()
db.commit()
return None if data == None else self.server.get_channel(data[0])
class Command:
def __init__(self, server: Guild) -> None:
self.server = server
def check_disabled(self, command: str):
try:
data = db.execute(
"SELECT command FROM disabledCommandsData WHERE server = ? AND command = ?",
(
self.server.id,
command,
),
).fetchone()
db.commit()
return data is not None and command == data[0]
except:
pass
async def disable(self, command: str):
db.execute(
"INSERT OR IGNORE INTO disabledCommandsData (server, command) VALUES (?,?)",
(
self.server.id,
command,
),
)
db.commit()
async def enable(self, command: str):
db.execute(
"DELETE FROM disabledCommandsData WHERE server = ? AND command = ?",
(
self.server.id,
command,
),
)
db.commit()
@property
def list_all_disabled(self) -> list[str]:
data = db.execute(
"SELECT command FROM disabledCommandsData WHERE server = ?",
(self.server.id,),
).fetchall()
db.commit()
return [str(i[0]) for i in data] if data else None
class Moderation:
def __init__(self, server: Optional[Guild] = None) -> None:
self.server = server
async def warn_user(
self, member: Member, moderator: int, reason: str, warn_id: int, date: int
):
db.execute(
"INSERT OR IGNORE INTO warnData (guild_id, user_id, moderator_id, reason, warn_id, date) VALUES (?,?,?,?,?,?)",
(
self.server.id,
member.id,
moderator,
reason,
warn_id,
date,
),
)
db.commit()
def fetch_warnings_server(self) -> list | None:
warnings = db.execute(
"SELECT * FROM warnDATA WHERE guild_id = ?", (self.server.id,)
).fetchall()
db.commit()