-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
1169 lines (1132 loc) · 45.7 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
/***
Discord utility bot built mostly by Jett, Jonah, and some cool contributors.
TODO:
- Word filter
- Better mute command, hooked up to server's DB.
IDEAS:
- Add modules to clean up this code!!!
- Add a databse to manage server-specific data, then bot can be added to other servers and work
- Management category
- Should mod cmds be deleted?
- Turn the roles channel into a bot controlled one
Any comments that are not role giving commands are deleted, channel will only allow giving of roles
- Have a report feature that deletes a post after 3-5 flags, only if user is able to
Included with the above, a message can be approved with a reaction from staff
- Bulk add roles to someone, at least 1, check if roles are different. addRoles <user> <roles, ...>
- Server info
- Roleinfo
- Total number of msgs in server
- Ping command
- Channel info
- Deletion logs
- Unban cmd
- Polls
- View active invites for a server
- Lock a channel
- Return errors if bot doesn’t have right channels to post logs and stuff in
- Binary convertor
- Color info
- Cmd to make bot react to given message, with given emoji
- If message gets N downvotes, it can’t get to star board
- For all the events, put them in an obj like the commands obj and loop through accordingly.
***/
// Load .env variables.
require("dotenv").load();
// Require needed modules.
const Discord = require("discord.js");
const request = require("request");
const Filter = require("./modules/filter/Filter");
// Set up client.
const client = new Discord.Client();
// Client settings.
const prefix = "=";
const deleteDelay = 5000; // 5 second delete delay.
const creators = ["<@218397146049806337>", "<@309845156696424458>"]; // Jett and Jonah
const botAdmin = []; // Maybe fill this with IDs of users who can use eval.
const blacklisted = []; // IDs of blacklisted users.
// Embed colors.
const embedDefaultColor = "b3b3b3"; // Grey.
const embedRedColor = "ff6666"; // Red.
const embedGreenColor = "00b33c"; // Green.
const embedYellowColor = "e6e600"; // Yellow.
// Variables to be defined.
const DEV_MODE = process.env.DEV == 1;
const LOGS_ID = DEV_MODE ? process.env.LOGS_ID : "530516100354670642";
const JUNKYARD_ID = DEV_MODE ? process.env.JUNKYARD_ID : "477291431069745154";
const MUTED_ROLE = DEV_MODE ? process.env.MUTED_ROLE : "474244727223615492";
// In KAD.
const hiddenChannels = ["452247073174323222", "473221758279745552", "454132320849625109", "477291431069745154"];
const filter = new Filter(require("./homoglyphs.json"), require("./filter.json"));
// Permissions checking functions.
const hasManageMessages = msg => {
if (msg.member.hasPermission("MANAGE_MESSAGES")) {
return true;
}
return false;
}
const hasKickPerms = msg => {
if (msg.member.hasPermission("KICK_MEMBERS")) {
return true;
}
return false;
}
const hasBanPerms = msg => {
if (msg.member.hasPermission("BAN_MEMBERS")) {
return true;
}
return false;
}
const hasRolesPerms = msg => {
if (msg.member.hasPermission("MANAGE_ROLES")) {
return true;
}
return false;
}
const hasManageGuild = msg => {
if (msg.member.hasPermission("MANAGE_GUILD")) {
return true;
}
return false;
}
// Message sending functions.
const deleteMessage = msg => {
msg.delete(deleteDelay);
};
const logMessage = (msg, obj) => {
let embed = new Discord.RichEmbed();
embed.setTimestamp();
if (obj.serverChange) {
embed.setColor(embedDefaultColor);
embed.setThumbnail(client.user.avatarURL);
embed.addField("Server Change", obj.serverChange);
embed.addField("Change by", obj.byWho);
embed.addField("Reason", obj.reason);
msg.guild.channels.find("id", LOGS_ID).send({ embed });
} else
if (obj.modAction) {
embed.setColor(embedRedColor);
embed.setThumbnail(client.user.avatarURL);
embed.addField("Staff Action", obj.modAction);
embed.addField("User", obj.user)
embed.addField("Action by", obj.byWho);
embed.addField("Reason", obj.reason);
msg.guild.channels.find("id", LOGS_ID).send({ embed });
} else
if (obj.flaggers) {
embed.setColor(embedRedColor);
embed.setThumbnail("https://media.discordapp.net/attachments/479408863162925062/485630915586949163/unknown.png");
embed.addField("Message Author", obj.user);
embed.addField("Message Content", obj.content);
embed.addField("Flaggers", obj.flaggers);
embed.addField("Posted in", obj.channel);
msg.guild.channels.find("id", JUNKYARD_ID).send({ embed }).then(m => m.react("🗑"));
}
}
const sendDM = msg => {
if (!DEV_MODE) {
client.users.find("id", "218397146049806337").send(msg);
}
};
const sendError = err => {
let embed = new Discord.RichEmbed();
embed.setColor("#e60000");
embed.setThumbnail(client.user.avatarURL);
embed.setAuthor("Error!", "https://media.discordapp.net/attachments/386537690260176897/418165473897611274/unknown.png");
embed.setDescription(err);
embed.setTimestamp();
sendDM({ embed });
};
const permError = msg => {
msg.react("❌");
msg.channel.send("You do not have permissions to use this command.")
.then(m => deleteMessage(m));
};
const commandError = (msg, err) => {
msg.react("❌");
msg.channel.send(`:x: ${err}`)
.then(msg => msg.delete(deleteDelay));;
}
// Misc functions.
const millisToTime = function(milliseconds) {
let x = milliseconds / 1000;
let s = Math.floor(x % 60);
x /= 60;
let m = Math.floor(x % 60);
x /= 60;
let h = Math.floor(x % 24);
return h + " Hours, " + m + " Minutes, " + s + " Seconds";
};
const otherFunctions = (message) => {
var content = message.content.toLowerCase();
if (content.includes("good night") || content.includes("g'night") || content.includes("goodnight") || content.includes("g night")) message.react("🌙");
if (message.author.id === "309845156696424458" || message.author.id === "218397146049806337" || message.author.id === "221285118608801802" || message.author.id === "299150484218970113") {
if (content == "blob") {
message.channel.send("<a:rainbowBlob:402289443593125888>").then((m) => {
message.delete();
m.react("402289443593125888");
}).catch(e => {
sendError(e);
});
}
}
if (content.includes("jett burns") || content.includes("jett") || message.mentions.users.exists("id", "218397146049806337")) {
if (message.author.id != "218397146049806337") {
let embed = new Discord.RichEmbed();
embed.setColor(embedDefaultColor);
embed.setAuthor("You were mentioned!", message.author.avatarURL);
embed.addField("Content", message.content);
embed.addField("Sender", message.author);
embed.addField("Server", message.guild);
embed.addField("Channel", message.channel, true);
embed.addField("Link", `https://discordapp.com/channels/${message.guild.id}/${message.channel.id}?jump=${message.id}`, true);
embed.setTimestamp();
sendDM({ embed });
}
}
// If bot is mentioned, react with thinking.
if (message.mentions.users.exists("id", "372013264453894154")) message.react("🤔");
};
// All bot commands.
const commands = {
help: {
name: "help",
category: "General",
description: "Returns all of my commands.",
usage: `${prefix}help`,
do: (message, client, args, Discord) => {
if (!args[0]){
let embed = new Discord.RichEmbed();
embed.setColor(embedDefaultColor);
embed.setAuthor("My Commands", client.user.avatarURL);
embed.addField("General", Object.keys(commands).filter(key => {
return commands[key].category === "General";
}).reduce((acc, curr, idx, arr) => {
return acc + curr + (idx === arr.length-1 ? "" : ", ");
}, ""), false);
embed.addField("Moderation", Object.keys(commands).filter(key => {
return commands[key].category === "Moderation";
}).reduce((acc, curr, idx, arr) => {
return acc + curr + (idx === arr.length-1 ? "" : ", ");
}, ""), false);
embed.setThumbnail(client.user.avatarURL);
message.channel.send({ embed });
} else {
let selection = args[0];
let embed = new Discord.RichEmbed();
embed.setColor(embedDefaultColor);
embed.setThumbnail(client.user.avatarURL);
embed.addField("Usage:", commands[selection].usage);
embed.addField("Description:", commands[selection].description);
embed.setFooter("<Angle Brackets> = Required Parameters. [Brackets] = Optional Parameters.");
message.channel.send({ embed });
}
}
},
ping: {
name: "ping",
category: "General",
description: "Shows how long does it take the bot to respond.",
usage: `${prefix}ping`,
do: (message, client, args, Discord) => {
message.channel.send('Pinging...').then(sent => {
sent.edit(`:clock2: Pong! Took ${sent.createdTimestamp - message.createdTimestamp}ms`);
});
}
},
memberCount: {
name: "memberCount",
description: "Check how many members are in the server.",
category: "General",
usage: `${prefix}memberCount`,
do: (message, client, args, Discord) => {
let embed = new Discord.RichEmbed();
embed.addField("Members", message.guild.memberCount);
embed.setColor(embedDefaultColor);
message.channel.send({ embed });
}
},
uptime: {
name: "uptime",
description: "Shows how long the bot has been online.",
category: "General",
usage: `${prefix}uptime`,
do: (message, client, args, Discord) => {
message.channel.send(":clock230: Bot has been online for " + millisToTime(client.uptime));
}
},
color: {
name: "color",
description: "Display a given hex color",
category: "General",
usage: `${prefix}color <hex>`,
do: (message, client, args, Discord) => {
// Add validation, regex
if (args[0]) {
let embed = new Discord.RichEmbed();
embed.setThumbnail(`http://placehold.it/300x300.png/${args[0]}/000000&text=%20`);
embed.setColor(args[0]);
message.channel.send({ embed });
} else {
commandError(message, "Not a valid hex value.");
}
}
},
info: {
name: "info",
description: "Shows info about this bot.",
category: "General",
usage: `${prefix}info`,
do: (message, client, args, Discord) => {
let embed = new Discord.RichEmbed();
embed.setThumbnail(client.user.avatarURL);
embed.addField("Users", client.users.size, true);
embed.addField("Servers", client.guilds.size, true);
embed.addField("Creators", creators[0] + ", " + creators[1], true);
embed.addField("Invite", "http://bit.ly/InviteToolbot", true);
embed.addField("GitHub", "https://github.com/JettBurns14/Discord-tool-bot", true);
embed.setColor(embedDefaultColor);
message.channel.send({ embed });
}
},
userInfo: {
name: "userInfo",
description: "Check info about yourself or a given user.",
category: "General",
usage: `${prefix}userInfo [member]`,
do: (message, client, args, Discord) => {
let member = message.mentions.members.first();
if (member == null) { member = message.member; }
let joined = new Date(member.joinedAt);
let registered = new Date(member.user.createdAt);
let embed = new Discord.RichEmbed();
let perms = [];
for (let [key, value] of Object.entries(member.permissions.serialize())) {
if (value == true) {
perms.push(key);
} else {
continue;
}
}
embed.setAuthor(member.user.tag, member.user.avatarURL);
embed.setThumbnail(member.user.avatarURL);
embed.addField("ID", member.id, true);
embed.addField("Nickname", (member.nickname != null ? member.nickname : "None"), true);
embed.addField("Status", member.presence.status, true);
embed.addField("Game", (member.presence.game != null ? member.presence.game.name : "None"), true);
embed.addField("Joined", joined, true);
embed.addField("Registered", registered, true);
embed.addField("Roles", member.roles.map(x => x.name).join(", "), true);
embed.addField("Permissions", perms.join(", ").toLowerCase(), true);
embed.setColor(embedDefaultColor);
message.channel.send({ embed }).catch(e => {
sendError(e);
});
//console.log(Object.entries(Object.values(member.permissions.serialize()).filter(x => x == true)));
}
},
levels: {
name: "levels",
description: "Displays top ten Mee6 users.",
category: "General",
usage: `${prefix}levels`,
do: (message, client, args, Discord) => {
// Check if Mee6 is in server
if (message.guild.members.exists("id", "159985870458322944")) {
let serverId = message.guild.id;
// Get Mee6 stats
request(`https://mee6.xyz/api/plugins/levels/leaderboard/${serverId}`, (err, res, body) => {
let data = JSON.parse(body);
// Get top ten users
let topTen = data.players.filter((curr, idx, arr) => {
return idx < 10;
});
// Incase the above doesn"t work
if (topTen.length === 10) {
let embed = new Discord.RichEmbed();
embed.setColor(embedDefaultColor);
// Add 10 fields in embed
topTen.forEach((user, i) => {
embed.addField(i + 1, `<@${user.id}> – **${user.xp.toLocaleString()}** Exp – Level **${user.level}**`);
});
embed.setThumbnail(message.guild.iconURL);
message.channel.send({ embed });
} else {
commandError(message, "Could not get top ten Mee6 users.");
}
});
} else {
commandError(message, "Mee6 is not in this server.");
}
}
},
purge: {
name: "purge",
category: "Moderation",
description: "Remove messages in bulk, 1-100.",
usage: `${prefix}purge <number>`,
do: (message, client, args, Discord) => {
if (hasManageMessages(message)) {
if (+args[0] <= 100 && +args[0] >= 1) {
message.channel.bulkDelete(+args[0] + 1).then(msgs => {
message.channel.send(`:white_check_mark: Deleted ${msgs.size - 1} messages`).then(msg => deleteMessage(msg));
}).catch(e => {
sendError(e);
});
} else {
commandError(message, "Please provide a number ≤ 100 and ≥ 1.");
}
} else {
permError(message);
}
}
},
kick: {
name: "kick",
description: "Kick a member.",
category: "Moderation",
usage: `${prefix}kick <member> <reason>`,
do: (message, client, args, Discord) => {
if (hasKickPerms(message)) {
const user = message.mentions.users.first();
const reason = args.slice(1).join(" ");
const userId = args[0];
// This doesn't want to work when a user isn't in the guild.
if (user) {
const member = message.guild.member(user);
if (member) {
if (reason) {
member.kick(reason)
.then(u => {
logMessage(message, {
modAction: "Kick User",
user: `<@${u.id}>`,
byWho: `<@${message.author.id}>`,
reason: reason
});
})
.catch(e => {
sendError(e);
});
} else {
commandError(message, "You must provide a reason for kicking.");
}
} else {
// The mentioned user isn't in this guild
commandError(message, "That user isn\'t in this guild, try providing their user ID instead.");
}
} else {
commandError(message, "You didn't identify a valid user.");
}
} else {
permError(message);
}
}
},
ban: {
name: "ban",
description: "Ban a member.",
category: "Moderation",
usage: `${prefix}ban <member> <reason>`,
do: (message, client, args, Discord) => {
if (hasBanPerms(message)) {
const user = message.mentions.users.first();
const reason = args.slice(1).join(" ");
const userId = args[0];
// This doesn't want to work when a user isn't in the guild.
if (user) {
const member = message.guild.member(user);
if (member) {
if (reason) {
message.guild.ban(user, {
days: 0,
reason: reason
})
.then(u => {
logMessage(message, {
modAction: "Ban User",
user: `<@${u.id}>`,
byWho: `<@${message.author.id}>`,
reason: reason
});
})
.catch(e => {
sendError(e);
});
} else {
commandError(message, "You must provide a reason for banning.");
}
} else {
// The mentioned user isn't in this guild
commandError(message, "That user isn\'t in this guild, try providing their user ID instead.");
}
} else {
commandError(message, "You didn't identify a valid user.");
}
} else {
permError(message);
}
}
},
unban: {
name: "unban",
description: "Unban a member.",
category: "Moderation",
usage: `${prefix}unban <member> <reason>`,
do: (message, client, args, Discord) => {
if (hasBanPerms(message)) {
const reason = args.slice(1).join(" ");
const user = message.mentions.members.first();
const userId = args[0];
console.log(userId);
if (user || userId) {
if (reason) {
message.guild.unban(user || userId, reason)
.then(u => {
logMessage(message, {
modAction: "Unban User",
user: `<@${u.id}>`,
byWho: `<@${message.author.id}>`,
reason: reason
});
})
.catch(e => {
sendError(e);
});
} else {
commandError(message, "You must provide a reason for unbanning.");
}
} else {
commandError(message, "You didn't identify a valid user.");
}
} else {
permError(message);
}
}
},
setGame: {
name: "setGame",
description: "Set game of the bot.",
category: "Moderation",
usage: `${prefix}setGame <game>`,
do: (message, client, args, Discord) => {
if (message.author.id === "218397146049806337") {
client.user.setPresence({ game: { name: args.join(" "), type: 0 } });
message.channel.send(":white_check_mark: Game set to: `" + args.join(" ") + "`").then(msg => deleteMessage(msg));
} else {
permError(message);
}
}
},
bans: {
name: "bans",
description: "View bans for this server",
category: "Moderation",
usage: `${prefix}bans`,
do: (message, client, args, Discord) => {
if (hasBanPerms(message)) {
message.guild.fetchBans()
.then(bans => {
if (bans.size > 0) {
let embed = new Discord.RichEmbed();
embed.setColor(embedDefaultColor);
embed.addField("Bans",
bans.array().reduce((acc, curr) => {
return acc + `${curr.tag}\n`;
}, "")
);
message.channel.send({ embed });
} else {
commandError(message, "No bans for this server.");
}
}).catch(e => {
sendError(e);
});
} else {
permError(message);
}
}
},
eval: {
name: "eval",
category: "Moderation",
description: "Evaluates JavaScript code.",
usage: `${prefix}eval <code>`,
do: (message, client, args, Discord) => {
if (message.author.id === "218397146049806337" || message.author.id === "309845156696424458") {
function clean(text) {
if (typeof(text) === "string")
return text.replace(/`/g, "`" + String.fromCharCode(8203)).replace(/@/g, "@" + String.fromCharCode(8203));
else
return text;
}
try {
const code = args.join(" ");
let evaled = eval(code);
if (typeof evaled !== "string") {
evaled = require("util").inspect(evaled);
}
message.channel.send(clean(evaled), { code: "xl" }).catch(e => {
sendError(e);
});
} catch (err) {
message.channel.send(`\`ERROR\` \`\`\`xl\n${clean(err)}\n\`\`\``);
}
} else {
permError(message);
}
}
},
msgEdits: {
name: "msgEdits",
description: "View edit history of a given message.",
category: "Moderation",
usage: `${prefix}msgEdits <messageID>`,
do: (message, client, args, Discord) => {
if (hasManageMessages(message)) {
let edits = "";
let embed = new Discord.RichEmbed();
//embed.setThumbnail(client.user.avatarURL); Use this????
embed.setColor(embedDefaultColor);
message.channel.fetchMessage(args[0])
.then(msg => {
for (var i = 0; i < msg.edits.length; ++i) {
edits += msg.edits[i] + ", ";
}
embed.addField("Content", msg.content);
embed.addField("Edits", edits);
message.channel.send({ embed });
}).catch(e => {
sendError(e);
});
} else {
permError(message);
}
}
},
clearReactions: {
name: "clearReactions",
description: "Clear reactions for a given message.",
category: "Moderation",
usage: `${prefix}clearReactions <messageId>`,
do: (message, client, args, Discord) => {
if (hasManageMessages(message)) {
let embed = new Discord.RichEmbed();
embed.setColor(embedDefaultColor);
message.channel.fetchMessage(args[0]).then(msg => {
msg.clearReactions();
embed.addField("Success", ":white_check_mark: Reactions cleared.");
message.channel.send({ embed }).then(msg => deleteMessage(msg));
}).catch(e => {
sendError(e);
});
} else {
permError(message);
}
}
},
pin: {
name: "pin",
description: "Pin a given message.",
category: "Moderation",
usage: `${prefix}pin <messageId>`,
do: (message, client, args, Discord) => {
if (hasManageMessages(message)) {
let embed = new Discord.RichEmbed();
embed.setColor(embedDefaultColor);
message.channel.fetchMessage(args[0]).then(msg => {
msg.pin();
embed.addField("Success", ":white_check_mark: Message pinned.");
message.channel.send({ embed }).then(msg => deleteMessage(msg));
}).catch(e => {
sendError(e);
});
} else {
permError(message);
}
}
},
unpin: {
name: "unpin",
description: "Unpin a given message.",
category: "Moderation",
usage: `${prefix}unpin <messageId>`,
do: (message, client, args, Discord) => {
if (hasManageMessages(message)) {
let embed = new Discord.RichEmbed();
embed.setColor(embedDefaultColor);
message.channel.fetchMessage(args[0]).then(msg => {
msg.unpin();
embed.addField("Success", ":white_check_mark: Message unpinned.");
message.channel.send({ embed }).then(msg => deleteMessage(msg));
}).catch(e => {
sendError(e);
});
} else {
permError(message);
}
}
},
servers: {
name: "servers",
description: "Get names and IDs of servers this bot is handling.",
category: "Moderation",
usage: `${prefix}servers`,
do: (message, client, args, Discord) => {
if (message.author.id === "218397146049806337") {
let embed = new Discord.RichEmbed();
embed.setColor(embedDefaultColor);
embed.addField("Servers", client.guilds.map(guild => guild.name));
embed.addField("IDs", client.guilds.map(guild => guild.id));
embed.addField("Owners", client.guilds.map(guild => guild.owner));
message.channel.send({ embed });
} else {
permError(message);
}
}
},
say: {
name: "say",
description: "Send a message with given content",
category: "Moderation",
usage: `${prefix}say <content>`,
do: (message, client, args, Discord) => {
if (message.author.id === "218397146049806337") {
message.delete().then(() => {
message.channel.send(args.join(" "));
}).catch(e => {
sendError(e);
});
} else {
permError(message);
}
}
},
mute: {
name: "mute",
description: "Mutes a member",
category: "Moderation",
usage: `${prefix}mute <user> <reason>`,
do: (message, client, args, Discord) => {
if (hasRolesPerms(message)) {
const user = message.mentions.users.first();
const reason = args.slice(1).join(" ");
if (user) {
const member = message.guild.member(user);
if (member) {
if (reason) {
let muteRole = message.guild.roles.find("id", MUTED_ROLE);
if (muteRole) {
member.addRole(muteRole, reason).then(u => {
logMessage(message, {
modAction: "Mute User",
user: `<@${u.id}>`,
byWho: `<@${message.author.id}>`,
reason: reason
});
}).catch(e => {
sendError(e);
});
} else {
commandError(message, "Muted role does not exist.");
}
} else {
commandError(message, "Please provide a reason for this mute.");
}
} else {
commandError(message, "This user isn't a member of this server.");
}
} else {
commandError(message, "This user cannot be found.");
}
} else {
permError(message);
}
}
},
unmute: {
name: "unmute",
description: "Unmutes a member",
category: "Moderation",
usage: `${prefix}unmute <user>`,
do: (message, client, args, Discord) => {
if (hasRolesPerms(message)) {
const user = message.mentions.users.first();
const reason = args.slice(1).join(" ");
if (user) {
const member = message.guild.member(user);
if (member) {
if (reason) {
let muteRole = message.guild.roles.find("id", MUTED_ROLE);
if (muteRole) {
member.removeRole(muteRole, reason).then(u => {
logMessage(message, {
modAction: "Unmute User",
user: `<@${u.id}>`,
byWho: `<@${message.author.id}>`,
reason: reason
});
}).catch(e => {
sendError(e);
});
} else {
commandError(message, "Muted role does not exist.");
}
} else {
commandError(message, "Please provide a reason for this unmute.");
}
} else {
commandError(message, "This user isn't a member of this server.");
}
} else {
commandError(message, "This user cannot be found.");
}
} else {
permError(message);
}
}
},
invites: {
name: "invites",
description: "Show all invites for a server.",
category: "Moderation",
usage: `${prefix}invites`,
do: (message, client, args, Discord) => {
if (message.member.hasPermission("MANAGE_GUILD")) {
message.guild.fetchInvites().then(invites => {
if (invites.size > 0) {
let embed = new Discord.RichEmbed();
embed.setColor(embedDefaultColor);
embed.setThumbnail(client.user.avatarURL);
embed.addField("Invites",
invites.array().reduce((acc, curr) => {
return acc + `${curr.code} - ${curr.uses} (${curr.inviter.username}: <@${curr.inviter.id}>)\n`;
}, "")
);
message.channel.send({ embed });
} else {
commandError(message, "There are no invites.");
}
}).catch(e => {
sendError(e);
});
}
}
},
destroy: {
name: "destroy",
description: "Shut down the bot",
category: "Moderation",
usage: `${prefix}destroy`,
do: (message, client, args, Discord) => {
if (message.author.id === "218397146049806337") {
client.destroy().then(() => {
console.log("Client destroyed");
process.exit(0);
});
} else {
permError(message);
}
}
},
action: {
name: "action",
description: "Log a change to the server.",
category: "Moderation",
usage: `${prefix}action <description>`,
do: (message, client, args, Discord) => {
if (message.member.hasPermission("MANAGE_GUILD")) {
}
}
},
modLog: {
name: "modLog",
description: "test",
category: "Moderation",
usage: `${prefix}log`,
do: (message, client, args, Discord) => {
logMessage(message, {
modAction: "Kicked alt",
user: "MrAlt",
byWho: "Jett",
reason: "This user was kicked because of very similar behavior to a user we previously banned and the obvious name."
});
}
},
change: {
name: "change",
description: "test",
category: "Moderation",
usage: `${prefix}change`,
do: (message, client, args, Discord) => {
logMessage(message, {
serverChange: "New bot, fixed channel perms",
byWho: "Jett",
reason: "This bot was added because of X and the channel perms were broken, so we disabled TTS for users."
});
}
},
/*
blacklist: {
name: "User blacklist",
description: "Add or remove member to blacklist, and view it.",
usage: `${prefix}blacklist [add/remove] [member]`,
do: (message, client, args, Discord) => {
try {
if (message.member.hasPermission("MANAGE_SERVER")) {
//let reason = args.slice(1).join(" ");
if (message.mentions.members.size !== 0) {
//message.mentions.members.first().ban(reason)
message.channel.send(`<@${message.mentions.users.first().id}> has been mentioned by <@${message.author.id}>.`);
} else {
message.channel.send("You didn"t identify a valid user");
}
}
} catch(e) {
console.log(e);
}
}
}*/
};
// Client events.
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}`);
client.user.setPresence({ game: { name: `${prefix}help`, type: 0 } });
let embed = new Discord.RichEmbed();
embed.setColor(embedDefaultColor);
embed.setThumbnail(client.user.avatarURL);
embed.setAuthor("Ready!", "https://media.discordapp.net/attachments/307975805357522944/392142646618882060/image.png");
embed.setDescription("I am online and at your service, Jett!");
embed.setTimestamp();
sendDM({ embed });
});
client.on("message", message => {
if (message.author.bot) return;
if (message.channel.type !== "dm") {
filter.run(message, Discord, JUNKYARD_ID)
.catch(e => console.error("Filter error: ", e));
}
otherFunctions(message);
if (!message.content.startsWith(prefix)) return;
let args = message.content.split(" ").splice(1);
let command = message.content.substring(prefix.length).split(" ");
for (let i in commands){
if (command[0].toLowerCase() === commands[i].name.toLowerCase()) {
try {
commands[i].do(message, client, args, Discord);
} catch(e) {
sendError(e);
}
}
}
});
client.on("messageUpdate", (oldMsg, newMsg) => {
if (newMsg.channel.type !== "dm" && newMsg.content) {
console.log("Message edited:");
console.log(`Old content: ${oldMsg.content}`);
console.log(`New content: ${newMsg.content}`);
filter.run(newMsg, Discord, JUNKYARD_ID)
.catch(e => console.error("Filter error: ", e));
}
});
client.on("messageReactionAdd", (reaction, user) => {
const msgChannelId = reaction.message.channel.id;
// If emoji is the KA flag...
if (reaction.emoji.id === "485490810071285809") {
// and user is not blacklisted, and user isn't flagging their own msg...
if (blacklisted.indexOf(user.id) !== -1 || user.id === reaction.message.author.id) {
// Remove user if so.
reaction.remove(user);
} else {
// log the flagged message.
logMessage(reaction.message, {
user: `<@${reaction.message.author.id}>`,
flaggers: reaction.users.array().map(u => `<@${u.id}>`).join(", "),
content: reaction.message.content,
channel: `<#${msgChannelId}>`
});
}
}
switch(reaction.emoji.name) {
case "🗑":
// If user has manage message perms...
if (reaction.message.guild.members.find("id", user.id).hasPermission("MANAGE_MESSAGES") && user.id !== "372013264453894154") {
// and the channel is not any official one...
if (msgChannelId !== "473520957022142484" &&
msgChannelId !== "473521399210835989" &&
msgChannelId !== "479828958498783243" &&
msgChannelId !== "479420816963141690") {
// delete the message!
reaction.message.delete();
} else {
reaction.remove(user);
}
}
break;
// case "📌":
// if (reaction.count >= 6) {