-
Notifications
You must be signed in to change notification settings - Fork 3
/
PokeHelp.js
1345 lines (1244 loc) · 72 KB
/
PokeHelp.js
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
/*
Copyright (c) 2019 Jenner Palacios
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
//
// DISCORD JS
//
const Discord=require("discord.js");
const bot=new Discord.Client({fetchAllMembers: true}); bot.commands=new Discord.Collection();
//
// DEPENDENCIES AND SETTINGS
//
const fs=require("fs"), request=require("request"),
botConfig=require("./config/botConfig.json"), globalSettings=require("./config/globalSettings.json"),
serverPokeSettings=require("./data/serverPokeSettings.json"),
chuckNorris=require("./data/chuckNorris.json"),
pokemon=require("./data/pokemon.json"), pokemonMoves=require("./data/pokemonMoves.json"),
pokemonTypes=require("./data/pokemonTypes.json");
var serverSettings=JSON.parse(fs.readFileSync("./config/serverSettings.json","utf8")), myDB="disabled", sqlite="disabled";
if(serverSettings.myDBserver){
if(serverSettings.myDBserver.enabled==="yes"){
const mySQL=require("mysql");
myDB=mySQL.createConnection(serverSettings.myDBserver);
myDB.connect(error=>{
if(error){
console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"ACCESS"+cc.cyan+" Database "+cc.reset+"(invalid login)\nRAW: "+error.sqlMessage)
}
});
}
else{
sqlite=require("sqlite"); sqlite.open("./database/data.sqlite");
}
}
//
// LOAD ALL COMMANDS
//
const commands=fs.readdirSync("./commands").filter(file=>file.endsWith(".js"));
for(const file of commands){
const command=require("./commands/"+file);bot.commands.set(command.name,command);
}
//
// SHORTEN JSON DATA AND CONSOLE COLORS
//
const advText=globalSettings.advText, foulText=globalSettings.foulText, pokeCity=serverPokeSettings.pokeCity,
pokeBadge=serverPokeSettings.pokeBadge, pokeRegion=serverPokeSettings.pokeRegion, pokeCuttie=serverPokeSettings.pokeCuttie,
cc={"reset":"\x1b[0m","ul":"\x1b[4m","lred":"\x1b[91m","red":"\x1b[31m","lgreen":"\x1b[92m","green":"\x1b[32m","lyellow":"\x1b[93m","yellow":"\x1b[33m",
"lblue":"\x1b[94m","blue":"\x1b[34m","lcyan":"\x1b[96m","cyan":"\x1b[36m","pink":"\x1b[95m","purple":"\x1b[35m","bgwhite":"\x1b[107m","bggray":"\x1b[100m",
"bgred":"\x1b[41m","bggreen":"\x1b[42m","bglgreen":"\x1b[102m","bgyellow":"\x1b[43m","bgblue":"\x1b[44m","bglblue":"\x1b[104m","bgcyan":"\x1b[106m",
"bgpink":"\x1b[105m","bgpurple":"\x1b[45m","hlwhite":"\x1b[7m","hlred":"\x1b[41m\x1b[30m","hlgreen":"\x1b[42m\x1b[30m","hlblue":"\x1b[44m\x1b[37m",
"hlcyan":"\x1b[104m\x1b[30m","hlyellow":"\x1b[43m\x1b[30m","hlpink":"\x1b[105m\x1b[30m","hlpurple":"\x1b[45m\x1b[37m"};
//
// FUNCTION: CLEAN TEXT FOR EVALUATION COMMAND
//
function clean(text){
if(typeof(text)==="string"){
return text.replace(/`/g, "`"+String.fromCharCode(8203)).replace(/@/g, "@"+String.fromCharCode(8203));
}
return text;
}
//
// FUNCTION: TIME STAMP
//
function timeStamp(type){
let CurrTime=new Date();
let mo=CurrTime.getMonth()+1;if(mo<10){mo="0"+mo;}let da=CurrTime.getDate();if(da<10){da="0"+da;}let yr=CurrTime.getFullYear();
let hr=CurrTime.getHours();if(hr<10){hr="0"+hr;}let min=CurrTime.getMinutes();if(min<10){min="0"+min;}let sec=CurrTime.getSeconds();if(sec<10){sec="0"+sec;}
if(!type || type===0){
// YYYY/MM/DD HH:MM:SS |
return cc.blue+yr+"/"+mo+"/"+da+" "+hr+":"+min+":"+sec+cc.reset+" |"
}
if(type===1){
// `MM/DD/YYYY @ HH:MM:SS`
return "`"+mo+"/"+da+"/"+yr+" @ "+hr+":"+min+":"+sec+"`"
}
}
//
// FUNCTION: GET THIS GUILD
//
function getGuild(guildID){
for(let n=0;n<serverSettings.servers.length;n++){
if(guildID===serverSettings.servers[n].id){
return n;
}
}
}
//
// RANDOM FUNCTION
//
function random(type,arg){
if(type==="key"){
let keyGen="";
let possible="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for(var i=0;i<arg;i++) {
keyGen+=possible.charAt(Math.floor(Math.random()*possible.length));
}
return keyGen
}
if(type==="num"){
let numGen="";
let possible="0123456789";
for(var i=0;i<arg;i++) {
numGen+=possible.charAt(Math.floor(Math.random()*possible.length));
}
return numGen
}
if(type==="arr"){
return arg[Math.floor(Math.random()*arg.length)];
}
}
//
// FUNCTION: GET BANNED MEMBER
//
function getBannedMember(guild,channelID,guildName){
setTimeout(function(){
guild.fetchAuditLogs({limit:1,type:22})
.then(auditLog=>{
let masterName="",masterID="",minionName="",minionID="",reason="",embedMSG="";
auditLog.entries.map(u=>{
masterName=u.executor.username,masterID=u.executor.id,minionName=u.target.username,minionID=u.target.id,reason="."+String(u.reason)+"."
});
if(botConfig.consoleLog==="all" || botConfig.consoleLog==="allnochat" || botConfig.consoleLog==="cmdsevents" || botConfig.consoleLog==="events"){
console.log(
timeStamp()+" "+cc.cyan+minionName+cc.reset+"("+cc.lblue+minionID+cc.reset+") was "+cc.green+"banned"+cc.reset+" from: "+cc.yellow+guild.name+cc.reset
+", due to: "+cc.cyan+reason.replace("|CmdBy:", cc.reset+" | CmdBy:"+cc.red).slice(1,-1)+cc.reset
);
}
reason=reason.replace("|CmdBy:", "\n\n**CmdBy**:");if(reason===".."){reason="It was **not** __defined__"}else{reason=reason.slice(1,-1)}
embedMSG={
"embed": {
"color": 0xFF0000,
"title": "⛔ \""+minionName+"\" WAS BANNED",
"thumbnail": {"url": globalSettings.images.banned},
"description": "**UserID**: `"+minionID+"`\n**UserTag**: <@"+minionID+">\n"
+"**Reason**: "+reason+"\n**By**: <@"+masterID+">\n**On**: "+timeStamp(1)
}
};
if(guildName){
embedMSG={
"embed": {
"color": 0xFF0000,
"title": "⛔ \""+minionName+"\" WAS BANNED",
"thumbnail": {"url": globalSettings.images.banned},
"description": "**UserID**: `"+minionID+"`\n**UserTag**: <@"+minionID+">\n"
+"**From Server**: "+guildName+"\n**Reason**: "+reason+"\n**By**: <@"+masterID+">\n**On**: "+timeStamp(1)
}
};
}
bot.channels.get(channelID).send(embedMSG)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not send message to channel ID: "+cc.cyan+channelID+cc.reset+" | "+error.message));
})
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"fetchAuditLogs()"+cc.reset+" | "+error.message));
},2000)
}
//
// FUNCTION: GET NEW MEMBER
//
function getNewMember(member,channelID,agreementRequired){
let assignedChannel="",agreementMethod="";
if(channelID && agreementRequired){
assignedChannel="(<#"+channelID+">)";
agreementMethod="and **accept** them by typing: `!agree` in channel: <#"+channelID+">";
}
else if(channelID){
assignedChannel="(<#"+channelID+">)";
}
let welcomeMSG=`
Welcome to **${member.guild.name}**'s Discord, ${member}.
**FIRST**
Confirm your contact information with **Discord** so you can have read-access to our basic channels.
**THEN:**
Carefully read our **Rules**${assignedChannel}; make sure you have clear understanding of our **rules** ${agreementMethod}
-If you have any question, or need clarification about a rule, contact a **Moderator** or **Staff** member.
**LASTLY:**
Enjoy and have fun catching awesome **Pokemon** while using our services. Meet other trainers, and try to attend our community events.
-<@${botConfig.ownerID}>
`
;
member.send(welcomeMSG)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+error.message+" | Member has disabled DMs or has blocked me"));
}
//
// DATABASE TIMER FOR TEMPORARY ROLES
//
setInterval(function(){
let timeNow=new Date().getTime(),dbTime="",daysLeft="",logginChannel="",sid="",member="";
if(myDB!=="disabled"){
myDB.query(`SELECT * FROM PokeHelp_bot.temporaryRoles;`,(error,results)=>{
if(error){console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" TemporaryRoles timer, could not "+cc.yellow+"DELETE FROM"+cc.cyan+" temporaryRoles"+cc.reset+" table\nRAW: "+error);}
else{
if(results.length<1){
return;
}
else{
let rows=results;
for(let rowNumber="0"; rowNumber<rows.length; rowNumber++){
dbTime=rows[rowNumber].endDate; daysLeft=(dbTime*1)-(timeNow*1);
sid=getGuild(rows[rowNumber].guildID);if(sid===undefined){return}
member=bot.guilds.get(rows[rowNumber].guildID).members.get(rows[rowNumber].userID) || "notFound";
if(serverSettings.servers[sid].id){
if(serverSettings.servers[sid].tempRoles){
if(serverSettings.servers[sid].tempRoles.remindAtDays){
let daysRemaining=Math.ceil(daysLeft/86400000), remindAt=(serverSettings.servers[sid].tempRoles.remindAtDays*1), dayORdays=" day";
if(serverSettings.servers[sid].tempRoles.remindAtDays>1){dayORdays=" days"}
if(daysRemaining===remindAt){
myDB.query(`UPDATE PokeHelp_bot.temporaryRoles SET reminderSent=? WHERE userID="${rows[rowNumber].userID}" AND temporaryRole="${rows[rowNumber].temporaryRole}";`,
["yes"],error=>{
if(error){console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"UPDATE"+cc.cyan+" temporaryRoles"+cc.reset+" table\nRAW: "+error);}
}
);
if(rows[rowNumber].reminderSent===null || rows[rowNumber].reminderSent==="no"){
if(member!=="notFound"){
if(botConfig.consoleLog==="all" || botConfig.consoleLog==="allnochat"){
console.info(timeStamp()+" "+cc.lblue+rows[rowNumber].userName+cc.reset+"'s "
+cc.green+"temporary role"+cc.reset+" is expiring soon, sending notification..."+cc.reset);
}
member.send(
"⚠ <@"+rows[rowNumber].userID+">, you will **lose** your role: **"+rows[rowNumber].temporaryRole+"** "
+"in `"+daysRemaining+dayORdays+"`. Please contact <@"+botConfig.ownerID
+"> if you wish to renew your **temporary role**."
)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+error.message+" | Member has disabled DMs, blocked me, or is no longer in server"));
}
}
}
}
}
}
if(daysLeft<1){
let finalName=rows[rowNumber].userName, finalID=rows[rowNumber].userID;
if(serverSettings.servers[sid].id){
if(serverSettings.servers[sid].serverEvents){
if(serverSettings.servers[sid].serverEvents.roleChannelID){
bot.channels.get(serverSettings.servers[sid].serverEvents.roleChannelID)
.send("⚠ <@"+rows[rowNumber].userID+"> have **lost** their role: **"+rows[rowNumber].temporaryRole+"** - their **temporary** access has __EXPIRED__ 😭")
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" TemporaryRoles timer, could not send message to channel | "+error.message));
logginChannel=serverSettings.servers[sid].serverEvents.roleChannelID;
}
}
}
if(serverSettings.serverEvents){
if(serverSettings.serverEvents.roleChannelID){
if(serverSettings.serverEvents.roleChannelID){
if(logginChannel!==serverSettings.serverEvents.roleChannelID){
bot.channels.get(serverSettings.serverEvents.joinChannelID)
.send("⚠ <@"+rows[rowNumber].userID+"> have **lost** their role: **"+rows[rowNumber].temporaryRole+"** - their **temporary** access has __EXPIRED__ 😭")
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" TemporaryRoles timer, could not send message to channel | "+error.message));
}
}
}
}
if(member==="notFound"){
console.info(
timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+cc.cyan+rows[rowNumber].userName+cc.reset+"("+cc.lblue+rows[rowNumber].userID+cc.reset
+") was not found in server: "+cc.yellow+rows[rowNumber].guildName+cc.reset+" | They will be removed from "+cc.cyan+"TemporaryRoles"+cc.reset+" DataBase"
);
}
else{
finalName=member.user.username; finalID=member.user.id;
let roleToRemove=bot.guilds.get(rows[rowNumber].guildID).roles.find(role=>role.name===rows[rowNumber].temporaryRole) || "notFound";
if(roleToRemove==="notFound"){
console.info(
timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" The "+cc.green+"temporary"+cc.reset+" role: "+cc.cyan+rows[rowNumber].temporaryRole+cc.reset+" was "
+cc.red+"not"+cc.reset+" found in server: "+cc.yellow+rows[rowNumber].guildName+cc.reset+" | But dbEntry will be "+cc.green+"removed"+cc.reset+" from DataBase"
);
}
else{
member.send(
"⚠ <@"+rows[rowNumber].userID+">, you have **lost** your role: **"+rows[rowNumber].temporaryRole+"** - your **temporary**"
+"access has __EXPIRED__ 😭 \nPlease contact <@"+botConfig.ownerID+"> if you wish to renew your **temporary role**."
)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+error.message+" | Member has disabled DMs, blocked me, or is no longer in server"));
if(member.roles.has(roleToRemove.id)){
member.removeRole(roleToRemove)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" TemporaryRoles timer, could not "+cc.yellow+"removeRole()"+cc.reset+" from member | "+error.message));
}
}
console.log(
timeStamp()+" "+cc.cyan+finalName+cc.reset+"("+cc.lblue+finalID+cc.reset+") have lost their "
+cc.green+"temporary"+cc.reset+" role: "+cc.red+rows[rowNumber].temporaryRole+cc.reset+", in server: "+cc.yellow+rows[rowNumber].guildName+cc.reset
);
}
myDB.query(`DELETE FROM PokeHelp_bot.temporaryRoles WHERE userID="${rows[rowNumber].userID}" AND temporaryRole="${rows[rowNumber].temporaryRole}";`,error=>{
if(error){console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" TemporaryRoles timer, could not "+cc.yellow+"DELETE FROM"+cc.cyan+" temporaryRoles"+cc.reset+" table\nRAW: "+error);}
});
}
}
}
}
});
}
else{
sqlite.all(`SELECT * FROM temporaryRoles;`).then(rows=>{
if(rows.length<1){return}
else{
for(let rowNumber="0"; rowNumber<rows.length; rowNumber++){
dbTime=rows[rowNumber].endDate; daysLeft=(dbTime*1)-(timeNow*1);
sid=getGuild(rows[rowNumber].guildID);if(sid===undefined){return}
member=bot.guilds.get(rows[rowNumber].guildID).members.get(rows[rowNumber].userID) || "notFound";
if(serverSettings.servers[sid].id){
if(serverSettings.servers[sid].tempRoles){
if(serverSettings.servers[sid].tempRoles.remindAtDays){
let daysRemaining=Math.ceil(daysLeft/86400000), remindAt=(serverSettings.servers[sid].tempRoles.remindAtDays*1), dayORdays=" day";
if(serverSettings.servers[sid].tempRoles.remindAtDays>1){dayORdays=" days"}
if(daysRemaining===remindAt){
sqlite.run(`UPDATE temporaryRoles SET reminderSent=? WHERE userID="${rows[rowNumber].userID}" AND temporaryRole="${rows[rowNumber].temporaryRole}";`,["yes"])
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"UPDATE"+cc.cyan+" temporaryRoles"+cc.reset+" table | "+error.message));
if(rows[rowNumber].reminderSent===null || rows[rowNumber].reminderSent==="no"){
if(member!=="notFound"){
if(botConfig.consoleLog==="all" || botConfig.consoleLog==="allnochat"){
console.info(timeStamp()+" "+cc.lblue+rows[rowNumber].userName+cc.reset+"'s "
+cc.green+"temporary role"+cc.reset+" is expiring soon, sending notification..."+cc.reset);
}
member.send(
"⚠ <@"+rows[rowNumber].userID+">, you will **lose** your role: **"+rows[rowNumber].temporaryRole+"** "
+"in `"+daysRemaining+dayORdays+"`. Please contact <@"+botConfig.ownerID
+"> if you wish to renew your **temporary role**."
)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+error.message+" | Member has disabled DMs, blocked me, or is no longer in server"));
}
}
}
}
}
}
if(daysLeft<1){
let finalName=rows[rowNumber].userName, finalID=rows[rowNumber].userID;
if(serverSettings.servers[sid].id){
if(serverSettings.servers[sid].serverEvents){
if(serverSettings.servers[sid].serverEvents.roleChannelID){
bot.channels.get(serverSettings.servers[sid].serverEvents.roleChannelID)
.send("⚠ <@"+rows[rowNumber].userID+"> have **lost** their role: **"+rows[rowNumber].temporaryRole+"** - their **temporary** access has __EXPIRED__ 😭")
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" TemporaryRoles timer, could not send message to channel | "+error.message));
logginChannel=serverSettings.servers[sid].serverEvents.roleChannelID;
}
}
}
if(serverSettings.serverEvents){
if(serverSettings.serverEvents.roleChannelID){
if(serverSettings.serverEvents.roleChannelID){
if(logginChannel!==serverSettings.serverEvents.roleChannelID){
bot.channels.get(serverSettings.serverEvents.joinChannelID)
.send("⚠ <@"+rows[rowNumber].userID+"> have **lost** their role: **"+rows[rowNumber].temporaryRole+"** - their **temporary** access has __EXPIRED__ 😭")
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" TemporaryRoles timer, could not send message to channel | "+error.message));
}
}
}
}
if(member==="notFound"){
console.info(
timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+cc.cyan+rows[rowNumber].userName+cc.reset+"("+cc.lblue+rows[rowNumber].userID+cc.reset
+") was not found in server: "+cc.yellow+rows[rowNumber].guildName+cc.reset+" | They will be removed from "+cc.cyan+"TemporaryRoles"+cc.reset+" DataBase"
);
}
else{
finalName=member.user.username; finalID=member.user.id;
let roleToRemove=bot.guilds.get(rows[rowNumber].guildID).roles.find(role=>role.name===rows[rowNumber].temporaryRole) || "notFound";
if(roleToRemove==="notFound"){
console.info(
timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" The "+cc.green+"temporary"+cc.reset+" role: "+cc.cyan+rows[rowNumber].temporaryRole+cc.reset+" was "
+cc.red+"not"+cc.reset+" found in server: "+cc.yellow+rows[rowNumber].guildName+cc.reset+" | But dbEntry will be "+cc.green+"removed"+cc.reset+" from DataBase"
);
}
else{
member.send(
"⚠ <@"+rows[rowNumber].userID+">, you have **lost** your role: **"+rows[rowNumber].temporaryRole+"** - your **temporary**"
+"access has __EXPIRED__ 😭 \nPlease contact <@"+botConfig.ownerID+"> if you wish to renew your **temporary role**."
)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+error.message+" | Member has disabled DMs, blocked me, or is no longer in server"));
if(member.roles.has(roleToRemove.id)){
member.removeRole(roleToRemove)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" TemporaryRoles timer, could not "+cc.yellow+"removeRole()"+cc.reset+" from member | "+error.message));
}
}
console.log(
timeStamp()+" "+cc.cyan+finalName+cc.reset+"("+cc.lblue+finalID+cc.reset+") have lost their "
+cc.green+"temporary"+cc.reset+" role: "+cc.red+rows[rowNumber].temporaryRole+cc.reset+", in server: "+cc.yellow+rows[rowNumber].guildName+cc.reset
);
}
sqlite.run(`DELETE FROM temporaryRoles WHERE userID="${rows[rowNumber].userID}" AND temporaryRole="${rows[rowNumber].temporaryRole}";`)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" TemporaryRoles timer, could not "+cc.yellow+"DELETE FROM"+cc.reset+" database | "+error.message));
}
}
}
})
.catch(error=>{console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" TemporaryRoles timer, could not "+cc.yellow+"SELECT FROM"+cc.cyan+" database | "+error.message)});
}
},3600000);
// 86400000 = 24hrs
// 43200000 = 12hrs
// 21600000 = 6hrs
// 10800000 = 3hrs
// 3600000 = 1hr <-
// 1800000 = 30mins
//
// UNHANDLED REJECTION/PROMISE
//
process.on("unhandledRejection",error=>console.log(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Uncaught Promise Rejection:\n"+error));
//
// BOT SIGNED IN AND IS READY
//
bot.on("ready", ()=>{
botConfig.botVersion="3.8";
console.info(timeStamp()+" -- DISCORD HELPBOT: "+cc.yellow+bot.user.username+cc.reset+", IS "+cc.green+"READY"+cc.reset+"! --");
// VERSION CHECKER
request("https://raw.githubusercontent.com/JennerPalacios/PokeHelp-Bot/master/version.txt",(error,response,body)=>{
if(error){
console.info(timeStamp()+" "+cc.hlred+"ERROR "+cc.reset+" Could not load version from gitHub | "+error);
}
if(body){
let gitHubVer=body.slice(0,-1); let timeLog=timeStamp();
let verChecker=cc.green+"up-to-date"+cc.reset; if(gitHubVer!==botConfig.botVersion){ verChecker=cc.hlred+" OUTDATED! "+cc.reset }
console.info(
timeLog+" GitHub Discord Bot [PokéHelp]: "+cc.yellow+"v"+gitHubVer+cc.reset+"\n"
+timeLog+" Local Discord Bot ["+bot.user.username+"]: "+cc.yellow+"v"+botConfig.botVersion+cc.reset+" -> "+verChecker+"\n"
+timeLog+" Discord API [discord.js]: "+cc.yellow+"v"+Discord.version+cc.reset+"\n"
+timeLog+" Node API [node.js] version: "+cc.yellow+process.version+cc.reset
);
}
});
//
// DATABASE FILE AND TABLE CREATION
//
//CHARACTER SET utf8mb4 COLLATE utf8mb4_bin
if(myDB!=="disabled"){
// CREATE DATABASE
myDB.query(`CREATE DATABASE IF NOT EXISTS PokeHelp_bot CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`,error=>{
if(error){console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"CREATE DATABASE"+cc.cyan+" PokeHelp_bot "+cc.reset+"\nRAW: "+error)}
});
// CREATE TABLE MEMBER AGREEMENT TRACKER
myDB.query(`CREATE TABLE IF NOT EXISTS PokeHelp_bot.agreedMembers (userID TEXT,userName TEXT,serverID TEXT,serverName TEXT,dateAccepted TEXT);`,error=>{
if(error){console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"CREATE TABLE"+cc.cyan+" agreedMembers "+cc.reset+"in database\nRAW: "+error)}
});
// CREATE TABLE CHAT TRACKER
myDB.query(`CREATE TABLE IF NOT EXISTS PokeHelp_bot.chatTracker (userID TEXT,userName TEXT,lastMsgID TEXT,lastMsg TEXT,lastChanID TEXT,lastChanName TEXT,guildID TEXT,guildName TEXT,lastDate TEXT,points INTEGER,level INTEGER);`,error=>{
if(error){console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"CREATE TABLE"+cc.cyan+" chatTracker "+cc.reset+"in database\nRAW: "+error)}
});
// CREATE TABLE COMMAND SPAM CONTROL
myDB.query(`CREATE TABLE IF NOT EXISTS PokeHelp_bot.cmdSpamControl (userID TEXT,userName TEXT,guildID TEXT,guildName TEXT,lastDate TEXT,cmdCount TEXT);`,error=>{
if(error){console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"CREATE TABLE"+cc.cyan+" cmdSpamControl "+cc.reset+"in database\nRAW: "+error)}
});
// CREATE TABLE TEMPORARY ROLES
myDB.query(`CREATE TABLE IF NOT EXISTS PokeHelp_bot.temporaryRoles (userID TEXT,userName TEXT,temporaryRole TEXT,guildID TEXT,guildName TEXT,startDate TEXT,endDate TEXT,addedByID TEXT,addedByName TEXT);`,error=>{
if(error){console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"CREATE TABLE"+cc.cyan+" temporaryRoles "+cc.reset+"in database\nRAW: "+error)}
});
myDB.query(`SELECT reminderSent FROM PokeHelp_bot.temporaryRoles;`,async (error,results)=>{
if(error){
console.info(timeStamp()+" "+cc.hlblue+" WARNING "+cc.reset+" Could not "+cc.yellow+"SELECT reminderSent FROM"+cc.cyan+" temporaryRoles"+cc.reset+" table\nRAW: "+error
+"\n"+timeStamp()+" Column above did not exist. Adding column to table...");
myDB.query(`ALTER TABLE PokeHelp_bot.temporaryRoles ADD COLUMN reminderSent TEXT AFTER addedByName;`,error=>{
if(error){console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"ALTER TABLE"+cc.cyan+" temporaryRoles "+cc.reset+"in database\nRAW: "+error)}
});
}
});
// CREATE TABLE TEMPORARY SELF ROLES
myDB.query(`CREATE TABLE IF NOT EXISTS PokeHelp_bot.temporarySelfTag (userID TEXT,userName TEXT,temporaryTag TEXT,guildID TEXT,guildName TEXT,startDate TEXT,endDate TEXT);`,error=>{
if(error){console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"CREATE TABLE"+cc.cyan+" temporarySelfTag "+cc.reset+"in database\nRAW: "+error)}
});
// CREATE TABLE MESSAGE REACTIONS
myDB.query(`CREATE TABLE IF NOT EXISTS PokeHelp_bot.messageReactions (id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,serverID TEXT,serverName TEXT,channelID TEXT,channelName TEXT,messageID TEXT,emojiAnimated TEXT,emojiName TEXT,emojiID TEXT,roleName TEXT,roleID TEXT,title TEXT,display TEXT);`,error=>{
if(error){console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"CREATE TABLE"+cc.cyan+" messageReactions "+cc.reset+"in database\nRAW: "+error)}
});
}
else{
// MEMBER AGREEMENT TRACKER
sqlite.run(`CREATE TABLE IF NOT EXISTS agreedMembers (userID TEXT, userName TEXT, serverID TEXT, serverName TEXT, dateAccepted TEXT);`)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"CREATE TABLE"+cc.cyan+" agreedMembers "+cc.reset+"in database | "+error.message+"\n"+error));
// CHAT TRACKER
sqlite.run(`CREATE TABLE IF NOT EXISTS chatTracker (userID TEXT, userName TEXT, lastMsgID, lastMsg TEXT, lastChanID TEXT, lastChanName TEXT, guildID TEXT, guildName TEXT, lastDate TEXT, points INTEGER, level INTEGER);`)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"CREATE TABLE"+cc.cyan+" chatTracker "+cc.reset+"in database | "+error.message));
// COMMAND SPAM CONTROL
sqlite.run(`CREATE TABLE IF NOT EXISTS cmdSpamControl (userID TEXT, userName TEXT, guildID TEXT, guildName TEXT, lastDate TEXT, cmdCount TEXT);`)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"CREATE TABLE"+cc.cyan+" cmdSpamControl "+cc.reset+"in database | "+error.message));
// TEMPORARY ROLES
sqlite.run(`CREATE TABLE IF NOT EXISTS temporaryRoles (userID TEXT, userName TEXT, temporaryRole TEXT, guildID TEXT, guildName TEXT, startDate TEXT, endDate TEXT, addedByID TEXT, addedByName TEXT);`)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"CREATE TABLE"+cc.cyan+" temporaryRoles "+cc.reset+"in database | "+error.message));
sqlite.all(`SELECT reminderSent FROM temporaryRoles`)
.catch(err=>{
sqlite.run(`ALTER TABLE temporaryRoles ADD COLUMN reminderSent TEXT AFTER addedByName;`)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"ALTER"+cc.cyan+" temporaryRoles"+cc.reset+" table | "+error.message));
console.info(timeStamp()+" "+cc.hlblue+" NOTICE "+cc.reset+" Could not "+cc.yellow+"SELECT reminderSent FROM"+cc.cyan+" temporaryRoles"+cc.reset+" table\nRAW: "+err.message
+"\n"+timeStamp()+" Column above did not exist. Adding column to table...")
});
// TEMPORARY SELF ROLES
sqlite.run(`CREATE TABLE IF NOT EXISTS temporarySelfTag (userID TEXT, userName TEXT, temporaryTag TEXT, guildID TEXT, guildName TEXT, startDate TEXT, endDate TEXT);`)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"CREATE TABLE"+cc.cyan+" temporarySelfTag "+cc.reset+"in database | "+error.message));
// MESSAGE REACTIONS
sqlite.run(`CREATE TABLE IF NOT EXISTS messageReactions (id INTEGER PRIMARY KEY, serverID TEXT, serverName TEXT, channelID TEXT, channelName TEXT, messageID TEXT, emojiAnimated TEXT, emojiName TEXT, emojiID TEXT, roleName TEXT, roleID TEXT, title TEXT, display TEXT);`)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"CREATE TABLE"+cc.cyan+" messageReactions "+cc.reset+"in database | "+error.message));
}
});
//
// JOIN EVENT
//
bot.on("guildMemberAdd", member=>{
let joinedServer="", guild=member.guild, user=member.user, sid=getGuild(member.guild.id);if(sid===undefined){return}
if(botConfig.consoleLog==="all" || botConfig.consoleLog==="allnochat" || botConfig.consoleLog==="cmdsevents" || botConfig.consoleLog==="events"){
console.log(timeStamp()+" "+cc.cyan+user.username+cc.reset+"("+cc.lblue+user.id+cc.reset+") has joined server: "+cc.yellow+guild.name+cc.reset);
}
let welcomeList=[
member+" came to get their last badge, the **"+random("arr",pokeBadge)+" Badge**!",
"Everyone quick! A **shiny** "+member+" has just **spawned**!",
member+" is looking for their **"+random("arr",pokeCuttie)+"**, anyone seen it?",
"Prepare for trouble, "+member+", and make it double...",
member+" wants to be their very **best** ♪, like no one ever was! ♫ ♪",
"Trainer "+member+" needs a **"+random("arr",pokeCuttie)+"** to complete their **PokeDex**!",
member+", from the **"+random("arr",pokeRegion)+" Region**, is looking for a friendly match!",
"Anyone with a **"+random("arr",pokeBadge)+" Badge**? "+member+" needs help getting one!",
member+" needs help finding the **"+random("arr",pokeCity)+" City Gym**, help them out plz!",
"A wild "+member+" **CP**:`489` (__82%__ 12/10/15) has just **spawned**!",
"One sec guys! "+member+" needs to heal their Pokémon...",
member+" has an `OP` **"+random("arr",pokeCuttie)+"**! Niantic, nerf it pl0x!",
"Gratz "+member+"! You just caught your first **"+random("arr",pokeCuttie)+"**!",
member+" has come to show off their **"+random("arr",pokeCuttie)+"** - what a noOb!"
];
let joinMSG=random("arr",welcomeList), logginChannel="";
if(serverSettings.servers[sid].id){
if(serverSettings.servers[sid].newMember){
if(serverSettings.servers[sid].newMember.welcomeDM==="yes"){
if(serverSettings.servers[sid].newMember.rulesChannelID && serverSettings.servers[sid].newMember.roleAgreementRequired==="yes"){
getNewMember(member,serverSettings.servers[sid].newMember.rulesChannelID,"yes");
}
else if(serverSettings.servers[sid].newMember.rulesChannelID){
getNewMember(member,serverSettings.servers[sid].newMember.rulesChannelID);
}
else{
getNewMember(member);
}
}
if(serverSettings.servers[sid].newMember.roleOnJoinEnabled==="yes"){
if(serverSettings.servers[sid].newMember.roleOnJoinName){
let starterRole=guild.roles.find(role=>role.name===serverSettings.servers[sid].newMember.roleOnJoinName) || "notFound";
if(starterRole==="notFound"){
console.info(
timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Role: "+cc.cyan+serverSettings.servers[sid].newMember.roleOnJoinName+cc.reset
+" was "+cc.red+"not"+cc.reset+" found in server: "+cc.yellow+member.guild.name+cc.reset+", as it was input in "
+cc.purple+"serverSettings.json"+cc.reset+" > "+cc.purple+"newMember"+cc.reset+" > "+cc.purple+"roleOnJoinName"+cc.reset
);
}
else{
member.addRole(starterRole)
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"addRole()"+cc.reset+" to new member | "+error.message));
}
}
}
}
if(serverSettings.servers[sid].serverEvents){
if(serverSettings.servers[sid].serverEvents.joinChannelID){
if(serverSettings.servers[sid].serverEvents.joinEvents==="yes"){
if(serverSettings.servers[sid].serverEvents.joinPokeRandom==="yes"){
bot.channels.get(serverSettings.servers[sid].serverEvents.joinChannelID).send(timeStamp(1)+" "+joinMSG)
.catch(
error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not send message to channelID "
+cc.cyan+serverSettings.servers[sid].serverEvents.joinChannelID+cc.reset+" | "+error.message)
);
}
else{
bot.channels.get(serverSettings.servers[sid].serverEvents.joinChannelID).send(timeStamp(1)+" "+member.user.username+" has joined server!")
.catch(
error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not send message to channelID "
+cc.cyan+serverSettings.servers[sid].serverEvents.joinChannelID+cc.reset+" | "+error.message)
);
}
logginChannel=serverSettings.servers[sid].serverEvents.joinChannelID;
}
}
}
}
if(serverSettings.serverEvents){
if(serverSettings.serverEvents.joinChannelID){
if(logginChannel!=="" && logginChannel===serverSettings.serverEvents.joinChannelID){return}
if(serverSettings.serverEvents.joinEvents==="yes"){
if(serverSettings.serverEvents.joinPokeRandom==="yes"){
bot.channels.get(serverSettings.serverEvents.joinChannelID).send(timeStamp(1)+" "+joinMSG)
.catch(
error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not send message to channelID "
+cc.cyan+serverSettings.serverEvents.joinChannelID+cc.reset+" | "+error.message)
);
}
else{
bot.channels.get(serverSettings.serverEvents.joinChannelID).send(timeStamp(1)+" "+member+" has joined server!")
.catch(
error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not send message to channelID "
+cc.cyan+serverSettings.serverEvents.joinChannelID+cc.reset+" | "+error.message)
);
}
}
}
}
});
// END OF: JOIN EVENT
//
// BAN EVENT
//
bot.on("guildBanAdd",async (guild,user)=>{
let sid=await getGuild(guild.id);if(sid===undefined){return} let logginChannel="";
if(serverSettings.servers[sid].id){
if(serverSettings.servers[sid].moderationEvents){
if(serverSettings.servers[sid].moderationEvents.channelID){
if(serverSettings.servers[sid].moderationEvents.banEvents==="yes"){
getBannedMember(guild,serverSettings.servers[sid].moderationEvents.channelID);
logginChannel=serverSettings.servers[sid].moderationEvents.channelID;
}
}
}
}
if(serverSettings.moderationEvents){
if(serverSettings.moderationEvents.channelID){
if(logginChannel!=="" && logginChannel===serverSettings.moderationEvents.channelID){return}
if(serverSettings.moderationEvents.banEvents==="yes"){
getBannedMember(guild,serverSettings.moderationEvents.channelID,guild.name);
}
}
}
});
// END OF: BAN EVENT
//////////////////////////////////////////////////////////////////////////////////////////////////
// //
// MESSAGE LISTENER //
// //
//////////////////////////////////////////////////////////////////////////////////////////////////
bot.on("messageUpdate",async (oldMessage,newMessage)=>{
if(newMessage.channel.guild===undefined){return}
let member=newMessage.member, sid=await getGuild(newMessage.channel.guild.id);if(sid===undefined){return}
// GRAB ADMINS AND MODERATORS
let adminRole=newMessage.channel.guild.roles.find(role=>role.name===serverSettings.servers[sid].adminRoleName);
if(!adminRole){
adminRole={"id":"10101"};console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" I could not find "
+cc.red+"adminRoleName"+cc.reset+": "+cc.cyan+serverSettings.servers[sid].adminRoleName+cc.reset+" for server: "
+cc.lblue+newMessage.channel.guild.name+cc.reset+" in "+cc.purple+"serverSettings.json"+cc.reset)}
let modRole=newMessage.channel.guild.roles.find(role=>role.name===serverSettings.servers[sid].modRoleName);
if(!modRole){
modRole={"id":"10101"};console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" I could not find "
+cc.red+"modRoleName"+cc.reset+": "+cc.cyan+serverSettings.servers[sid].modRoleName+cc.reset+" for server: "
+cc.lblue+newMessage.channel.guild.name+cc.reset+" in "+cc.purple+"serverSettings.json"+cc.reset)}
// FOUL LANGUAGE FILTER
if(foulText.some(word=>newMessage.content.includes(word))){
let skip="no";if(member.roles.has(modRole.id) || member.roles.has(adminRole.id) || member.id===botConfig.ownerID){skip="yes"}
if(serverSettings.servers[sid].id){if(serverSettings.servers[sid].chatFilter){if(serverSettings.servers[sid].chatFilter.allowFoulLanguage==="yes"){skip="yes"}}}
if(skip==="no"){
newMessage.delete();
embedMSG={
"embed": {
"color": 0xFF0000,
"title": "⚠ WARNING: Watch Your Language ⚠",
"thumbnail": {"url": globalSettings.images.warning},
"description": "You are being **WARNED** about a **inappropriate** word... "
+"Please watch your language; kids play this game too, you know\n**OffenseDate**: "+timeStamp(1)
}
};
console.log(
timeStamp()+" "+cc.hlyellow+" WARNING "+cc.reset+" FOUL LANGUAGE: "+cc.cyan+member.user.username+cc.reset+"("+cc.lblue+member.id+cc.reset+") said: "+newMessage.content
);
member.send(embedMSG).then(()=>{
member.send("Please **Read/Review Our Rules** in order to avoid a `Mute`/`Kick`/`Ban`")
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+error.message+" | Member has disabled DMs or has blocked me"));
})
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+error.message+" | Member has disabled DMs or has blocked me"));
}
}
// ADVERTISEMENT FILTER
if(advText.some(word=>newMessage.content.toLowerCase().includes(word))){
let skip="no";if(member.roles.has(modRole.id) || member.roles.has(adminRole.id) || member.id===botConfig.ownerID){skip="yes"}
if(serverSettings.servers[sid].id){if(serverSettings.servers[sid].chatFilter){if(serverSettings.servers[sid].chatFilter.allowLinks==="yes"){skip="yes"}}}
if(skip==="no"){
newMessage.delete();
embedMSG={
"embed": {
"color": 0xFF0000,
"title": "⚠ WARNING: No Advertising ⚠",
"thumbnail": {"url": globalSettings.images.warning},
"description": "You are being **WARNED** about a link... "
+"Advertising is **NOT** allowed in our server.\n**OffenseDate**: "+timeStamp(1)
}
};
console.log(
timeStamp()+" "+cc.hlyellow+" WARNING "+cc.reset+" ADVERTISEMENT: "+cc.cyan+member.user.username+cc.reset+"("+cc.lblue+member.id+cc.reset+") said: "+newMessage.content
);
member.send(embedMSG).then(()=>{
member.send("Please **Read/Review Our Rules** in order to avoid a `Mute`/`Kick`/`Ban`")
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+error.message+" | Member has disabled DMs or has blocked me"));
})
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+error.message+" | Member has disabled DMs or has blocked me"));
}
}
// INVITE LINK FILTER
let invLinks=newMessage.content.toLowerCase().match(/discord.gg/g);
if(invLinks){
let skip="no";if(member.roles.has(modRole.id) || member.roles.has(adminRole.id) || member.id===botConfig.ownerID){skip="yes"}
if(serverSettings.servers[sid].id){if(serverSettings.servers[sid].chatFilter){if(serverSettings.servers[sid].chatFilter.allowInvites==="yes"){skip="yes"}}}
if(skip==="no"){
newMessage.delete();
embedMSG={
"embed": {
"color": 0xFF0000,
"title": "⚠ WARNING: No Invites ⚠",
"thumbnail": {"url": globalSettings.images.warning},
"description": "You are being **WARNED** about an __invite__ code or link... "
+"Advertising of other servers is **NOT** allowed in our server.\n**OffenseDate**: "+timeStamp(1)
}
};
console.log(timeStamp()+" "+cc.hlyellow+" WARNING "+cc.reset+" INVITE: "+cc.cyan+member.user.username+cc.reset+"("+cc.lblue+member.id+cc.reset+") said: "+newMessage.content);
member.send(embedMSG).then(()=>{
member.send("Please **Read/Review Our Rules** in order to avoid a `Mute`/`Kick`/`Ban`")
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+error.message+" | Member has disabled DMs or has blocked me"))
}).catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+error.message+" | Member has disabled DMs or has blocked me"))
}
}
});
bot.on("message",message=>{
if(!message.member){return}if(!message.member.user){return}if(!message.member.user.username){return}
if(message.member.user.bot || message.channel.type==="dm"){return}if(!message.content){return}
// DEFINE SHORTER DISCORD PROPERTIES
let guild=message.guild, channel=message.channel, member=message.member, sid=getGuild(message.guild.id);if(sid===undefined){return}
// GRAB COMMAND
let command=message.content.toLowerCase().split(/ +/)[0]; command=command.slice(botConfig.cmdPrefix.length);
// GRAB ARGUMENTS
let args=message.content.toLowerCase().split(/ +/).slice(1),ARGS=message.content.split(/ +/).slice(1);
// GRAB ADMINS AND MODERATORS
let adminRole=guild.roles.find(role=>role.name===serverSettings.servers[sid].adminRoleName);
if(!adminRole){
adminRole={"id":"10101"};console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" I could not find "
+cc.red+"adminRoleName"+cc.reset+": "+cc.cyan+serverSettings.servers[sid].adminRoleName+cc.reset+" for server: "
+cc.lblue+guild.name+cc.reset+" in "+cc.purple+"serverSettings.json"+cc.reset)}
let modRole=guild.roles.find(role=>role.name===serverSettings.servers[sid].modRoleName);
if(!modRole){
modRole={"id":"10101"};console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" I could not find "
+cc.red+"modRoleName"+cc.reset+": "+cc.cyan+serverSettings.servers[sid].modRoleName+cc.reset+" for server: "
+cc.lblue+guild.name+cc.reset+" in "+cc.purple+"serverSettings.json"+cc.reset)}
//
//
// CHAT LISTENER
//
// CHAT ACTIVITY UPDATER
//MAX PTS | MAX LVL | XP MULTIPLIER
//----------+---------+--------------
//99,999pts = lvl 999 = 3.15914 xp
//99,999pts = lvl 100 = 0.31623 xp
//99,999pts = lvl 40 = 0.1265 xp
//99,999pts = lvl 31 = 0.1 xp « old system
let curTime=new Date().getTime(), points2add=1;
if(args.length>5){
if(args.length>9){points2add=2.5}if(args.length>14){points2add=3.5}
if(args.length>19){points2add=5.5}if(args.length>24){points2add=6.5}
if(args.length>29){points2add=8.5}if(args.length>34){points2add=9.5}
if(args.length>39){points2add=11.5}if(args.length>44){points2add=12.5}
if(args.length>49){points2add=14.5}if(args.length>54){points2add=15.5}
if(args.length>59){points2add=17.5}if(args.length>64){points2add=18.5}
}
if(myDB!=="disabled"){
myDB.query(`SELECT * FROM PokeHelp_bot.chatTracker WHERE userID="${member.id}" AND guildID="${guild.id}";`,(error,results)=>{
if(error){console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"SELECT * FROM"+cc.cyan+" chatTracker"+cc.reset+" table\nRAW: "+error);}
else{
if(results.length<1){
myDB.query(`INSERT INTO PokeHelp_bot.chatTracker (userID, userName, lastMsgID, lastMsg, lastChanID, lastChanName, guildID, guildName, lastDate, points, level) VALUES (?,?,?,?,?,?,?,?,?,?,?);`,
[member.id, member.user.username, message.id, message.content, channel.id, channel.name, guild.id, guild.name, curTime, 1, 0],error=>{
if(error){console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"INSERT INTO"+cc.cyan+" chatTracker"+cc.reset+" table\nRAW: "+error);}
}
);
}
else{
let row=results[0];let curLevel=Math.floor(0.31623 * Math.sqrt(row.points)), newPoints=row.points+points2add;
if(curLevel>row.level){
row.level=curLevel;
myDB.query(`UPDATE PokeHelp_bot.chatTracker SET lastMsgID=?, lastMsg=?, lastChanID=?, lastChanName=?, lastDate=?, points=?, level=? WHERE userID="${member.id}" AND guildID="${guild.id}";`,
[message.id, message.content, channel.id, channel.name, curTime, newPoints, row.level],error=>{
if(error){console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"UPDATE"+cc.cyan+" chatTracker"+cc.reset+" table\nRAW: "+error);}
}
);
if(serverSettings.servers[sid].id){
if(serverSettings.servers[sid].chatActivity){
if(serverSettings.servers[sid].chatActivity.broadCastNewLevel==="yes"){
channel.send("🎉 Gratz "+member+"! You've leveled up! Your new level is: **"+curLevel+"**! Keep the chat going 👍")
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not send message to channel | "+error.message))
}
}
}
if(serverSettings.chatActivity){
if(serverSettings.chatActivity.broadCastNewLevel==="yes"){
channel.send("🎉 Gratz "+member+"! You've leveled up! Your new level is: **"+curLevel+"**! Keep the chat going 👍")
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not send message to channel | "+error.message))
}
}
}
else{
myDB.query(`UPDATE PokeHelp_bot.chatTracker SET lastMsgID=?, lastMsg=?, lastChanID=?, lastChanName=?, lastDate=?, points=? WHERE userID="${member.id}" AND guildID="${guild.id}";`,
[message.id, message.content, channel.id, channel.name, curTime, newPoints],error=>{
if(error){console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"UPDATE"+cc.cyan+" chatTracker"+cc.reset+" table\nRAW: "+error);}
}
);
}
}
}
});
}
else{
sqlite.get(`SELECT * FROM chatTracker WHERE userID="${member.id}" AND guildID="${guild.id}";`)
.then(row=>{
if(!row){
sqlite.run(`INSERT INTO chatTracker (userID, userName, lastMsgID, lastMsg, lastChanID, lastChanName, guildID, guildName, lastDate, points, level) VALUES (?,?,?,?,?,?,?,?,?,?,?);`,
[member.id, member.user.username, message.id, message.content, channel.id, channel.name, guild.id, guild.name, curTime, 1, 0])
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"INSERT INTO"+cc.reset+cc.cyan+" chatTracker"+cc.reset+" table | "+error.message));
}
else{
let curLevel=Math.floor(0.31623 * Math.sqrt(row.points)), newPoints=row.points+points2add;
if(curLevel>row.level){
row.level=curLevel;
sqlite.run(`UPDATE chatTracker SET lastMsgID=?, lastMsg=?, lastChanID=?, lastChanName=?, lastDate=?, points=?, level=? WHERE userID="${member.id}" AND guildID="${guild.id}";`,
[message.id, message.content, channel.id, channel.name, curTime, newPoints, row.level])
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"UPDATE"+cc.cyan+" chatTracker"+cc.reset+" table | "+error.message))
if(serverSettings.servers[sid].id){
if(serverSettings.servers[sid].chatActivity){
if(serverSettings.servers[sid].chatActivity.broadCastNewLevel==="yes"){
channel.send("🎉 Gratz "+member+"! You've leveled up! Your new level is: **"+curLevel+"**! Keep the chat going 👍")
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" #1 Could not send message to channel | "+error.message));
}
}
}
if(serverSettings.chatActivity){
if(serverSettings.chatActivity.broadCastNewLevel==="yes"){
channel.send("🎉 Gratz "+member+"! You've leveled up! Your new level is: **"+curLevel+"**! Keep the chat going 👍")
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not send message to channel | "+error.message));
}
}
}
else{
sqlite.run(`UPDATE chatTracker SET lastMsgID=?, lastMsg=?, lastChanID=?, lastChanName=?, lastDate=?, points=? WHERE userID="${member.id}" AND guildID="${guild.id}";`,
[message.id, message.content, channel.id, channel.name, curTime, newPoints])
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"UPDATE"+cc.cyan+" chatTracker"+cc.reset+" table | "+error.message));
}
}
})
.catch(error=>{
console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" Could not "+cc.yellow+"SELECT"+cc.reset+" items from "+cc.cyan+"chatTracker"+cc.reset+" table | "+error.message);
});
}
// FOUL LANGUAGE FILTER
if(foulText.some(word=>message.content.includes(word))){
let skip="no";if(member.roles.has(modRole.id) || member.roles.has(adminRole.id) || member.id===botConfig.ownerID){skip="yes"}
if(serverSettings.servers[sid].id){if(serverSettings.servers[sid].chatFilter){if(serverSettings.servers[sid].chatFilter.allowFoulLanguage==="yes"){skip="yes"}}}
if(skip==="no"){
message.delete();
embedMSG={
"embed": {
"color": 0xFF0000,
"title": "⚠ WARNING: Watch Your Language ⚠",
"thumbnail": {"url": globalSettings.images.warning},
"description": "You are being **WARNED** about a **inappropriate** word... "
+"Please watch your language; kids play this game too, you know\n**OffenseDate**: "+timeStamp(1)
}
};
console.log(
timeStamp()+" "+cc.hlyellow+" WARNING "+cc.reset+" FOUL LANGUAGE: "+cc.cyan+member.user.username+cc.reset+"("+cc.lblue+member.id+cc.reset+") said: "+message.content
);
member.send(embedMSG).then(()=>{
member.send("Please **Read/Review Our Rules** in order to avoid a `Mute`/`Kick`/`Ban`")
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+error.message+" | Member has disabled DMs or has blocked me"));
})
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+error.message+" | Member has disabled DMs or has blocked me"));
}
}
// ADVERTISEMENT FILTER
if(advText.some(word=>message.content.toLowerCase().includes(word))){
let skip="no";if(member.roles.has(modRole.id) || member.roles.has(adminRole.id) || member.id===botConfig.ownerID){skip="yes"}
if(serverSettings.servers[sid].id){if(serverSettings.servers[sid].chatFilter){if(serverSettings.servers[sid].chatFilter.allowLinks==="yes"){skip="yes"}}}
if(skip==="no"){
message.delete();
embedMSG={
"embed": {
"color": 0xFF0000,
"title": "⚠ WARNING: No Advertising ⚠",
"thumbnail": {"url": globalSettings.images.warning},
"description": "You are being **WARNED** about a link... "
+"Advertising is **NOT** allowed in our server.\n**OffenseDate**: "+timeStamp(1)
}
};
console.log(
timeStamp()+" "+cc.hlyellow+" WARNING "+cc.reset+" ADVERTISEMENT: "+cc.cyan+member.user.username+cc.reset+"("+cc.lblue+member.id+cc.reset+") said: "+message.content
);
member.send(embedMSG).then(()=>{
member.send("Please **Read/Review Our Rules** in order to avoid a `Mute`/`Kick`/`Ban`")
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+error.message+" | Member has disabled DMs or has blocked me"));
})
.catch(error=>console.info(timeStamp()+" "+cc.hlred+" ERROR "+cc.reset+" "+error.message+" | Member has disabled DMs or has blocked me"));
}
}
// INVITE LINK FILTER
let invLinks=message.content.toLowerCase().match(/discord.gg/g);
if(invLinks){
let skip="no";if(member.roles.has(modRole.id) || member.roles.has(adminRole.id) || member.id===botConfig.ownerID){skip="yes"}
if(serverSettings.servers[sid].id){if(serverSettings.servers[sid].chatFilter){if(serverSettings.servers[sid].chatFilter.allowInvites==="yes"){skip="yes"}}}
if(skip==="no"){
message.delete();
embedMSG={
"embed": {
"color": 0xFF0000,
"title": "⚠ WARNING: No Invites ⚠",
"thumbnail": {"url": globalSettings.images.warning},
"description": "You are being **WARNED** about an __invite__ code or link... "
+"Advertising of other servers is **NOT** allowed in our server.\n**OffenseDate**: "+timeStamp(1)
}
};
console.log(timeStamp()+" "+cc.hlyellow+" WARNING "+cc.reset+" "+cc.cyan+member.user.username+cc.reset+"("+cc.lblue+member.id+cc.reset+") said: "+message.content);
member.send(embedMSG).then(()=>{
member.send("Please **Read/Review Our Rules** in order to avoid a `Mute`/`Kick`/`Ban`")