forked from Vaeb/VaeBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
1506 lines (1250 loc) · 60.3 KB
/
index.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
console.log('\n-STARTING-\n');
// //////////////////////////////////////////////////////////////////////////////////////////////
const Auth = require('./Auth.js');
exports.FileSys = require('fs');
exports.DateFormat = require('dateformat');
exports.Request = require('request');
exports.Urban = require('urban');
const TrelloObj = require('node-trello');
exports.Ytdl = require('ytdl-core');
exports.Path = require('path');
exports.NodeOpus = require('node-opus');
exports.Exec = require('child_process').exec;
const YtInfoObj = require('youtube-node');
exports.Translate = require('google-translate-api');
exports.MySQL = require('mysql');
exports.NodeUtil = require('util');
// exports.YoutubeSearch = require('youtube-search');
exports.YtInfo = new YtInfoObj();
exports.TrelloHandler = new TrelloObj(Auth.trelloKey, Auth.trelloToken);
exports.linkGuilds = [
['417110408088780801', '309785618932563968'],
];
exports.dbPass = Auth.dbPass;
exports.dbPassVeil = Auth.dbPassVeil;
// //////////////////////////////////////////////////////////////////////////////////////////////
global.index = module.exports;
global.has = Object.prototype.hasOwnProperty;
global.selfId = '224529399003742210';
global.vaebId = '107593015014486016';
global.botDir = '/home/flipflop8421/files/discordExp/VaeBot'; // '/home/flipflop8421/files/discordExp/VaeBot' 'C:\\Users\\Adam\\Documents\\GitVaeb\\VaeBot'
global.Util = require('./Util.js');
global.Data = require('./core/ManageData.js');
global.Trello = require('./core/ManageTrello.js');
global.Admin = require('./core/ManageAdmin.js');
global.Music = require('./core/ManageMusic.js');
global.Music2 = require('./core/ManageMusic2.js');
global.Cmds = require('./core/ManageCommands.js');
global.Events = require('./core/ManageEvents.js');
global.Discord = require('discord.js');
/* Discord.BaseGuildMember = Discord.GuildMember;
Discord.NewGuildMember = class extends Discord.BaseGuildMember {
constructor(guild, data) {
super(guild, data);
Util.mergeUser(this);
}
}; */
/* class ExtendableProxy {
constructor(guild, data) {
const OriginalGuildMember = new Discord.BaseGuildMember(guild, data);
return new Proxy(this, {
get: (object, key) => {
return OriginalGuildMember[key];
},
set: (object, key, value) => {
OriginalGuildMember[key] = value;
return value;
},
});
}
}
Discord.GuildMember = class extends ExtendableProxy {}; */
/* Discord.GuildMember.prototype.getProp = function (p) {
if (this[p] != null) return this[p];
return this.user[p];
};
Discord.User.prototype.getProp = function (p) {
return this[p];
}; */
exports.YtInfo.setKey(Auth.youtube);
global.client = new Discord.Client({
disabledEvents: ['TYPING_START'],
fetchAllMembers: true,
disableEveryone: true,
});
// //////////////////////////////////////////////////////////////////////////////////////////////
exports.dailyMutes = [];
exports.dailyKicks = [];
exports.dailyBans = [];
exports.commandTypes = {
locked: 'vaeb',
staff: 'staff',
public: 'null',
};
const briefHour = 2;
const msToHours = 1 / (1000 * 60 * 60);
const dayMS = 24 / msToHours;
let madeBriefing = false;
global.colAction = 0xF44336; // Log of action, e.g. action from within command
global.colUser = 0x4CAF50; // Log of member change
global.colMessage = 0xFFEB3B; // Log of message change
global.colCommand = 0x2196F3; // Log of command being executed
global.colGreen = 0x00E676;
global.colBlue = 0x00BCD4;
exports.blockedUsers = {};
exports.blockedWords = [];
exports.runFuncs = [];
exports.warnedImage = {};
// //////////////////////////////////////////////////////////////////////////////////////////////
function setBriefing() {
setTimeout(() => {
const time1 = new Date();
const time2 = new Date();
time2.setHours(briefHour);
time2.setMinutes(0);
time2.setSeconds(0);
time2.setMilliseconds(0);
const t1 = +time1;
const t2 = +time2;
let t3 = t2 - t1;
if (t3 < 0) t3 += dayMS;
const channel = client.channels.get('168744024931434498');
// const guild = channel.guild;
Util.log(`Set daily briefing for ${t3 * msToHours} hours`);
setTimeout(() => {
// const upField = { name: '', value: '', inline: false };
const muteField = { name: 'Mutes', value: 'No mutes today', inline: false };
// var rightField = {name: "", value: ""}
const kickField = { name: 'Kicks', value: 'No kicks today', inline: false };
const banField = { name: 'Bans', value: 'No bans today', inline: false };
const embFields = [muteField, kickField, banField];
const embObj = {
title: 'Daily Briefing',
description: '',
fields: embFields,
footer: { text: '>> More info in #vaebot-log <<' },
thumbnail: { url: './resources/avatar.png' },
color: colGreen,
};
if (exports.dailyMutes.length > 0) {
const dataValues = [];
for (let i = 0; i < exports.dailyMutes.length; i++) {
const nowData = exports.dailyMutes[i];
const userId = nowData[0];
// const userName = nowData[1];
const userReason = nowData[2];
// const userTime = nowData[3];
const targMention = `<@${userId}>`;
let reasonStr = '';
if (userReason != null && userReason.trim().length > 0) {
reasonStr = ` : ${userReason}`;
}
dataValues.push(targMention + reasonStr);
}
muteField.value = dataValues.join('\n\n');
}
muteField.value = `\n${muteField.value}\n`;
if (exports.dailyKicks.length > 0) {
const dataValues = [];
for (let i = 0; i < exports.dailyKicks.length; i++) {
const nowData = exports.dailyKicks[i];
const userId = nowData[0];
// const userName = nowData[1];
const userReason = nowData[2];
const targMention = `<@${userId}>`;
let reasonStr = '';
if (userReason != null && userReason.trim().length > 0) {
reasonStr = ` : ${userReason}`;
}
dataValues.push(targMention + reasonStr);
}
kickField.value = dataValues.join('\n\n');
}
kickField.value = `\n${kickField.value}\n`;
if (exports.dailyBans.length > 0) {
const dataValues = [];
for (let i = 0; i < exports.dailyBans.length; i++) {
const nowData = exports.dailyBans[i];
const userId = nowData[0];
// const userName = nowData[1];
const userReason = nowData[2];
const targMention = `<@${userId}>`;
let reasonStr = '';
if (userReason != null && userReason.trim().length > 0) {
reasonStr = ` : ${userReason}`;
}
dataValues.push(targMention + reasonStr);
}
banField.value = dataValues.join('\n\n');
}
banField.value = `\n${banField.value}\n`;
if (exports.dailyMutes.length > 0
|| exports.dailyKicks.length > 0
|| exports.dailyBans.length > 0) {
channel.send(undefined, { embed: embObj })
.catch(error => Util.log(`[E_SendBriefing] ${error}`));
}
exports.dailyMutes = []; // Reset
exports.dailyKicks = [];
exports.dailyBans = [];
setBriefing();
}, t3);
}, 2000); // Let's wait 2 seconds before starting countdown, just in case of floating point errors triggering multiple countdowns
}
exports.globalBan = {
'201740276472086528': true, // No idea
'75736018761818112': true, // No idea
'123146298504380416': true, // No idea
'263372398059847681': true, // No idea
'238981466606927873': true, // Lindah
'189687397951209472': true, // xCraySECx / Nico Nico
'154255141317378050': true, // HighDefinition
'157749388964265985': true, // Zetroxer
'280419231181307906': true, // Solarical
'169261309353918464': true, // Slappy826
'331958080164200453': true, // derickbuum
'284410389469593611': true, // Papi
'255779902387650560': true, // Shiro's Twin
'80385350316339200': true, // Fennec
'175013861701713920': true, // chrome
};
function securityFunc(guild, member, sendRoleParam) {
const guildName = guild.name;
// const guildId = guild.id;
const memberId = member.id;
const memberName = Util.getFullName(member);
let sendRole = sendRoleParam;
if (sendRole == null) sendRole = Util.getRole('SendMessages', guild);
if (has.call(exports.globalBan, memberId)) {
member.kick()
.catch(console.error);
Util.logc('BanOld1', `Globally banned user ${memberName} had already joined ${guildName}`);
return;
}
if (sendRole != null) {
const isMuted = Admin.checkMuted(guild, memberId);
if (isMuted) {
if (Util.hasRole(member, sendRole)) {
member.removeRole(sendRole)
.catch(console.error);
Util.logc('MuteOld1', `Removed SendMessages from muted user ${memberName} who had already joined ${guildName}`);
}
} else if (!Util.hasRole(member, sendRole)) {
member.addRole(sendRole)
.catch(console.error);
Util.logc('AssignOld1', `Assigned SendMessages to old member ${memberName}`);
}
}
}
function setupSecurity(guild) {
const sendRole = Util.getRole('SendMessages', guild);
Util.logc('Security1', `Setting up security for ${guild.name} (${guild.members.size} members)`);
guild.members.forEach((member) => {
securityFunc(guild, member, sendRole);
});
}
function setupSecurityVeil() {
const veilGuild = client.guilds.get('417110408088780801');
if (!veilGuild) return Util.logc('SecureVeil1', '[ERROR_VP] Veil guild not found!');
const guild = client.guilds.get('309785618932563968');
if (!guild) return Util.logc('SecureVeil1', '[ERROR_VP] New Veil guild not found!');
const veilBuyer = veilGuild.roles.find('name', 'Veil-Owner');
if (!veilBuyer) return Util.logc('SecureVeil1', '[ERROR_VP] Veil Buyer role not found!');
const newBuyer = guild.roles.find('name', 'Veil-Owner');
if (!newBuyer) return Util.logc('SecureVeil1', '[ERROR_VP] New Buyer role not found!');
// const guildId = guild.id;
// const guildName = guild.name;
Util.logc('SecureVeil1', `Setting up auto-kick for ${guild.name} (${guild.members.size} members)`);
guild.members.forEach((member) => {
const memberId = member.id;
if (memberId === vaebId || memberId === selfId) return;
const memberName = Util.getFullName(member);
const veilMember = Util.getMemberById(memberId, veilGuild);
if (!veilMember) {
Util.logc('SecureVeil1', `[Auto-Old-Kick 1] User not in Veil: ${memberName}`);
member.kick()
.catch(error => Util.logc('SecureVeil1', `[E_AutoOldKick1] ${memberName} | ${error}`));
return;
}
if (!veilMember.roles.has(veilBuyer.id)) {
Util.logc('SecureVeil1', `[Auto-Old-Kick 2] User does not have Buyer role: ${memberName}`);
member.kick()
.catch(error => Util.logc('SecureVeil1', `[E_AutoOldKick2] ${memberName} | ${error}`));
return;
}
if (!member.roles.has(newBuyer.id)) {
member.addRole(newBuyer)
.catch(error => Util.logc('SecureVeil1', `[E_AutoOldAddRole1] ${memberName} | ${error}`));
Util.logc('SecureVeil1', `Updated old member with Buyer role: ${memberName}`);
}
});
return undefined;
}
const veilGuilds = {
'417110408088780801': true,
'309785618932563968': true,
};
exports.secure = async function () {
Util.log('> Securing guilds...');
let securityNum = 0;
const veilGuildsNum = Object.keys(veilGuilds).length;
await Promise.all(client.guilds.map(async (newGuild) => {
await newGuild.fetchMembers();
if (has.call(veilGuilds, newGuild.id)) {
securityNum++;
if (securityNum === veilGuildsNum) setupSecurityVeil();
}
setupSecurity(newGuild);
Trello.setupCache(newGuild);
}));
Util.log('> Security setup complete');
};
/* function notifyOn(channel) { // Not if the last message was a reminder...
// Util.sendDescEmbed(channel, 'Reminder', 'You can gain access to the #anime channel by sending a message saying: `;toggle anime`', null, null, colBlue);
} */
// //////////////////////////////////////////////////////////////////////////////////////////////
Cmds.initCommands();
// Index_Ready -> Data_SQL -> Mutes_Initialize -> Index_Secure
client.on('ready', async () => {
Util.log(`> Connected as ${client.user.username}!`);
if (madeBriefing === false) {
madeBriefing = true;
setBriefing();
}
const dbGuilds = [];
await Promise.all(client.guilds.map(async (newGuild) => {
const allMembers = await newGuild.fetchMembers();
allMembers.forEach(m => Util.mergeUser(m));
Util.logc('InitProxy', `Added proxies to the ${allMembers.size} members of ${newGuild.name}`);
// Music2.initGuild(newGuild);
if (newGuild.id == '417110408088780801') dbGuilds.push(newGuild);
}));
Util.log('> Cached all guild members!');
await Data.connectInitial(dbGuilds);
});
client.on('disconnect', (closeEvent) => {
Util.log('DISCONNECTED');
Util.log(closeEvent);
Util.log(`Code: ${closeEvent.code}`);
Util.log(`Reason: ${closeEvent.reason}`);
Util.log(`Clean: ${closeEvent.wasClean}`);
});
client.on('guildCreate', (guild) => {
guild.fetchMembers().then((allMembers) => {
allMembers.forEach(m => Util.mergeUser(m));
});
});
client.on('guildMemberRemove', (member) => {
const guild = member.guild;
Events.emit(guild, 'UserLeave', member);
const sendLogData = [
'User Left',
guild,
member,
{ name: 'Username', value: member.toString() },
{ name: 'Highest Role', value: member.highestRole.name },
];
Util.sendLog(sendLogData, colUser);
});
client.on('guildMemberAdd', (member) => {
Util.mergeUser(member);
const guild = member.guild;
const guildName = guild.name;
const memberId = member.id;
const memberName = Util.getFullName(member);
Util.logc(memberId, `User joined: ${memberName} (${memberId}) @ ${guildName}`);
// Protect Veil Private
if (guild.id === '309785618932563968') {
const veilGuild = client.guilds.get('417110408088780801');
const veilBuyer = veilGuild.roles.find('name', 'Veil-Owner');
const newBuyer = guild.roles.find('name', 'Veil-Owner');
if (!veilGuild) {
Util.logc(memberId, '[ERROR_VP] Veil guild not found!');
} else if (!veilBuyer) {
Util.logc(memberId, '[ERROR_VP] Veil Buyer role not found!');
} else if (!newBuyer) {
Util.logc(memberId, '[ERROR_VP] New Buyer role not found!');
} else {
const veilMember = Util.getMemberById(memberId, veilGuild);
if (!veilMember) {
Util.logc(memberId, `[Auto-Kick 1] User not in Veil: ${memberName}`);
member.kick()
.catch(error => Util.logc(memberId, `[E_AutoKick1] ${error}`));
return;
}
if (!veilMember.roles.has(veilBuyer.id)) {
Util.logc(memberId, `[Auto-Kick 2] User does not have Buyer role: ${memberName}`);
member.kick()
.catch(error => Util.logc(memberId, `[E_AutoKick2] ${error}`));
return;
}
member.addRole(newBuyer)
.catch(error => Util.logc(memberId, `[E_AutoAddRole1] ${error}`));
Util.logc(memberId, 'Awarded new member with Buyer role');
}
}
// Restore buyer role
if (guild.id == '417110408088780801') {
Data.query(`SELECT * FROM whitelist WHERE Disabled IS NULL AND DiscordId=${member.id};`, null, Data.connectionVeil).then((whitelistData) => {
if (whitelistData.length > 0) {
const buyerRole = Util.getRole('Veil-Owner', guild);
if (buyerRole) {
member.addRole(buyerRole)
.catch(Util.logErr);
Util.logc(member.id, `Assigned Buyer to new buyer ${memberName} who just joined ${guildName}`);
}
}
});
}
// GlobalBan
if (has.call(exports.globalBan, memberId)) {
member.kick()
.catch(console.error);
Util.logc(memberId, `Globally banned user ${memberName} joined ${guildName}`);
return;
}
// Restore mute
const isMuted = Admin.checkMuted(guild, memberId);
if (isMuted) {
Util.logc(memberId, `Muted user ${memberName} joined ${guildName}`);
} else {
const sendRole = Util.getRole('SendMessages', guild);
if (sendRole) {
member.addRole(sendRole)
.catch(console.error);
Util.logc(memberId, `Assigned SendMessages to new member ${memberName}`);
}
}
Data.getRecords(guild, 'members', { user_id: member.id }).then((results) => {
const isBuyer = Util.hasRoleName(member, 'Veil-Owner');
if (results.length == 0 && isBuyer) {
Data.addRecord(guild, 'members', { user_id: member.id, buyer: isBuyer ? 1 : 0 });
Util.logc(memberId, `Adding new member ${Util.getFullName(member)} to MySQL DB`);
}
});
if (memberId === '280579952263430145') member.setNickname('<- mentally challenged');
Events.emit(guild, 'UserJoin', member);
const sendLogData = [
'User Joined',
guild,
member,
{ name: 'Username', value: member.toString() },
];
Util.sendLog(sendLogData, colUser);
});
client.on('guildMemberUpdate', (oldMember, member) => {
const guild = member.guild;
const previousNick = oldMember.nickname;
const nowNick = member.nickname;
const oldRoles = oldMember.roles;
const nowRoles = member.roles;
const rolesAdded = nowRoles.filter(role => (!oldRoles.has(role.id)));
const rolesRemoved = oldRoles.filter(role => (!nowRoles.has(role.id)));
if (rolesAdded.size > 0) {
rolesAdded.forEach((nowRole) => {
if ((member.id === '214047714059616257' || member.id === '148931616452902912') && (nowRole.id === '293458258042159104' || nowRole.id === '284761589155102720')) {
member.removeRole(nowRole);
}
if (nowRole.name === 'Veil-Owner' && guild.id === '417110408088780801') {
/* const message = 'Please join the Veil Buyers Discord:\n\nhttps://discord.gg/PRq6fcg\n\nThis is very important, thank you.';
const title = 'Congratulations on your purchase of Veil';
const footer = Util.makeEmbedFooter('AutoMessage');
Util.sendDescEmbed(member, title, message, footer, null, colBlue); */
}
if (nowRole.name.includes('Mod') && (member.id == '202660584330625024')) {
member.removeRole(nowRole);
}
const isMuted = Admin.checkMuted(guild, member.id);
if (nowRole.name === 'SendMessages' && isMuted) {
member.removeRole(nowRole);
Util.log(`Force re-muted ${Util.getName(member)} (${member.id})`);
} else {
const sendLogData = [
'Role Added',
guild,
member,
{ name: 'Username', value: member.toString() },
{ name: 'Role Name', value: nowRole.name },
];
Util.sendLog(sendLogData, colUser);
}
if (nowRole.name === 'Veil-Owner') {
Data.getRecords(guild, 'members', { user_id: member.id, buyer: 1 }).then((results) => {
if (results.length == 0) {
Data.addRecord(guild, 'members', { user_id: member.id, buyer: 1 });
Util.logc('BuyerAdd1', `Adding ${Util.getFullName(member)} as a buyer in MySQL DB`);
}
});
}
Events.emit(guild, 'UserRoleAdd', member, nowRole);
});
}
if (rolesRemoved.size > 0) {
rolesRemoved.forEach((nowRole) => {
const isMuted = Admin.checkMuted(guild, member.id);
if (nowRole.name === 'SendMessages' && !isMuted) {
member.addRole(nowRole)
.catch(console.error);
Util.log(`Force re-unmuted ${Util.getName(member)} (${member.id})`);
} else {
const sendLogData = [
'Role Removed',
guild,
member,
{ name: 'Username', value: member.toString() },
{ name: 'Role Name', value: nowRole.name },
];
Util.sendLog(sendLogData, colUser);
}
if (nowRole.name === 'Veil-Owner') {
Data.getRecords(guild, 'members', { user_id: member.id, buyer: 1 }).then((results) => {
if (results.length > 0) {
Data.addRecord(guild, 'members', { user_id: member.id, buyer: 0 });
Util.logc('BuyerAdd1', `Removed ${Util.getFullName(member)} as a buyer in MySQL DB`);
}
});
}
Events.emit(guild, 'UserRoleRemove', member, nowRole);
});
}
if (previousNick !== nowNick) {
if (member.id === '280579952263430145' && nowNick !== '<- mentally challenged') member.setNickname('<- mentally challenged');
Events.emit(guild, 'UserNicknameUpdate', member, previousNick, nowNick);
const sendLogData = [
'Nickname Updated',
guild,
member,
{ name: 'Username', value: member.toString() },
{ name: 'Old Nickname', value: previousNick },
{ name: 'New Nickname', value: nowNick },
];
Util.sendLog(sendLogData, colUser);
}
});
/* client.on('userUpdate', (oldUser, user) => {
const oldUsername = oldUser.username;
const newUsername = user.username;
if (oldUsername !== newUsername) {
Events.emit(guild, 'UserNicknameUpdate', member, previousNick, nowNick);
const sendLogData = [
'Username Updated',
guild,
member,
{ name: 'Username', value: member.toString() },
{ name: 'Old Nickname', value: previousNick },
{ name: 'New Nickname', value: nowNick },
];
Util.sendLog(sendLogData, colUser);
}
}); */
client.on('messageUpdate', (oldMsgObj, newMsgObj) => {
if (newMsgObj == null) return;
const channel = newMsgObj.channel;
if (channel.name === 'vaebot-log') return;
const guild = newMsgObj.guild;
const member = newMsgObj.member;
const author = newMsgObj.author;
const content = newMsgObj.content;
const contentLower = content.toLowerCase();
// const isStaff = author.id == vaebId;
// const msgId = newMsgObj.id;
const oldContent = oldMsgObj.content;
for (let i = 0; i < exports.blockedWords.length; i++) {
if (contentLower.includes(exports.blockedWords[i].toLowerCase())) {
newMsgObj.delete();
return;
}
}
if (exports.runFuncs.length > 0) {
for (let i = 0; i < exports.runFuncs.length; i++) {
exports.runFuncs[i](newMsgObj, member, channel, guild, true);
}
}
Events.emit(guild, 'MessageUpdate', member, channel, oldContent, content);
if (oldContent !== content) {
const sendLogData = [
'Message Updated',
guild,
author,
{ name: 'Username', value: author.toString() },
{ name: 'Channel Name', value: channel.toString() },
{ name: 'Old Message', value: oldContent },
{ name: 'New Message', value: content },
];
Util.sendLog(sendLogData, colMessage);
}
});
exports.lockChannel = null;
exports.calmSpeed = 7000;
exports.slowChat = {};
exports.slowInterval = {};
exports.chatQueue = {};
exports.chatNext = {};
client.on('voiceStateUpdate', (oldMember, member) => {
const oldChannel = oldMember.voiceChannel; // May be null
const newChannel = member.voiceChannel; // May be null
const oldChannelId = oldChannel ? oldChannel.id : null;
const newChannelId = newChannel ? newChannel.id : null;
// const guild = member.guild;
if (member.id === selfId) {
if (member.serverMute) {
member.setMute(false);
Util.log('Force removed server-mute from bot');
}
if (exports.lockChannel != null && oldChannelId === exports.lockChannel && newChannelId !== exports.lockChannel) {
Util.log('Force re-joined locked channel');
oldChannel.join();
}
}
});
/*
Audit log types
const Actions = {
ALL: null,
GUILD_UPDATE: 1,
CHANNEL_CREATE: 10,
CHANNEL_UPDATE: 11,
CHANNEL_DELETE: 12,
CHANNEL_OVERWRITE_CREATE: 13,
CHANNEL_OVERWRITE_UPDATE: 14,
CHANNEL_OVERWRITE_DELETE: 15,
MEMBER_KICK: 20,
MEMBER_PRUNE: 21,
MEMBER_BAN_ADD: 22,
MEMBER_BAN_REMOVE: 23,
MEMBER_UPDATE: 24,
MEMBER_ROLE_UPDATE: 25,
ROLE_CREATE: 30,
ROLE_UPDATE: 31,
ROLE_DELETE: 32,
INVITE_CREATE: 40,
INVITE_UPDATE: 41,
INVITE_DELETE: 42,
WEBHOOK_CREATE: 50,
WEBHOOK_UPDATE: 51,
WEBHOOK_DELETE: 52,
EMOJI_CREATE: 60,
EMOJI_UPDATE: 61,
EMOJI_DELETE: 62,
MESSAGE_DELETE: 72,
};
*/
/* function chooseRelevantEntry(entries, options) {
if (options.action == null || options.time == null) {
Util.log(options);
Util.log('Options did not contain necessary properties');
return undefined;
}
const strongest = [null, null];
entries.forEach((entry) => {
if (entry.action !== options.action || (options.target != null && entry.target.id !== options.target.id)) return;
const timeScore = -Math.abs(options.time - entry.createdTimestamp);
if (strongest[0] == null || timeScore > strongest[0]) {
strongest[0] = timeScore;
strongest[1] = entry;
}
});
return strongest[1];
} */
client.on('messageDelete', (msgObj) => {
Util.log('qqq1');
if (msgObj == null) return;
const channel = msgObj.channel;
const guild = msgObj.guild;
const member = msgObj.member;
const author = msgObj.author;
const content = msgObj.content;
const eventTime = +new Date();
// const evTime = +new Date();
// const contentLower = content.toLowerCase();
// const isStaff = author.id == vaebId;
// const msgId = msgObj.id;
// if (author.id === vaebId) return;
Events.emit(guild, 'MessageDelete', member, channel, content);
if (guild != null) {
Util.getAuditLog(guild, 'MESSAGE_DELETE', { target: author }).then((auditEntry) => {
auditEntry = auditEntry || {};
const executor = auditEntry.executor;
const sinceAuditLog = executor ? eventTime - auditEntry.createdTimestamp : 0;
if (executor) Util.log(`[MESSAGE_DELETE] Elapsed since audit log: ${sinceAuditLog}`);
const attachmentLinks = [];
msgObj.attachments.forEach(obj => attachmentLinks.push(obj.url));
const sendLogData = [
'Message Deleted',
guild,
author,
{ name: 'User', value: Util.resolveMention(author) },
executor ? { name: 'Possible Moderator', value: Util.resolveMention(executor) } : {},
{ name: 'Channel Name', value: channel.toString() },
{ name: 'Message', value: content },
{ name: 'Attachments', value: attachmentLinks.join('\n') },
];
Util.sendLog(sendLogData, colMessage);
});
/* setTimeout(() => {
guild.fetchAuditLogs({
// user: member,
type: 72,
})
.then((logs) => {
Util.log('[MD] Got audit log data');
const entries = logs.entries;
const entry = chooseRelevantEntry(entries, {
time: evTime,
target: author,
action: 'MESSAGE_DELETE',
});
Util.log(entry);
Util.log(entry.executor.toString());
Util.log(entry.target.toString());
const sendLogData = [
'Message Deleted',
guild,
author,
{ name: 'Username', value: author.toString() },
{ name: 'Moderator', value: entry.executor.toString() },
{ name: 'Channel Name', value: channel.toString() },
{ name: 'Message', value: content },
];
Util.sendLog(sendLogData, colMessage);
})
.catch((error) => {
Util.log(error);
Util.log('[MD] Failed to get audit log data');
});
}, 5000); */
}
});
const messageStamps = {};
const userStatus = {};
const lastWarn = {};
const checkMessages = 5; // (n)
const warnGrad = 11.5; // Higher = More Spam (Messages per Second) | 10 = 1 message per second
const sameGrad = 4;
const muteGrad = 8.5; // 9
const waitTime = 5.5;
const endAlert = 40;
/* const replaceAll = function (str, search, replacement) {
return str.split(search).join(replacement);
};
let contentLower = 'lol <qe23> tege <> <e321z> dz';
contentLower = contentLower.replace(/<[^ ]*?[:#@][^ ]*?>/gm, '');
// contentLower = replaceAll(contentLower, ' ', '');
Util.log(contentLower); */
/* exports.runFuncs.push((msgObj, speaker, channel, guild) => { // More sensitive
if (guild == null || msgObj == null || speaker == null || speaker.user.bot === true || speaker.id === vaebId) return;
let contentLower = msgObj.content.toLowerCase();
contentLower = contentLower.replace(/<[^ ]*?[:#@][^ ]*?>/gm, '');
contentLower = Util.replaceAll(contentLower, ' ', '');
contentLower = Util.replaceAll(contentLower, 'one', '1');
contentLower = Util.replaceAll(contentLower, 'won', '1');
contentLower = Util.replaceAll(contentLower, 'uno', '1');
contentLower = Util.replaceAll(contentLower, 'una', '1');
contentLower = Util.replaceAll(contentLower, 'two', '2');
contentLower = Util.replaceAll(contentLower, 'dose', '2');
contentLower = Util.replaceAll(contentLower, 'dos', '2');
contentLower = Util.replaceAll(contentLower, 'too', '2');
contentLower = Util.replaceAll(contentLower, 'to', '2');
contentLower = Util.replaceAll(contentLower, 'three', '3');
contentLower = Util.replaceAll(contentLower, 'tres', '3');
contentLower = Util.replaceAll(contentLower, 'free', '3');
let triggered = false;
if (contentLower === '3') {
triggered = true;
} else {
// const trigger = [/11./g, /12[^8]/g, /13./g, /21./g, /22./g, /23./g, /31./g, /32[^h]/g, /33./g, /muteme/g, /onet.?o/g, /threet.?o/g];
// const trigger = [/[123][123][123]/g, /muteme/g];
const trigger = [/[123][^\d]?[^\d]?[123][^\d]?[^\d]?[123]/g, /[123][123]\d/g, /muteme/g];
for (let i = 0; i < trigger.length; i++) {
if (trigger[i].test(contentLower)) {
triggered = true;
break;
}
}
}
if (triggered) {
Admin.addMute(guild, channel, speaker, 'System', { 'reason': 'Muted Themself' });
}
}); */
/* exports.runFuncs.push((msgObj, speaker, channel, guild) => {
if (guild == null || msgObj == null || speaker == null || speaker.user.bot === true || speaker.id === vaebId || speaker.id === guild.owner.id) return;
let contentLower = msgObj.content.toLowerCase();
contentLower = contentLower.replace(/<[^ ]*?[:#@][^ ]*?>/gm, '');
contentLower = Util.replaceAll(contentLower, ' ', '');
contentLower = Util.replaceAll(contentLower, 'one', '1');
contentLower = Util.replaceAll(contentLower, 'won', '1');
contentLower = Util.replaceAll(contentLower, 'uno', '1');
contentLower = Util.replaceAll(contentLower, 'una', '1');
contentLower = Util.replaceAll(contentLower, 'two', '2');
contentLower = Util.replaceAll(contentLower, 'dose', '2');
contentLower = Util.replaceAll(contentLower, 'dos', '2');
contentLower = Util.replaceAll(contentLower, 'too', '2');
contentLower = Util.replaceAll(contentLower, 'to', '2');
contentLower = Util.replaceAll(contentLower, 'three', '3');
contentLower = Util.replaceAll(contentLower, 'tres', '3');
contentLower = Util.replaceAll(contentLower, 'free', '3');
let triggered = false;
const trigger = [/1\W*2\W*3\d/g];
for (let i = 0; i < trigger.length; i++) {
if (trigger[i].test(contentLower)) {
triggered = true;
break;
}
}
if (triggered) {
Admin.addBan(guild, channel, speaker, 'System', { time: null, reason: 'Banned Themself', temp: true });
}
}); */
exports.runFuncs.push((msgObj, speaker, channel, guild) => {
if (guild == null || msgObj == null || speaker == null || speaker.user.bot === true || speaker.id === vaebId) return;
let contentLower = msgObj.content.toLowerCase();
contentLower = contentLower.replace(/\s/g, '');
contentLower = contentLower.replace(/which/g, 'what');
contentLower = contentLower.replace(/great/g, 'best');
contentLower = contentLower.replace(/finest/g, 'best');
contentLower = contentLower.replace(/perfect/g, 'best');
contentLower = contentLower.replace(/top/g, 'best');
contentLower = contentLower.replace(/hack/g, 'exploit');
contentLower = contentLower.replace(/h\Sx/g, 'exploit');
contentLower = contentLower.replace(/le?v\S?l(?:\d|s|f)/g, 'exploit');
let triggered = 0;
const trigger = [/wh?[au]t/g, /b\S?st/g, /explo\S?t/g];
for (let i = 0; i < trigger.length; i++) {
if (trigger[i].test(contentLower)) triggered++;
}
if (triggered == trigger.length) {