-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbot.py
1744 lines (1550 loc) · 61 KB
/
bot.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 base64
import datetime
import json
import os
import sqlite3
import sys
import urllib
import requests
from email import message
from os import listdir
from os.path import isfile
from os.path import join
from pydoc import describe
from time import time
import discord
from discord import Embed
from discord import guild_only
from discord.commands import option
from discord.ext import commands
from discord.ext.commands.core import command
from quickchart import QuickChart
from get_enviroment import ANNOUNCEMENTS_CHANNEL
from get_enviroment import COMMAND_PREFIX
from get_enviroment import DEV_SUGGESTIONS_CHANNEL
from get_enviroment import OWNER
from get_enviroment import SECURITY_CHANNEL
from get_enviroment import SECURITY_GUILD
from get_enviroment import SWEAR_WORDS_LIST
from get_enviroment import TOKEN
from get_enviroment import FEMTOLINK
# Language Loading
def jsonToDict(filename):
"""
:param filename:
"""
with open(filename) as f_in:
return json.load(f_in)
# get all language json files available
langFiles = [f for f in listdir("./langs") if isfile(join("./langs", f))]
languages = dict()
for languageFile in langFiles:
languages[languageFile.split(".")[0]] = jsonToDict("./langs/" +
languageFile)
# database import & connection
conn = sqlite3.connect("maindatabase1.db")
cur = conn.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS `warns` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`userid` INT(100),
`guildid` INT,
`reason` TEXT,
`timestamp` INT);
""")
cur.execute("""CREATE TABLE IF NOT EXISTS `customWords` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`guildid` INT,
`uploaderId`INT,
`word` TEXT,
`type` INT);
""")
cur.execute("""CREATE TABLE IF NOT EXISTS `settings` (
`guildid` INT(100) UNIQUE,
`automod` INT,
`language` TEXT);
""")
cur.execute("""CREATE TABLE IF NOT EXISTS `metrics` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`commandName` TEXT,
`timestamp` INT);
""")
hammericon = "https://images-ext-2.discordapp.net/external/OKc8xu6AILGNFY3nSTt7wGbg-Mi1iQZonoLTFg85o-E/%3Fsize%3D1024/https/cdn.discordapp.com/avatars/591633652493058068/e6011129c5169b29ed05a6dc873175cb.png?width=670&height=670"
intents = discord.Intents.default()
# intents.members = True
intents.message_content = True
bot = commands.Bot(command_prefix=COMMAND_PREFIX, intents=intents)
client = discord.Client()
bot.remove_command("help")
#
# HELP SECTIONN
#
@bot.slash_command(
name="help", description="Displays all the available commands for Hammer")
async def help(ctx):
# Define each page
descr = await GetTranslatedText(ctx.guild.id, "help_description")
embed = Embed(title="Hammer Bot Help",
description=descr,
colour=discord.Colour.lighter_grey())
user = await GetTranslatedText(ctx.guild.id, "user")
reason = await GetTranslatedText(ctx.guild.id, "reason")
seconds = await GetTranslatedText(ctx.guild.id, "seconds")
channel = await GetTranslatedText(ctx.guild.id, "channel")
embed.add_field(
name=await GetTranslatedText(ctx.guild.id, "help_moderation_title"),
value=f"""
{COMMAND_PREFIX}ban [{user}] <{reason}>
{COMMAND_PREFIX}kick [{user}] <{reason}>
{COMMAND_PREFIX}warn [{user}] <{reason}>
{COMMAND_PREFIX}softwarn [{user}] <{reason}>
{COMMAND_PREFIX}unwarn [{user}] [id] <{reason}>
{COMMAND_PREFIX}clearwarns [{user}] <{reason}>
{COMMAND_PREFIX}seewarns [{user}]
""",
inline=True,
)
embed.add_field(
name=await GetTranslatedText(ctx.guild.id, "help_automod_title"),
value=await GetTranslatedText(ctx.guild.id,
"help_automod_description",
COMMAND_PREFIX=COMMAND_PREFIX),
inline=True,
)
embed.add_field(
name=await GetTranslatedText(ctx.guild.id, "help_chatmod_title"),
value=f"""
{COMMAND_PREFIX}setdelay [{seconds}] <{reason}>\n
{COMMAND_PREFIX}mute [{user}] <{reason}>\n
{COMMAND_PREFIX}unmute [{user}] <{reason}>\n
{COMMAND_PREFIX}lock <{channel}> <{reason}>\n
{COMMAND_PREFIX}unlock <{channel}> <{reason}>\n
{COMMAND_PREFIX}bulkdelete [{channel}] [{user}] <{reason}>
""",
inline=True,
)
embed.add_field(
name=await GetTranslatedText(ctx.guild.id, "help_various_title"),
value=f"""
{COMMAND_PREFIX}whois [{user}]
""",
inline=True,
)
embed.add_field(
name=await GetTranslatedText(ctx.guild.id, "help_links_title"),
value=await GetTranslatedText(ctx.guild.id, "help_links_description"),
inline=True,
)
embed.add_field(
name=await GetTranslatedText(ctx.guild.id, "help_commands_title"),
value=await GetTranslatedText(ctx.guild.id,
"help_commands_description",
COMMAND_PREFIX=COMMAND_PREFIX),
inline=True,
)
embed.set_footer(
text=await GetTranslatedText(ctx.guild.id,
"footer_executed_by",
USERNAME=filterMember(ctx.author)),
icon_url=hammericon,
)
await ctx.respond(embed=embed)
#
# VARIOUS FUNCTIONS
#
# Function to alert the owner of something, normally to log use of eval command.
async def respondNotifOwner(text):
await bot.get_channel(int(SECURITY_CHANNEL)).respond(text)
async def GetWarnings(userid: int, guildid: int, fullData: bool = False):
cur.execute(
"SELECT * FROM warns WHERE userid=? AND guildid=?",
(
userid,
guildid,
),
)
rows = cur.fetchall()
if not fullData:
return len(rows)
else:
return rows
async def GetMetrics():
cur.execute("SELECT * FROM metrics")
rows = cur.fetchall()
return rows
# Function to add a warning and save it at the database
async def AddWarning(userid: int, guildid: int, reason):
warncount = await GetWarnings(userid, guildid)
cur.execute(
"""INSERT OR IGNORE INTO warns (userid, guildid, reason, timestamp)
VALUES (?, ?, ?, ?)
""",
(userid, guildid, reason, time()),
)
conn.commit()
return warncount + 1
async def Removewarn(userid: int, guildId: int, relativeWarnId: int):
c = 0
for warn in await GetWarnings(userid, guildId, fullData=True):
warnRealId, _, _, SubReason, _ = warn
if c == relativeWarnId:
# delete that row
cur.execute(
"DELETE FROM warns WHERE userid=? AND guildid=? AND id=? LIMIT 1",
(userid, guildId, warnRealId),
)
c = c + 1
conn.commit()
return c - 1
async def Clearwarns(userid: int, guildId: int):
# delete all rows
cur.execute("DELETE FROM warns WHERE userid=? AND guildid=?",
(userid, guildId))
conn.commit()
return
async def getAllWarns(userid: int, guildid: int):
allwarns = []
c = 0
for warn in await GetWarnings(userid, guildid, fullData=True):
_, _, _, SubReason, timestamp = warn
dt = timestamp
if c <= 9:
emojis = ":" + numToEmoji(c) + ":"
else:
emojis = str(c)
ddt = int(str(dt)[:str(dt).find(".")])
allwarns.append(await GetTranslatedText(guildid,
"warns_line_loop",
EMOJIS=emojis,
SUBREASON=SubReason,
DDT=ddt))
c = c + 1
return allwarns
async def GetAutomodCustomWords(guildid: int, mode: str):
wtype = 1 if mode == "allow" else 0
cur.execute("SELECT word FROM customWords WHERE guildid = ? AND type = ?",
(guildid, wtype))
words = cur.fetchall()
a = []
if len(words) > 0:
for word in words:
a.append(str(word[0]))
return a
else:
return [] # default is emptys
async def AddAllowedWord(guildid: int, userid: int, word: str):
# check if user is in blacklist
# if(word in await GetAutomodCustomWords(guildid, "deny")):
try:
cur.execute(
"""DELETE FROM customWords WHERE guildid=? AND word=? AND type=0
""",
(guildid, word),
)
cur.execute(
"""INSERT OR IGNORE INTO customWords (id, guildid, uploaderId, word, type)
VALUES (NULL, ?, ?, ?, 1)
""",
(guildid, userid, word),
)
conn.commit()
except:
return False
return True
async def AddDeniedWord(guildid: int, userid: int, word: str):
try:
cur.execute(
"""DELETE FROM customWords WHERE guildid=? AND word=? AND type=1
""",
(guildid, word),
)
cur.execute(
"""INSERT OR IGNORE INTO customWords (id, guildid, uploaderId, word, type)
VALUES (NULL, ?, ?, ?, 0)
""",
(guildid, userid, word),
)
conn.commit()
except:
return False
return True
async def GetSettings(guildid: int, index: int):
cur.execute("SELECT * FROM settings WHERE guildid = ? LIMIT 1",
(guildid, ))
rows = cur.fetchall()
if len(rows) > 0:
return rows[0][index]
else:
return 0 # default is off
async def GetTranslatedText(guildid: int, index: str, **replace):
global languages
dbLanguageRecord = await GetSettings(guildid, 2)
currentLanguage = ("en" if dbLanguageRecord == 0
or dbLanguageRecord == None else dbLanguageRecord)
text = languages[currentLanguage].get(index, "Word not translated yet.")
for oldString, newString in replace.items():
text = text.replace("{" + oldString + "}", str(newString))
return text
async def SendMetric(commandName: str):
cur.execute(
"""INSERT INTO metrics (id, commandName, timestamp)
VALUES (NULL, ?, ?)
""",
(commandName, int(time())),
)
conn.commit()
async def SaveSetting(guildid: int, module: str, value: str):
cur.execute("SELECT * FROM settings WHERE guildid = ? LIMIT 1",
(guildid, ))
rows = cur.fetchall()
# print(rows)
if len(
rows
) > 0: # cur.execute('INSERT INTO foo (a,b) values (?,?)', (strA, strB))
query = f"""UPDATE settings
SET {module}=?
WHERE guildid=?"""
cur.execute(query, (value, guildid))
else:
cur.execute(
"""INSERT OR IGNORE INTO settings (guildid, automod)
VALUES (?,?)
""",
(
guildid,
value,
),
)
conn.commit()
return
def ShortenLink(link: str):
"""
:param link: str:
"""
headers = {
"Authorization": f"Bearer {FEMTOLINK}",
"Content-Type": "application/json",
}
data = '{ "long_url": "' + link + '" }'
response = requests.post("https://femtolink.jaumelopez.dev/api/link",
headers=headers,
data=data)
return response.json()["link"]
def GenerateChart(datasets):
"""
:param datasets:
"""
qc = QuickChart()
qc.width = 500
qc.height = 300
qc.device_pixel_ratio = 2.0
qc.config = {
"type": "line",
"data": {
"datasets": datasets
},
"options": {
"scales": {
"xAxes": [{
"type": "time",
"time": {
"parser": "YYYY-MM-DD HH:mm:ss",
"displayFormats": {
"day": "DD/MM/YYYY"
},
},
}]
}
},
}
uurl = qc.get_url()
return uurl
# Function to try to send a message to a user
async def SendMessageTo(ctx, member, message):
try:
await member.send(message)
except:
await ctx.respond(
embed=ErrorEmbed(await
GetTranslatedText(ctx.guild.id,
"error_deliver_msg",
USERNAME=filterMember(member))),
ephemeral=True,
)
# Function to create a template for all errors.
def ErrorEmbed(error):
"""
:param error:
"""
embed = Embed(title=f":no_entry_sign: Error!", description=error)
embed.set_thumbnail(
url=
"https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ficonsplace.com%2Fwp-content%2Fuploads%2F_icons%2Fff0000%2F256%2Fpng%2Ferror-icon-14-256.png&f=1&nofb=1"
)
embed.set_footer(
text=f"Hammer",
icon_url=hammericon,
)
return embed
def unicodeLetterConver(word):
"""
:param word:
"""
f = ""
normalAlph = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789"
alphs = [
"𝐀𝐚𝐁𝐛𝐂𝐜𝐃𝐝𝐄𝐞𝐅𝐟𝐆𝐠𝐇𝐡𝐈𝐢𝐉𝐣𝐊𝐤𝐋𝐥𝐌𝐦𝐍𝐧𝐎𝐨𝐏𝐩𝐐𝐪𝐑𝐫𝐒𝐬𝐓𝐭𝐔𝐮𝐕𝐯𝐖𝐰𝐗𝐱𝐘𝐲𝐙𝐳𝟎𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟖𝟗",
"𝕬𝖆𝕭𝖇𝕮𝖈𝕯𝖉𝕰𝖊𝕱𝖋𝕲𝖌𝕳𝖍𝕴𝖎𝕵𝖏𝕶𝖐𝕷𝖑𝕸𝖒𝕹𝖓𝕺𝖔𝕻𝖕𝕼𝖖𝕽𝖗𝕾𝖘𝕿𝖙𝖀𝖚𝖁𝖛𝖂𝖜𝖃𝖝𝖄𝖞𝖅𝖟",
"𝑨𝒂𝑩𝒃𝑪𝒄𝑫𝒅𝑬𝒆𝑭𝒇𝑮𝒈𝑯𝒉𝑰𝒊𝑱𝒋𝑲𝒌𝑳𝒍𝑴𝒎𝑵𝒏𝑶𝒐𝑷𝒑𝑸𝒒𝑹𝒓𝑺𝒔𝑻𝒕𝑼𝒖𝑽𝒗𝑾𝒘𝑿𝒙𝒀𝒚𝒁𝒛",
"𝕒𝕓𝕔𝕕𝕖𝕗𝕘𝕙𝕚𝕛𝕜𝕝𝕞𝕟𝕠𝕡𝕢𝕣𝕤𝕥𝕦𝕧𝕨𝕩𝕪𝕫𝔸𝔹ℂ𝔻𝔼𝔽𝔾ℍ𝕀𝕁𝕂𝕃𝕄ℕ𝕆ℙℚℝ𝕊𝕋𝕌𝕍𝕎𝕏𝕐ℤ𝟘𝟙𝟚𝟛𝟜𝟝𝟞𝟟𝟠𝟡",
"🄰🄰🄱🄱🄲🄲🄳🄳🄴🄴🄵🄵🄶🄶🄷🄷🄸🄸🄹🄹🄺🄺🄻🄻🄼🄼🄽🄽🄾🄾🄿🄿🅀🅀🅁🅁🅂🅂🅃🅃🅄🅄🅅🅅🅆🅆🅇🅇🅈🅈🅉🅉0123456789",
"🅰🅰🅱🅱🅲🅲🅳🅳🅴🅴🅵🅵🅶🅶🅷🅷🅸🅸🅹🅹🅺🅺🅻🅻🅼🅼🅽🅽🅾🅾🅿🅿🆀🆀🆁🆁🆂🆂🆃🆃🆄🆄🆅🆅🆆🆆🆇🆇🆈🆈🆉🆉𝟎𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟖𝟗",
"ⒶⓐⒷⓑⒸⓒⒹⓓⒺⓔⒻⓕⒼⓖⒽⓗⒾⓘⒿⓙⓀⓚⓁⓛⓂⓜⓃⓝⓄⓞⓅⓟⓆⓠⓇⓡⓈⓢⓉⓣⓊⓤⓋⓥⓌⓦⓍⓧⓎⓨⓏⓩ0①②③④⑤⑥⑦⑧⑨",
"🅐🅐🅑🅑🅒🅒🅓🅓🅔🅔🅕🅕🅖🅖🅗🅗🅘🅘🅙🅙🅚🅚🅛🅛🅜🅜🅝🅝🅞🅞🅟🅟🅠🅠🅡🅡🅢🅢🅣🅣🅤🅤🅥🅥🅦🅦🅧🅧🅨🅨🅩🅩𝟎𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟖𝟗",
"ᗩᗩᗷᗷᑕᑕᗪᗪEEᖴᖴGGᕼᕼIIᒍᒍKKᒪᒪᗰᗰᑎᑎOOᑭᑭᑫᑫᖇᖇᔕᔕTTᑌᑌᐯᐯᗯᗯ᙭᙭YYᘔᘔ0123456789",
"𝗔𝗮𝗕𝗯𝗖𝗰𝗗𝗱𝗘𝗲𝗙𝗳𝗚𝗴𝗛𝗵𝗜𝗶𝗝𝗷𝗞𝗸𝗟𝗹𝗠𝗺𝗡𝗻𝗢𝗼𝗣𝗽𝗤𝗾𝗥𝗿𝗦𝘀𝗧𝘁𝗨𝘂𝗩𝘃𝗪𝘄𝗫𝘅𝗬𝘆𝗭𝘇𝟬𝟭𝟮𝟯𝟰𝟱𝟲𝟳𝟴𝟵",
"𝘼𝙖𝘽𝙗𝘾𝙘𝘿𝙙𝙀𝙚𝙁𝙛𝙂𝙜𝙃𝙝𝙄𝙞𝙅𝙟𝙆𝙠𝙇𝙡𝙈𝙢𝙉𝙣𝙊𝙤𝙋𝙥𝙌𝙦𝙍𝙧𝙎𝙨𝙏𝙩𝙐𝙪𝙑𝙫𝙒𝙬𝙓𝙭𝙔𝙮𝙕𝙯𝟎𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟖𝟗",
"𝘈𝘢𝘉𝘣𝘊𝘤𝘋𝘥𝘌𝘦𝘍𝘧𝘎𝘨𝘏𝘩𝘐𝘪𝘑𝘫𝘒𝘬𝘓𝘭𝘔𝘮𝘕𝘯𝘖𝘰𝘗𝘱𝘘𝘲𝘙𝘳𝘚𝘴𝘛𝘵𝘜𝘶𝘝𝘷𝘞𝘸𝘟𝘹𝘠𝘺𝘡𝘻0123456789",
"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789",
"⒜⒜⒝⒝⒞⒞⒟⒟⒠⒠⒡⒡⒢⒢⒣⒣⒤⒤⒥⒥⒦⒦⒧⒧⒨⒨⒩⒩⒪⒪⒫⒫⒬⒬⒭⒭⒮⒮⒯⒯⒰⒰⒱⒱⒲⒲⒳⒳⒴⒴⒵⒵0⑴⑵⑶⑷⑸⑹⑺⑻⑼",
"𝙰𝚊𝙱𝚋𝙲𝚌𝙳𝚍𝙴𝚎𝙵𝚏𝙶𝚐𝙷𝚑𝙸𝚒𝙹𝚓𝙺𝚔𝙻𝚕𝙼𝚖𝙽𝚗𝙾𝚘𝙿𝚙𝚀𝚚𝚁𝚛𝚂𝚜𝚃𝚝𝚄𝚞𝚅𝚟𝚆𝚠𝚇𝚡𝚈𝚢𝚉𝚣𝟶𝟷𝟸𝟹𝟺𝟻𝟼𝟽𝟾𝟿",
"𝖠𝖺𝖡𝖻𝖢𝖼𝖣𝖽𝖤𝖾𝖥𝖿𝖦𝗀𝖧𝗁𝖨𝗂𝖩𝗃𝖪𝗄𝖫𝗅𝖬𝗆𝖭𝗇𝖮𝗈𝖯𝗉𝖰𝗊𝖱𝗋𝖲𝗌𝖳𝗍𝖴𝗎𝖵𝗏𝖶𝗐𝖷𝗑𝖸𝗒𝖹𝗓𝟢𝟣𝟤𝟥𝟦𝟧𝟨𝟩𝟪𝟫",
"🇦🇦🇧🇧🇨🇨🇩🇩🇪🇪🇫🇫🇬🇬🇭🇭🇮🇮🇯🇯🇰🇰🇱🇱🇲🇲🇳🇳🇴🇴🇵🇵🇶🇶🇷🇷🇸🇸🇹🇹🇺🇺🇻🇻🇼🇼🇽🇽🇾🇾🇿🇿0123456789",
"คค๖๖¢¢໓໓ēēffງງhhiiววkkll๓๓ຖຖ໐໐pp๑๑rrŞŞttนนงงຟຟxxฯฯຊຊ0123456789",
"₳₳฿฿₵₵ĐĐɆɆ₣₣₲₲ⱧⱧłłJJ₭₭ⱠⱠ₥₥₦₦ØØ₱₱QQⱤⱤ₴₴₮₮ɄɄVV₩₩ӾӾɎɎⱫⱫ0123456789",
"卂卂乃乃匚匚ᗪᗪ乇乇千千ᎶᎶ卄卄丨丨フフҜҜㄥㄥ爪爪几几ㄖㄖ卩卩ɊɊ尺尺丂丂ㄒㄒㄩㄩᐯᐯ山山乂乂ㄚㄚ乙乙0123456789",
"ꭿaꞴꞵꞒꞓDdEꬲꟻꝭGgꞪꜧIꭵꞲjꞢꞣꝆꝇMꝳꞐꝴꝊꭴꝔꝓꝖꝙꮢꞧꞨꞩꮦtUuꝞꝟꝠꝡꭓꭗꝨꝩZz0123456789",
"ДӓѢѣҀҁDdЗЭFfGgњћIїJjККLlMmЙђФѳPpQqЯГSsҬҭЦЧVѵШШЖxӲӳZz0123456789",
"ᴀᴀʙʙᴄᴄᴅᴅᴇᴇꜰꜰɢɢʜʜɪɪᴊᴊᴋᴋʟʟᴍᴍɴɴᴏᴏᴩᴩQqʀʀꜱꜱᴛᴛᴜᴜᴠᴠᴡᴡxxYyᴢᴢ0123456789",
"ₐₐBbCcDdₑₑFfGgₕₕᵢᵢⱼⱼₖₖₗₗₘₘₙₙₒₒₚₚQqᵣᵣₛₛₜₜᵤᵤᵥᵥWwₓₓYyZz₀₁₂₃₄₅₆₇₈₉",
"ᴬᵃᴮᵇᶜᶜᴰᵈᴱᵉᶠᶠᴳᵍᴴʰᴵⁱᴶʲᴷᵏᴸˡᴹᵐᴺⁿᴼᵒᴾᵖQqᴿʳˢˢᵀᵗᵁᵘⱽᵛᵂʷˣˣʸʸᶻᶻ⁰¹²³⁴⁵⁶⁷⁸⁹",
"ΔΔββĆĆĐĐ€€₣₣ǤǤĦĦƗƗĴĴҜҜŁŁΜΜŇŇØØƤƤΩΩŘŘŞŞŦŦỮỮVVŴŴЖЖ¥¥ŽŽ0123456789",
"ααɓɓ૮૮∂∂ε僃ɠɠɦɦเเʝʝҡҡℓℓɱɱɳɳσσρρφφ૨૨รรƭƭµµѵѵωωאאყყƶƶ0123456789",
]
for l in word:
if l in normalAlph:
f = f + l
continue
for alphabet in alphs:
pos = alphabet.find(l)
if pos != -1:
print("found", f)
f = f + normalAlph[pos]
break
return f
def numToEmoji(num):
"""
:param num:
"""
v = ""
if num == 0:
v = "zero"
if num == 1:
v = "one"
if num == 2:
v = "two"
if num == 3:
v = "three"
if num == 4:
v = "four"
if num == 5:
v = "five"
if num == 6:
v = "six"
if num == 7:
v = "seven"
if num == 8:
v = "eight"
if num == 9:
v = "nine"
return v
def filterMember(member: discord.Member):
"""
:param member: discord.Member:
:param member: discord.Member:
"""
username, discriminator = str(member).split("#")
if discriminator == "0":
return username
return str(member)
#
# MAIN COMMANDS - BOT
#
# # swear words detector
@bot.event
async def on_message(message):
await bot.process_commands(message)
# Skip bot messages
if message.author.bot:
return
if message.content == "" or message.content == None:
return
settings = await GetSettings(message.guild.id, 1)
if settings != 1:
return # user has disabled Automod or does not have it installed
words = message.content.split()
allowed_words_guild_list = await GetAutomodCustomWords(
message.guild.id, "allow")
denied_words_guild_list = await GetAutomodCustomWords(
message.guild.id, "deny")
print("scanned: ", message.content)
for word in words:
# print("scanning word:",word)
originalWord = str(word).lower()
word = unicodeLetterConver(str(word).lower())
if word in allowed_words_guild_list:
continue
if word in denied_words_guild_list or word in SWEAR_WORDS_LIST:
member = message.author
# if member == .has perms :
# return # is admin so don't warn it
# maybe new function to optionally say the word (settings)
descr = await GetTranslatedText(
message.guild.id,
"automod_warn_description",
USERNAME=filterMember(member),
)
embed = Embed(
title=await GetTranslatedText(
message.guild.id,
"automod_warn_title",
USERNAME=filterMember(member),
),
description=descr,
)
embed.set_footer(
text=await GetTranslatedText(message.guild.id,
"automod_warn_footer"),
icon_url=hammericon,
)
embed.set_thumbnail(url=member.display_avatar)
warn = await AddWarning(
member.id,
message.guild.id,
await GetTranslatedText(message.guild.id,
"automod_warn_reason"),
)
await SendMetric("automod")
s = "s" if warn > 1 else ""
embed.add_field(
name=await GetTranslatedText(message.guild.id,
"automod_count_title"),
value=await GetTranslatedText(
message.guild.id,
"automod_count_description",
USERNAME=filterMember(member),
WARN=warn,
S=s,
),
inline=True,
)
bannedmessage = (
message.content[:message.content.find(originalWord)] + "~~" +
word + "~~" +
message.content[message.content.find(originalWord) +
len(word):])
embed.add_field(
name=await GetTranslatedText(message.guild.id,
"automod_removed_title"),
value=await GetTranslatedText(
message.guild.id,
"automod_removed_description",
BANNEDMESSAGE=bannedmessage,
),
inline=True,
)
embed.add_field(
name=await GetTranslatedText(message.guild.id,
"automod_nothappy_title"),
value=await GetTranslatedText(message.guild.id,
"automod_nothappy_description"),
inline=False,
)
await message.channel.send(embed=embed)
await message.delete()
try:
channel = await member.create_dm()
await channel.send(embed=embed)
except:
embed = ErrorEmbed(
await message.channel.send(embed=ErrorEmbed(
await GetTranslatedText(
message.guild.id,
"error_deliver_msg",
USERNAME=filterMember(member),
)), ), )
message.channel.send(embed=embed)
@bot.event
async def on_ready():
print("HAMMER BOT Ready!", datetime.datetime.now())
await bot.sync_commands()
await bot.change_presence(activity=discord.Activity(
type=discord.ActivityType.watching, name="you"))
botname = await bot.application_info()
print("logged in as:", botname.name)
if botname.name == "Hammer":
print("I'm on:")
print(len(bot.guilds), "servers")
print(sum(1 for x in bot.get_all_channels()), "channels")
print(sum(1 for x in bot.get_all_members()), "members")
chnl = bot.get_channel(int(ANNOUNCEMENTS_CHANNEL))
await chnl.send("Bot UP!")
print("Sent message to #" + str(chnl))
debug = False # ALWAYS FALSE!
@bot.slash_command(guild_only=True,
name="hello",
guild_ids=[int(SECURITY_GUILD)])
async def hello(ctx):
await ctx.defer()
await SendMetric("hello")
text = await GetTranslatedText(ctx.guild.id, "hello_command")
await ctx.respond(text)
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.respond(
await GetTranslatedText(ctx.guild.id,
"error_404",
ERROR=error,
COMMAND_PREFIX=COMMAND_PREFIX),
ephemeral=True,
)
if isinstance(error, commands.MissingPermissions):
error = getattr(error, "original", error)
missing = [
perm.replace("_", " ").replace("guild", "server").title()
for perm in error.missing_perms
]
if len(missing) > 2:
fmt = "{}, and {}".format("**, **".join(missing[:-1]), missing[-1])
else:
fmt = " and ".join(missing)
await ctx.respond(
await GetTranslatedText(ctx.guild.id, "error_403", FMT=fmt),
ephemeral=True,
)
@bot.slash_command(
guild_only=True,
name="whois",
description="Displays all the public info from a specific user",
)
async def whois(ctx, member: discord.Member):
await SendMetric("whois")
try:
username, discriminator = str(member).split("#")
discriminator = "" if discriminator == "0" else discriminator
isbot = ":white_check_mark:" if member.bot else ":negative_squared_cross_mark:"
descr = await GetTranslatedText(
ctx.guild.id,
"whois_description",
NICK=member.nick,
USERNAME=username,
DISCRIMINATOR=discriminator,
CREATEDAT=member.created_at,
JOINEDAT=member.joined_at,
ISBOT=isbot,
MEMBERID=member.id,
AVATAR=member.display_avatar,
TOPROLE=member.top_role,
WARNS=await GetWarnings(member.id, ctx.guild.id),
)
embed = Embed(
title=await GetTranslatedText(ctx.guild.id,
"whois_title",
MEMBER=filterMember(member)),
description=descr,
)
embed.set_thumbnail(url=member.display_avatar)
embed.set_footer(
text=await GetTranslatedText(ctx.guild.id,
"footer_executed_by",
USERNAME=filterMember(ctx.author)),
icon_url=hammericon,
)
await ctx.respond(embed=embed)
except Exception as e:
await ctx.respond(e)
@bot.slash_command(
guild_only=True,
name="ban",
description="Keeps out a user permanently, forbidding its entry",
)
@discord.default_permissions(ban_members=True, )
async def ban(ctx, member: discord.Member, *, reason=None):
await SendMetric("ban")
if member == ctx.author:
await ctx.respond(await GetTranslatedText(ctx.guild.id,
"error_self_ban"),
ephemeral=True)
return
if reason == None:
reason = await GetTranslatedText(ctx.guild.id,
"punishment_default_reason")
message = await GetTranslatedText(ctx.guild.id,
"ban_msg",
GUILD=ctx.guild.name,
REASON=reason)
descr = await GetTranslatedText(ctx.guild.id,
"ban_description",
MEMBER=filterMember(member),
REASON=reason)
embed = Embed(
title=await GetTranslatedText(ctx.guild.id,
"ban_title",
MEMBER=filterMember(member)),
description=descr,
)
embed.set_image(url="https://i.imgflip.com/19zat3.jpg")
embed.set_footer(
text=await GetTranslatedText(ctx.guild.id,
"footer_executed_by",
USERNAME=filterMember(ctx.author)),
icon_url=hammericon,
)
if not debug:
try:
await member.ban(reason=reason)
except:
await ctx.respond(
embed=ErrorEmbed(await GetTranslatedText(
ctx.guild.id,
"error_ban_perm",
MEMBER=filterMember(member))),
ephemeral=True,
)
return
embed.set_thumbnail(url=member.display_avatar)
await ctx.respond(embed=embed)
await SendMessageTo(ctx, member, message)
@bot.slash_command(guild_only=True,
name="kick",
description="Kicks out a member from the server")
@discord.default_permissions(kick_members=True, )
async def kick(ctx, member: discord.Member, *, reason=None):
await SendMetric("kick")
if member == ctx.author:
await ctx.respond(await GetTranslatedText(ctx.guild.id,
"error_self_kick"),
ephemeral=True)
return
if reason == None:
reason = await GetTranslatedText(ctx.guild.id,
"punishment_default_reason")
message = await GetTranslatedText(ctx.guild.id,
"kick_msg",
GUILD=ctx.guild.name,
REASON=reason)
if not debug:
try:
await member.kick(reason=reason)
except:
ctx.respond(
embed=ErrorEmbed(await GetTranslatedText(
ctx.guild.id,
"error_kick_perm",
MEMBER=filterMember(member))),
ephemeral=True,
)
return
descr = await GetTranslatedText(ctx.guild.id,
"kick_description",
MEMBER=filterMember(member),
REASON=reason)
embed = Embed(
title=await GetTranslatedText(ctx.guild.id,
"kick_title",
MEMBER=filterMember(member)),
description=descr,
)
embed.set_footer(
text=await GetTranslatedText(ctx.guild.id,
"footer_executed_by",
USERNAME=filterMember(ctx.author)),
icon_url=hammericon,
)
embed.set_thumbnail(url=member.display_avatar)
# # embed.image = member.image
await ctx.respond(embed=embed)
await SendMessageTo(ctx, member, message)
@bot.slash_command(
guild_only=True,
name="warn",
description="Sets a warning for a user, at 3 warns/strikes they get kicked",
)
@option(
"softwarn",
description="Select on/off",
autocomplete=discord.utils.basic_autocomplete(["on", "off"]),
)
@discord.default_permissions(administrator=True, )
async def warn(ctx,
member: discord.Member,
reason=None,
softwarn: bool = False):
await SendMetric("warn")
if member == ctx.author:
await ctx.respond(await GetTranslatedText(ctx.guild.id,
"error_self_warn"),
ephemeral=True)
return
if reason == None:
reason = await GetTranslatedText(ctx.guild.id,
"punishment_default_reason")
message = await GetTranslatedText(ctx.guild.id, "warn_msg", REASON=reason)
descr = await GetTranslatedText(ctx.guild.id,
"warn_description",
MEMBER=filterMember(member),
REASON=reason)
embed = Embed(
title=await GetTranslatedText(ctx.guild.id,
"warn_title",
MEMBER=filterMember(member)),
description=descr,
)
embed.set_footer(
text=await GetTranslatedText(ctx.guild.id,
"footer_executed_by",
USERNAME=filterMember(ctx.author)),
icon_url=hammericon,
)
embed.set_thumbnail(url=member.display_avatar)
warn = await AddWarning(member.id, ctx.guild.id, reason)
s = "s" if warn > 1 else ""
embed.add_field(
name=await GetTranslatedText(ctx.guild.id, "automod_count_title"),
value=await GetTranslatedText(
ctx.guild.id,
"automod_count_description",
USERNAME=filterMember(member),
WARN=warn,
S=s,
),
inline=True,
)
await ctx.respond(embed=embed, ephemeral=softwarn)
if not softwarn:
await SendMessageTo(ctx, member, message)
@bot.slash_command(
guild_only=True,
name="softwarn",
description=
"Sets a silent warning for a user, at 3 warns/strikes they get kicked",
)
@discord.default_permissions(administrator=True, )
async def softwarn(ctx, member: discord.Member, reason=None):
await SendMetric("softwarn")
await warn(ctx, member, reason, True)
@bot.slash_command(
guild_only=True,
name="seewarns",
description="Displays the warn history of a user in the guild",
)
@discord.default_permissions(administrator=True, )
async def seewarns(ctx, member: discord.Member):
await SendMetric("seewarns")
allwarns = await getAllWarns(member.id, ctx.guild.id)
if len(allwarns) == 0:
allwarns = [await GetTranslatedText(ctx.guild.id, "warn_no_warns")]
message = "\n".join(allwarns)
c = 0
data = []
# Data preparation using chart's syntax
for warn in await GetWarnings(member.id, ctx.guild.id, fullData=True):
_, _, _, _, timestamp = warn
c = c + 1
data.append({
"t":
str(
datetime.datetime.fromtimestamp(
int(str(timestamp)[:str(timestamp).find(".")]))),
"y":
c,
})
uurl = GenerateChart([{
"fill":
False,