-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeanie.js
8096 lines (7555 loc) · 464 KB
/
meanie.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
// modules and setup information
const Discord = require("discord.js");
const client = new Discord.Client({ autoReconnect: true, disableEveryone: true });
const config = require("./config.json");
const fs = require("fs");
const request = require("request");
const cheerio = require("cheerio");
const urlExists = require("url-exists");
const YTMP3Downloader = require("youtube-mp3-downloader");
const YTValidator = require("youtube-validator");
const getYTID = require("get-youtube-id");
// bot login
client.login(config.token);
// global default channel instantiation
const defaultChannel = guild => {
const channels = guild.channels.cache
.filter(c => c.type === "text" && c.permissionsFor(guild.me).has("SEND_MESSAGES"))
.sort((a, b) => a.createdTimestamp > b.createdTimestamp);
return channels.find(c => c.name.includes("general")) || channels.find(c => c.name.includes("main")) || channels.find(c => c.name.includes("lobby")) || channels.find(c => c.name.includes("genderlel")) || channels.find(c => c.name.includes("crib")) || channels.first();
}
// global function to convert every first letter of a word in a string to uppercase
function eachWordUpper(str) {
let array = str.split(" ");
let newarray = [];
for (let x = 0; x < array.length; x++) {
newarray.push(array[x].charAt(0).toUpperCase() + array[x].slice(1));
}
return newarray.join(" ");
}
// global function for testing to see what is attached to a message, if anything
function extension(attachment) {
const imageLink = attachment.split('.');
const typeOfImage = imageLink[imageLink.length - 1];
const image = /(jpg|jpeg|png|gif)/gi.test(typeOfImage);
if (!image) return '';
return attachment;
}
// configure global YouTube to MP3 downloader object
let YD = new YTMP3Downloader({
"ffmpegPath": "/usr/src/FFmpeg/libavcodec/libmp3lame.c", // Where is the FFmpeg binary located?
"outputPath": "/home/pi/djsbots/lphelper/yt2mp3_files", // Where should the downloaded and encoded files be stored?
"youtubeVideoQuality": "highest", // What video quality should be used?
"queueParallelism": 2, // How many parallel downloads/encodes should be started?
"progressTimeout": 2000 // How long should be the interval of the progress reports
});
// ready event
client.on("ready", () => {
// log that bot has successfully started
console.log("M.E.A.N.I.E. is now online!");
// pick random activity from file and set it as current activity
let activities = JSON.parse(fs.readFileSync("./activities.json"));
let activitiesAsArray = Object.keys(activities);
let randomActivity = activitiesAsArray[Math.floor(Math.random() * activitiesAsArray.length)];
client.user.setActivity(activities[randomActivity].botactivity, { type: activities[randomActivity].activitytype });
// continually set random activity every 30 minutes from here on out
setInterval(function() {
randomActivity = activitiesAsArray[Math.floor(Math.random() * activitiesAsArray.length)];
client.user.setActivity(activities[randomActivity].botactivity, { type: activities[randomActivity].activitytype });
// console.log(`Changed activity to "${activities[randomActivity].botactivity}" with activity type ${activities[randomActivity].activitytype}.`);
}, 1.8e+6);
});
// // user update event
// client.on("userUpdate", (oldUser, newUser) => {
// // update private server icon with new avatar on change
// if (oldUser.id === config.creatorid) {
// let pserver = client.guilds.cache.find(g => g.id === "200458694704627712");
// pserver.setIcon(newUser.displayAvatarURL(), "Vex avatar change occurred.")
// .catch(error => console.error(error));
// }
// });
// joining guild event
client.on("guildCreate", guild => {
const channel = defaultChannel(guild);
console.log(`I have joined a guild by the name of ${guild.name}!`);
channel.send(`M.E.A.N.I.E. has now arrived in **${guild.name}**! It is a pleasure to make your acquaintance. :robot:`).catch(error => console.error(error));
});
// leaving guild event
client.on("guildDelete", guild => {
console.log(`I have left a guild by the name of ${guild.name}!`);
});
// error event
client.on("error", e => console.error(e));
// warn event
client.on("warn", e => console.warn(e));
// debug event
// client.on("debug", e => console.info(e));
// message event
client.on("message", async message => {
// make sure author isn't bot
if (message.author.bot) return;
// check for command messages outside of #bots in Level Palace
// if (message.channel.type !== "dm" && message.channel.type !== "group" && message.guild.id === "325490421419606016" && !message.content.toLowerCase().startsWith("?mute") && !message.content.toLowerCase().startsWith("?unmute") && !message.content.toLowerCase().startsWith("?rank") && !message.content.toLowerCase().startsWith("!feed") && !message.content.toLowerCase().startsWith("-feed") && !message.content.toLowerCase().startsWith("~feed")) {
// let botprefix;
// let botcommand;
// // get prefix
// if (message.content.startsWith("<@127296623779774464>")) botprefix = "<@127296623779774464>";
// else if (message.content.startsWith("+")) botprefix = "+";
// else if (message.content.startsWith("`")) botprefix = "`";
// else if (message.content.startsWith("!")) botprefix = "!";
// else if (message.content.startsWith("-")) botprefix = "-";
// else if (message.content.startsWith("~")) botprefix = "~";
// else if (message.content.startsWith("?")) botprefix = "?";
// else if (message.content.startsWith(".")) botprefix = ".";
// else if (message.content.startsWith("t!")) botprefix = "t!";
// else if (message.content.startsWith("t@")) botprefix = "t@";
// else if (message.content.startsWith("=")) botprefix = "=";
// else if (message.content.startsWith(";;")) botprefix = ";;";
// else if (message.content.startsWith("%")) botprefix = "%";
// if (message.channel.id !== "325492750667612162" && message.channel.id !== "325495534896807936" && message.channel.id !== "325495670502850560" && message.channel.id !== "334144051706331136" && message.channel.id !== "330810124757368832") {
// if (message.content.startsWith("<@127296623779774464>") || message.content.startsWith("+") || message.content.startsWith("`") || message.content.startsWith("!") || message.content.startsWith("-") || message.content.startsWith("~") || message.content.startsWith("?") || message.content.startsWith(".") || message.content.startsWith("t!") || message.content.startsWith("t@") || message.content.startsWith("=") || message.content.startsWith(";;") || message.content.startsWith("%")) {
// botcommand = message.content.slice(botprefix.length);
// // check if the bot command begins with a letter
// function hasFirstLetterOrNumber(c) {
// if (botprefix === "<@127296623779774464>") c = c.trim();
// c = c.substring(0, 1);
// if (c.toLowerCase() !== c.toUpperCase() || /^\d/.test(c)) {
// return true;
// } else {
// return false;
// }
// }
// if (hasFirstLetterOrNumber(botcommand) && !botcommand.includes(botprefix)) {
// message.channel.send("Use other bot commands in <#325492750667612162>.").then(msg => {
// return msg.delete(5000);
// });
// }
// }
// }
// }
// code for "ayy"
if (message.content.toLowerCase() === "ayy" && message.guild.id === "325490421419606016" && message.channel.id === "325492750667612162" || message.content.toLowerCase() === "ayy" && message.guild.id !== "325490421419606016") return message.channel.send("You're not funny.");
// make sure message starts with command prefix or a bot mention from here onwards
if (!message.content.startsWith(config.prefix) && !message.content.startsWith(`<@${client.user.id}>`) && !message.content.startsWith(`<@!${client.user.id}>`)) return;
// respond to message with just a mention
if (message.content === `<@${client.user.id}>` || message.content === `<@!${client.user.id}>`) {
if (message.author.id !== config.creatorid) return message.channel.send(`Why the mention, **${message.author.username}**?`);
else return message.channel.send(`What do you need, master?`);
}
// various variable setup
let command;
let mentionMessage;
let args;
if (message.content.startsWith(config.prefix)) command = message.content.split(" ")[0].slice(config.prefix.length).toLowerCase();
else mentionMessage = message.content.split(" ").slice(1).join(" ").replace(/\s/g, "").toLowerCase();
if (message.content.startsWith(config.prefix)) args = message.content.split(" ").slice(1).join(" ");
// log method setup
function log(cmd) {
if (message.author.id === config.creatorid) return;
let trimmedArgs = args;
let logchannel = client.channels.cache.find(c => c.id === "436702599706705940");
if (message.channel === logchannel) return;
if (args.length > 500) trimmedArgs = args.substring(0, 500).trim() + "...";
if (!args) {
if (message.channel.type === "dm") {
return logchannel.send({ embed: {
color: 3447003,
fields: [
{
name: "Command Used",
value: cmd
},
{
name: "Author",
value: message.author.username
},
{
name: "Used in",
value: "Direct Messages"
}
]
}});
} else if (message.channel.type === "group") {
return logchannel.send({ embed: {
color: 3447003,
fields: [
{
name: "Command Used",
value: cmd
},
{
name: "Author",
value: message.author.username
},
{
name: "Used in",
value: `The ${message.channel.name} Group DM`
}
]
}});
} else {
return logchannel.send({ embed: {
color: 3447003,
fields: [
{
name: "Command Used",
value: cmd
},
{
name: "Author",
value: message.author.username
},
{
name: "Server",
value: message.guild.name
},
{
name: "Channel",
value: `#${message.channel.name}`
}
]
}});
}
} else {
if (message.channel.type === "dm") {
return logchannel.send({ embed: {
color: 3447003,
fields: [
{
name: "Command Used",
value: cmd
},
{
name: "Author",
value: message.author.username
},
{
name: "Used in",
value: "Direct Messages"
},
{
name: "Arguments",
value: trimmedArgs
}
]
}});
} else if (message.channel.type === "group") {
return logchannel.send({ embed: {
color: 3447003,
fields: [
{
name: "Command Used",
value: cmd
},
{
name: "Author",
value: message.author.username
},
{
name: "Used in",
value: `The ${message.channel.name} Group DM`
},
{
name: "Arguments",
value: trimmedArgs
}
]
}});
} else {
return logchannel.send({ embed: {
color: 3447003,
fields: [
{
name: "Command Used",
value: cmd
},
{
name: "Author",
value: message.author.username
},
{
name: "Server",
value: message.guild.name
},
{
name: "Channel",
value: `#${message.channel.name}`
},
{
name: "Arguments",
value: trimmedArgs
}
]
}});
}
}
}
// commands
if (command === "commands" || command === "help" || mentionMessage && mentionMessage.includes("commands") || mentionMessage && mentionMessage.includes("help")) {
log(command);
let pmsg = await message.channel.send("Generating...");
message.author.send({ embed: {
color: 3447003,
description: "A list of all M.E.A.N.I.E.'s commands, (Mario Editor Assistant New Intelligent Edition), a bot created by <@107944323454074880> that helps in automating various Mario editor and Discord actions.\n\n**Want to add me to your server? You can do so with the link below:**\nhttps://discordapp.com/oauth2/authorize?client_id=242866547771703296&scope=bot&permissions=1342185472\n\n***Current Command Prefix: " + config.prefix + "***",
fields: [
{
name: "---------- Basic Bot Commands ----------",
value: "These are very basic commands that pertain to me."
},
{
name: config.prefix + "commands or " + config.prefix + "help",
value: "Gives you this list of my commands."
},
{
name: config.prefix + "say",
value: "A command used to make me say whatever you want."
},
{
name: config.prefix + "invite",
value: "An easy way to get the invite link that is used to add me to your server."
},
{
name: config.prefix + "test or " + config.prefix + "ping",
value: "Tests to see if I'm currently working, and lists different latency statistics."
},
{
name: "---------- LP Site/SMF/SMC Commands ----------",
value: "These commands are used to automate various actions on the Level Palace site, or with Super Mario Flash/Super Mario Construct."
},
// {
// name: config.prefix + "contestresults",
// value: "**TEMPORARY**\nShows results from the latest LP contest!"
// },
{
name: config.prefix + "lpstatus or " + config.prefix + "islpup",
value: "Tests to see if Level Palace is currently up or not."
},
{
name: config.prefix + "user/" + config.prefix + "finduser/" + config.prefix + "member/" + config.prefix + "findmember/" + config.prefix + "profile/" + config.prefix + "findprofile",
value: "Lets you search for an LP user and links you to their profile if found. Also gives various information about them."
},
{
name: config.prefix + "iduser/" + config.prefix + "idfinduser/" + config.prefix + "idmember/" + config.prefix + "idfindmember/" + config.prefix + "idprofile/" + config.prefix + "idfindprofile",
value: "Lets you search for an LP user via ID and links you to their profile if found. Also gives various information about them."
},
// {
// name: config.prefix + "checkir or " + config.prefix + "ir",
// value: "Checks to see if Intensive Rating, (IR), is currently active or not."
// },
{
name: config.prefix + "numpending or " + config.prefix + "pending",
value: "Tells you how many levels are currently in Pending."
},
// {
// name: config.prefix + "ratesleft or " + config.prefix + "votesleft",
// value: "Calculates the remaining number of votes needed in order to clear out all of the levels in Pending."
// },
// {
// name: config.prefix + "levelinfo or " + config.prefix + "pendinginfo",
// value: "Checks the Pending section, and calculates the number of votes needed in order to clear out all of the levels."
// },
{
name: config.prefix + "randompending or " + config.prefix + "randomlevel",
value: "Randomly picks out a level from Pending for you to rate if there are any, and displays various information about it."
},
{
name: config.prefix + "game or " + config.prefix + "lpgame",
value: "Links any valid LP game that you specify."
},
{
name: config.prefix + "level or " + config.prefix + "levelsearch",
value: "Lets you search for an LP level and links you to it if found. Also lists up to 10 other possible matches if there are any, and lets you pick the one you want.\n\n***Note:*** *Due to the nature of this command, it does not find private levels. If you do wish to find a level with this condition, however, use the ID version of this command instead.*"
},
{
name: config.prefix + "idlevel or " + config.prefix + "idlevelsearch",
value: "Lets you search for an LP level via ID and links you to it if found."
},
// {
// name: config.prefix + "mp3 or " + config.prefix + "yt2mp3",
// value: "Converts a passed in YouTube video link or ID into an MP3 for you to use as Super Mario Flash custom music."
// },
{
name: "---------- LP Wiki Commands ----------",
value: "These commands are used to automate various actions on the Level Palace wiki."
},
{
name: config.prefix + "wiki or " + config.prefix + "wikisearch",
value: "Lets you search for any article on the LP wiki and links you to it if found. Also shows up to 500 characters of a page description if one is found. Enter \"random\" as the article name for me to fetch a random article."
},
{
name: "---------- Discord-related Commands ----------",
value: "These commands are used to automate various Discord-related actions."
},
{
name: config.prefix + "color or " + config.prefix + "colour",
value: "Adds a specified color role to you, and removes your previous one, if one exists. To generate a random color role, enter \"random\" as the color, and to remove your current color role, enter \"remove\" as the color.\n\n***Note:*** *This command may not work as intended in your server if you have a lot of colored roles that you assign to users.*"
},
{
name: config.prefix + "clean",
value: "**USER NEEDS MANAGE MESSAGES PERMISSION**\nDeletes specified messages that are sent by me in the current channel of a server."
},
{
name: config.prefix + "clear",
value: "**USER NEEDS MANAGE MESSAGES PERMISSION**\nDeletes specified messages from a channel. Can be specified by either a certain user, a number of messages to delete, or both."
},
{
name: config.prefix + "addemoji",
value: "**USER NEEDS MANAGE EMOJIS PERMISSION**\nAdds an emoji to a server."
},
{
name: config.prefix + "delemoji or " + config.prefix + "rememoji",
value: "**USER NEEDS MANAGE EMOJIS PERMISSION**\nDeletes an emoji from a server based on either a name or ID."
},
{
name: config.prefix + "emojislots or " + config.prefix + "emoteslots/" + config.prefix + "pinslots/" + config.prefix + "roleslots",
value: "Tells you how many emoji, pin, or role slots are remaining in a server, (or DM or Group DM if using " + config.prefix + "emojislots), depending on which command you use."
}
]
}}).then(msg => {
// cover for Discord latency
setTimeout(function() {
console.log(`My command list was sent to ${message.author.username} via Direct Message.`);
if (message.channel.type !== "dm") pmsg.edit("My command list has been sent to you via Direct Message!");
else pmsg.delete();
}, 1000);
}).catch(err => {
console.error(`My command list was failed to be sent to ${message.author.username} via Direct Message.`);
pmsg.edit("**An error occurred while trying to send a Direct Message:**```" + err + "```");
});
}
else if (command === "setprefix" || command === "prefix") {
if (message.author.id !== config.creatorid) {
let denymsg = await message.channel.send("You are not allowed to use this command!");
return denymsg.delete(5000);
}
if (!args) return message.channel.send("You need to include a command prefix!");
if (args.includes(" ")) return message.channel.send("Your command prefix must not include spaces!");
if (args === config.prefix) return message.channel.send("That is already my command prefix!");
args = args.replace(/"/g, '\\"');
args = args.replace(/`/g, '\\`');
message.channel.send(`My command prefix has now been changed to **${args}**!`, { split: true })
.then(function() {
console.log(`My command prefix was changed to "${args}".`);
fs.writeFile("./config.json", `{ "prefix": "${args}", "creatorid": "${config.creatorid}"}`, err => {
if (err) throw err;
});
}).catch(err => {
console.error(`An error occurred while trying to send a message:\n${err}`);
return message.channel.send("**An error occurred while trying to send a message:**```" + err + "```");
});
}
// else if (command === "banplumes") {
// if (message.author.id !== config.creatorid) return;
// message.guild.ban("339467371981045761").catch(console.error);
// message.guild.ban("339542563105144834").catch(console.error);
// message.guild.ban("402903141097537538").catch(console.error);
// message.guild.ban("315189616884056064").catch(console.error);
// message.guild.ban("405764980898791426").catch(console.error);
// message.guild.ban("405772963795828739").catch(console.error);
// message.guild.ban("405775816438579210").catch(console.error);
// message.guild.ban("326983588954505216").catch(console.error);
// message.guild.ban("337021712434462720").catch(console.error);
// message.guild.ban("397958778550747146").catch(console.error);
// message.guild.ban("275023064851546113").catch(console.error);
// message.guild.ban("148564483122528265").catch(console.error);
// message.guild.ban("397145235496370186").catch(console.error);
// message.channel.send("Banned all Plume accounts.");
// }
// else if (command === "unbanplumes") {
// if (message.author.id !== config.creatorid) return;
// message.guild.unban("339467371981045761").catch(console.error);
// message.guild.unban("339542563105144834").catch(console.error);
// message.guild.unban("402903141097537538").catch(console.error);
// message.guild.unban("315189616884056064").catch(console.error);
// message.guild.unban("405764980898791426").catch(console.error);
// message.guild.unban("405772963795828739").catch(console.error);
// message.guild.unban("405775816438579210").catch(console.error);
// message.guild.unban("326983588954505216").catch(console.error);
// message.guild.unban("337021712434462720").catch(console.error);
// message.guild.unban("397958778550747146").catch(console.error);
// message.guild.unban("275023064851546113").catch(console.error);
// message.guild.unban("148564483122528265").catch(console.error);
// message.guild.unban("397145235496370186").catch(console.error);
// message.channel.send("Unbanned all Plume accounts.");
// }
else if (command === "addactivity" || command === "botactivity") {
let activities = JSON.parse(fs.readFileSync("./activities.json"));
let botActivity;
let activityType;
if (!args) return message.channel.send("You need to include an activity with an activity type for me to add!");
if (!args.includes("|")) return message.channel.send("**Usage:**```" + config.prefix + "addactivity/" + config.prefix + "botactivity [Activity for me to add] | [Activity type for me to add] (Either 0, 1, 2, 3, or what they represent)```*Activity type 0 = \"Playing...\"\nActivity type 1 = \"Streaming...\"\nActivity type 2 = \"Listening...\"\nActivity type 3 = \"Watching...\"*");
botActivity = args.split("|")[0].trim();
activityType = args.split("|")[1].replace(/\s/g, "").toLowerCase();
if (message.author.id !== config.creatorid) {
let denymsg = await message.channel.send("You are not allowed to use this command!");
return denymsg.delete(5000);
}
if (!botActivity || !activityType || args.replace(/\s/g, "").toLowerCase() === "usage") return message.channel.send("**Usage:**```" + config.prefix + "addactivity/" + config.prefix + "botactivity [Activity for me to add] | [Activity type for me to add] (Either 0, 1, 2, 3, or what they represent)```*Activity type 0 = \"Playing...\"\nActivity type 1 = \"Streaming...\"\nActivity type 2 = \"Listening...\"\nActivity type 3 = \"Watching...\"*");
if (activityType && !/^0+$/.test(activityType) && parseInt(activityType) !== 1 && parseInt(activityType) !== 2 && parseInt(activityType) !== 3 && activityType !== "playing" && activityType !== "streaming" && activityType !== "listening" && activityType !== "watching") return message.channel.send("The only valid activity types are **PLAYING**, **STREAMING**, **LISTENING**, and **WATCHING**! (**0**, **1**, **2**, and **3**)");
// convert input to valid types
if (activityType === "0" || activityType === "playing") activityType = "PLAYING";
if (activityType === "1" || activityType === "streaming") activityType = "STREAMING";
if (activityType === "2" || activityType === "listening") activityType = "LISTENING";
if (activityType === "3" || activityType === "watching") activityType = "WATCHING";
// check to see if the specified activity along with the same activity type are already added
if (activities[botActivity] && activities[botActivity].activitytype === activityType) return message.channel.send("That activity with that activity type is already added to me!");
args = args.replace(/"/g, '\\"');
args = args.replace(/`/g, '\\`');
if (activities[botActivity] && activities[botActivity].activitytype !== activityType) {
// change activity type of existing activity
message.channel.send(`The activity type of **${botActivity}** has now been changed to **${activityType}!**`, { split: true })
.then(function() {
console.log(`The activity type of "${botActivity}" has been changed to ${activityType}.`);
activities[botActivity] = {
"botactivity" : botActivity,
"activitytype" : activityType
};
fs.writeFile("./activities.json", JSON.stringify(activities), err => {
if (err) console.log(err);
});
}).catch(err => {
console.error(`An error occurred while trying to send a message:\n${err}`);
return message.channel.send("**An error occurred while trying to send a message:**```" + err + "```");
});
} else {
// add activity with activity type
message.channel.send(`The activity **${botActivity}** with activity type **${activityType}** has been added!`, { split: true })
.then(function() {
console.log(`The activity "${botActivity}" with activity type ${activityType} was added.`);
activities[botActivity] = {
"botactivity" : botActivity,
"activitytype" : activityType
};
fs.writeFile("./activities.json", JSON.stringify(activities), err => {
if (err) console.log(err);
});
}).catch(err => {
console.error(`An error occurred while trying to send a message:\n${err}`);
return message.channel.send("**An error occurred while trying to send a message:**```" + err + "```");
});
}
}
else if (command === "delactivity" || command === "remactivity") {
// variable declarations
let activities = JSON.parse(fs.readFileSync("./activities.json"));
let botActivity;
if (!args) return message.channel.send("You need to include an activity for me to remove!");
botActivity = args.trim();
if (message.author.id !== config.creatorid) {
let denymsg = await message.channel.send("You are not allowed to use this command!");
return denymsg.delete(5000);
}
if (args.replace(/\s/g, "").toLowerCase() === "usage") return message.channel.send("**Usage:**```" + config.prefix + "delactivity/" + config.prefix + "remactivity [Activity for me to remove] (Activity type will be obtained automatically)```");
args = args.replace(/"/g, '\\"');
args = args.replace(/`/g, '\\`');
// check to see if the specified activity is added and can be removed
if (!activities[botActivity]) return message.channel.send("That activity is not currently added to me!");
// remove activity
message.channel.send(`The activity **${botActivity}** with activity type **${activities[botActivity].activitytype}** has been removed!`, { split: true })
.then(function() {
console.log(`The activity "${botActivity}" with activity type ${activities[botActivity].activitytype} was removed.`);
delete activities[botActivity];
fs.writeFile("./activities.json", JSON.stringify(activities), err => {
if (err) console.log(err);
});
}).catch(err => {
console.error(`An error occurred while trying to send a message:\n${err}`);
return message.channel.send("**An error occurred while trying to send a message:**```" + err + "```");
});
}
else if (command === "clearpins") {
if (message.author.id !== config.creatorid) {
let denymsg = await message.channel.send("You are not allowed to use this command!");
return denymsg.delete(5000);
}
let channel = client.channels.cache.find(c => c.id === "325490421419606016");
channel.fetchPinnedMessages().then(pins => {
pins.forEach(function (pin) {
pin.unpin().catch(err => {
console.error(`An error occurred while trying to unpin a message:\n${err}`);
message.channel.send("**An error occurred while trying to unpin a message:**```" + err + "```");
});
});
if (message.channel.id !== "325490421419606016") message.channel.send("All pins cleared in <#325490421419606016>!");
channel.send("All the pins are being cleared out to make room for new ones, and will all be unpinned shortly!");
}).catch(err => {
console.error(`An error occurred while trying to fetch pinned messages:\n${err}`);
message.channel.send("**An error occurred while trying to fetch pinned messages:**```" + err + "```");
});
}
// else if (command === "starboard") {
// if (message.channel.type === "dm" || message.channel.type === "group") return;
// if (message.guild.id !== "325490421419606016") return;
// if (message.channel.id === "326576626097979402" || message.channel.id === "325496108467879956" || message.channel.id === "357386246793723905" || message.channel.id === "414852683292213253" || message.channel.id === "468472403199000576" || message.channel.id === "456626411910856706" || message.channel.id === "456626483654557698" || message.channel.id === "455993305067683840" || message.channel.id === "454493943426449408" || message.channel.id === "399778380398198784" || message.channel.id === "392421139089063937" || message.channel.id === "325495534896807936" || message.channel.id === "325495670502850560" || message.channel.id === "334144051706331136" || message.channel.id === "330810124757368832") return message.channel.send("You cannot starboard messages from this channel!");
// if (!message.member.hasPermission("MANAGE_MESSAGES")) {
// return message.channel.send("You need the **Manage Messages** permission in order to use this command!").then(msg => {
// msg.delete(5000);
// // if (message.deletable && message.guild.me.hasPermission("MANAGE_MESSAGES")) message.delete(5000);
// });
// }
// log(command);
// args = args.replace(/\s/g, "").toLowerCase();
// // constant declarations
// const starChannel = client.channels.cache.find(c => c.id === "468472403199000576");
// const fetchedMessages = await starChannel.messages.fetch({ limit: 100 });
// const stars = fetchedMessages.find(m => m.embeds[0] && m.embeds[0].footer.text.startsWith('⭐') && m.embeds[0].footer.text.endsWith(args));
// // if statement checks
// if (!args) return message.channel.send("You must include an ID of a message for me to starboard that is no more than 100 messages older than yours, and that is from this channel!");
// if (args === "usage") return message.channel.send("**Usage:**\n```" + config.prefix + "starboard [ID of message for me to starboard]```\n\n***Note: Your message ID must be of a message that is no more than 100 messages older than yours, and must also be from this channel, due to Discord limitations.***");
// if (isNaN(args)) return message.channel.send("Please enter a numeric message ID!");
// if (args.length < 15 || args.length > 100) return message.channel.send("Please enter a message ID consisting of more than 15 digits, but less than 100 digits!");
// // check to see if the message is already in the starboard or not
// if (stars) {
// console.log(`${message.author.tag} tried to starboard a message that was already starboarded in #${message.channel.name} of ${message.guild.name}.`);
// message.channel.send("That message is already starboarded!");
// } else {
// let starMsg = await message.channel.messages.fetch({ limit: 100 }).catch(err => {
// console.error(`An error occurred while trying to fetch messages in #${message.channel.name} of ${message.guild.name}:\n${err}`);
// return message.channel.send("**An error occurred while trying to fetch messages:**```" + err + "```");
// });
// starMsg = starMsg.find(m => m.id === args);
// if (starMsg) {
// const image = starMsg.attachments.size > 0 ? await extension(starMsg.attachments.array()[0].url) : '';
// if (image === '' && starMsg.cleanContent.length < 1) return;
// await starChannel.send({ embed: {
// color: 0xfdaa30,
// description: starMsg.cleanContent,
// author: {
// name: starMsg.author.tag + ` in #${starMsg.channel.name} (Starboarded by ${message.author.tag})`,
// url: starMsg.url,
// icon_url: starMsg.author.displayAvatarURL()
// },
// timestamp: new Date(),
// footer: {
// text: `⭐ ❌ | ${starMsg.id}`
// },
// image: {
// url: image
// }
// }});
// // .setColor(0xfdaa30)
// // .setDescription(starMsg.cleanContent)
// // .setAuthor(starMsg.author.tag, starMsg.author.displayAvatarURL())
// // .setTimestamp(new Date())
// // .setFooter(`⭐ ❌ | ${starMsg.id}`)
// // .setImage(image);
// // await starChannel.send({ embed });
// console.log(`${message.author.tag} starboarded a message with an ID of ${args} in #${message.channel.name} of ${message.guild.name}.`);
// message.channel.send(`The message with an ID of **${args}** has been starboarded!`);
// } else {
// console.log(`${message.author.tag} tried to starboard a message that didn't exist in #${message.channel.name} of ${message.guild.name}.`);
// message.channel.send("That message either doesn't exist, isn't from this channel, or is more than 100 messages older than yours!");
// }
// }
// }
else if (command === "invite") {
log(command);
if (message.channel.type === "dm") {
console.log(`${message.author.tag} requested my invite link in DMs.`);
} else if (message.channel.type === "group") {
console.log(`${message.author.tag} requested my invite link in the ${message.channel.name} Group DM.`);
} else {
console.log(`${message.author.tag} requested my invite link in #${message.channel.name} of ${message.guild.name}.`);
}
message.channel.send("**Invite me to your server with the link below:**\nhttps://discordapp.com/oauth2/authorize?client_id=242866547771703296&scope=bot&permissions=1342185472");
}
else if (command === "restart") {
if (message.author.id !== config.creatorid) {
let denymsg = await message.channel.send("You are not allowed to use this command!");
return denymsg.delete(5000);
}
let pmsg = await message.channel.send("Restarting...");
client.destroy().then(function() {
client.login().then(token => {
pmsg.edit("Successfully restarted!");
});
});
}
else if (command === "die" || command === "stop" || command === "kill") {
if (message.author.id !== config.creatorid) {
let denymsg = await message.channel.send("You are not allowed to use this command!");
return denymsg.delete(5000);
}
message.channel.send("Until next time! :wave:").then(msg => {
client.destroy();
});
}
else if (command === "test" || command === "ping") {
log(command);
message.channel.send("Test!").then(msg => {
if (message.channel.type === "dm") {
console.log(`I was tested to see if I was online or not by ${message.author.username} in DMs. My latency was ${msg.createdTimestamp - message.createdTimestamp}ms, and my API latency was ${Math.round(client.ping)}ms!`);
} else if (message.channel.type === "group") {
console.log(`I was tested to see if I was online or not by ${message.author.username} in the ${message.channel.name} Group DM. My latency was ${msg.createdTimestamp - message.createdTimestamp}ms, and my API latency was ${Math.round(client.ping)}ms!`);
} else {
console.log(`I was tested to see if I was online or not by ${message.author.username} in #${message.channel.name} of ${message.guild.name}. My latency was ${msg.createdTimestamp - message.createdTimestamp}ms, and my API latency was ${Math.round(client.ping)}ms!`);
}
msg.edit(`__***Stats:***__\n\n**LATENCY:** ${msg.createdTimestamp - message.createdTimestamp}ms.\n**API LATENCY:** ${Math.round(client.ws.ping)}ms.`);
});
}
else if (command === "say") {
if (args === "You are not allowed to use this command!" && message.author.id !== config.creatorid || args === "You are not allowed to use this command here!" && message.author.id !== config.creatorid || args === "You are not aIIowed to use this command here!" && message.author.id !== config.creatorid) return message.channel.send("Stop trying to be funny, even MB has a better sense of humor than you.");
if (message.author.id !== config.creatorid && message.guild && message.guild.id === "325490421419606016") {
let denymsg = await message.channel.send("You are not allowed to use this command here!");
return denymsg.delete(5000);
}
if (!args) return message.channel.send("You must include something for me to say!");
if (args.length > 1500) return message.channel.send("Please enter a message consisting of 1500 characters or less!");
log(command);
message.channel.send(args, { split: true }).then(msg => {
if (message.channel.type === "dm") {
console.log(`I said "${args}" to ${message.author.username} in DMs.`);
} else if (message.channel.type === "group") {
console.log(`I said "${args}" to ${message.author.username} in the ${message.channel.name} Group DM.`);
} else {
console.log(`I said "${args}" to ${message.author.username} in #${message.channel.name} of ${message.guild.name}.`);
}
}).catch(err => {
console.error(`An error occurred while trying to send a message:\n${err}`);
return message.channel.send("**An error occurred while trying to send a message:**```" + err + "```");
});
}
else if (command === "gensay") {
if (message.author.id !== config.creatorid) return;
if (!args) return message.channel.send("You must include something for me to say in <#325490421419606016>!");
let channel = client.channels.cache.find(c => c.id === "325490421419606016");
channel.send(args);
}
else if (command === "setavatar" || command === "setpfp") {
if (message.author.id !== config.creatorid) return;
if (!args) return message.channel.send("You must include an avatar link!");
args = args.replace(/\s/g, "");
if (!args.toLowerCase().endsWith(".png") && !args.toLowerCase().endsWith(".gif") && !args.toLowerCase().endsWith(".jpg") && !args.toLowerCase().endsWith(".jpeg") && !args.toLowerCase().endsWith(".tiff")) return message.channel.send("That is not a valid image link!");
let pmsg = await message.channel.send("Changing avatar...");
urlExists(args, function(err, exists) {
if (!err) {
if (exists) {
client.user.setAvatar(args).then(user => {
pmsg.edit("Avatar set!");
}).catch(err => {
pmsg.edit("**An error occurred while trying to set my avatar:**```" + err + "```");
});
} else {
pmsg.edit("The URL specified is not a valid image!");
}
} else {
pmsg.edit("An error occurred while trying to verify whether or not your image link was valid. Please try again.");
}
});
}
else if (command === "setusername" || command === "setname") {
if (message.author.id !== config.creatorid) return;
if (!args) return message.channel.send("You must include a username!");
let pmsg = await message.channel.send("Changing username...");
client.user.setUsername(args).then(user => {
pmsg.edit(`Username set to **${user.username}**!`);
}).catch(err => {
pmsg.edit("**An error occurred while trying to set my username:**```" + err + "```");
});
}
// else if (command === "contestresults") {
// console.log(`I have sent the 2nd Annual LP Contest Results to ${message.author.username}!`);
// message.channel.send("__**2nd Annual LP Contest Results:**__\n\n**#1:** Popthatcorn14 | 95%\n**#2:** TheBlackKoopa232 | 91.6%\n**#3:** LazorCozmic5 | 91.3%\n**#4:** creator | 91%\n**#5:** Luigibonus | 84.6%\n**#6:** Mario Blight | 84%\n**#7:** 1 Up Shroom | 83.3%\n**#8:** Ubfunkeys7 | 83%\n**#9:** ElectricPenguin | 81.7%\n**#10:** Parbounli | 78.3%\n**#11:** Leer201 | 78.3%\n**#12:** Laser | 72.3%\n**#13:** Mario00000000 | 70.7%\n**#14:** Blue Meowstic | 69.3%\n**#15:** Q22 | 68.3%\n**#16:** PrzemekXD | 67%\n**#17:** Softendo | 53.3%\n**#18:** tranvucam | 50.3%\n**#19:** Nathan nathan | 49.7%\n**#20:** Ernesdo | 48.7%\n**#21:** Filip Underwood | 43.3%\n**#22:** cyanide4376 | 36.6%\n**#23:** BusteRalph | 23.3%\n**#24:** Waluigi68 | 20.3%\n**#25:** Nitrogamer | 18.6%\n**#26:** ForeverAlone | 7.6%\n**#27:** Plume 4.0 | 1%");
// }
else if (command === "islpup" || command === "lpstatus") {
if (message.guild && message.guild.id === "752287527473381419") return;
log(command);
let pmsg = await message.channel.send("Checking LP's status...");
// check LP's current status
request({ uri: "https://www.levelpalace.com/", timeout: 10000, time: true, headers: { "User-Agent": "lp-helper" } }, function(err, resp, body) {
if (!err && resp.statusCode === 200) {
let $ = cheerio.load(body);
if ($("div.navbar-fixed").length > 0) {
if (message.channel.type === "dm") {
console.log(`Level Palace was reported as being up by ${message.author.username} in DMs.`);
} else if (message.channel.type === "group") {
console.log(`Level Palace was reported as being up by ${message.author.username} in the ${message.channel.name} Group DM.`);
} else {
console.log(`Level Palace was reported as being up by ${message.author.username} in #${message.channel.name} of ${message.guild.name}.`);
}
pmsg.edit(`Level Palace is currently **up**, with a response time of **${resp.elapsedTime}ms**.`);
} else {
if (message.channel.type === "dm") {
console.log(`Level Palace was reported as being down by ${message.author.username} in DMs.`);
} else if (message.channel.type === "group") {
console.log(`Level Palace was reported as being down by ${message.author.username} in the ${message.channel.name} Group DM.`);
} else {
console.log(`Level Palace was reported as being down by ${message.author.username} in #${message.channel.name} of ${message.guild.name}.`);
}
pmsg.edit("Level Palace is currently **down**.");
}
} else {
if (message.channel.type === "dm") {
console.log(`Level Palace was reported as being down by ${message.author.username} in DMs.`);
} else if (message.channel.type === "group") {
console.log(`Level Palace was reported as being down by ${message.author.username} in the ${message.channel.name} Group DM.`);
} else {
console.log(`Level Palace was reported as being down by ${message.author.username} in #${message.channel.name} of ${message.guild.name}.`);
}
pmsg.edit("Level Palace is currently **down**.");
}
});
}
else if (command === "user" || command === "finduser" || command === "member" || command === "findmember" || command === "profile" || command === "findprofile") {
// if (message.author.id !== config.creatorid) return message.channel.send("Under construction, please wait.");
if (message.guild && message.guild.id === "752287527473381419") return;
if (!args) return message.channel.send("You must include a user to find!");
if (args.length > 100) return message.channel.send("Please enter a username consisting of 100 characters or less!");
args = args.replace(/"/g, '\\"');
args = args.replace(/`/g, '\\`');
let userName = encodeURIComponent(args.trim());
let userinfo = [];
log(command);
let pmsg = await message.channel.send("Finding user...");
// search for user(s) on members page
request({ uri: `https://www.levelpalace.com/profile?user=${userName}`, timeout: 10000, headers: { "User-Agent": "lp-helper" } }, function(err, resp, body) {
if (!err && resp.statusCode === 200) {
let $ = cheerio.load(body);
if ($("div.navbar-fixed").length === 0) return pmsg.edit("Level Palace is currently **down**, and so this command will not work properly right now. Please try again later!");
// let userlinks = [];
// let names = [];
// gather up to 10 members from the member search page
// if ($("td:contains('No members found.')").length === 0) {
// $("tr", "div.table-container").each(function() {
// if ($(this).find("td").length > 0) {
// if (names.length <= 9) {
// let profilelink = $(this).find("td").find("a[href*='profile']").attr("href");
// userlinks.push(profilelink);
// let name = $(this).find("td").find("a").text().trim();
// names.push(name);
// }
// }
// });
// }
// run certain code based on how many members were found on the members page
// if (names.length === 0) {
// if (message.channel.type === "dm") {
// console.log(`A user by the name of "${args.trim()}" was failed to be found by ${message.author.username} in DMs.`);
// } else if (message.channel.type === "group") {
// console.log(`A user by the name of "${args.trim()}" was failed to be found by ${message.author.username} in the ${message.channel.name} Group DM.`);
// } else {
// console.log(`A user by the name of "${args.trim()}" was failed to be found by ${message.author.username} in #${message.channel.name} of ${message.guild.name}.`);
// }
// pmsg.edit(`No LP user was found with the name: **${args.trim()}**! Please try again.`).catch(err => {
// pmsg.edit("**An error occurred while trying to edit this message:**```" + err + "```");
// });
// } else if (names.length === 1) {
// request({ uri: `https://www.levelpalace.com/profile?user=${userName}`, timeout: 10000, headers: { "User-Agent": "lp-helper" } }, function(err, resp, body) {
// if (!err && resp.statusCode === 200) {
// let $ = cheerio.load(body);
// if ($("div.navbar-fixed").length === 0) return pmsg.edit("Level Palace is currently **down**, and so this command will not work properly right now. Please try again later!");
if ($("div.page-banner").length > 0) {
$(".card-title", ".profile-banner").each(function() {
let stat = $(this).text().trim() || $("img.tooltipped").attr("alt").toLowerCase();
userinfo.push(stat);
});
$(".subtitle", ".profile-banner").each(function() {
let status = $(this).text().trim();
userinfo.push(status);
});
$("a[href*='rates?user_id=']", ".profile-banner").each(function() {
let link = $(this).attr("href").substring(14);
userinfo.push(link);
});
$("div", ".profile-user-icon").each(function() {
let avatar = $(this).attr("style").trim().split(")")[0].slice(22);
if (avatar.startsWith("files") || avatar.startsWith("images")) avatar = "https://www.levelpalace.com/" + avatar;
urlExists(avatar, function(err, exists) {
if (!err) {
if (!exists) {
avatar = "https://i.imgur.com/2E8BWdV.png";
}
} else {
avatar = "https://i.imgur.com/2E8BWdV.png";
}
});
userinfo.push(avatar);
});
if (message.channel.type === "dm") {
console.log(`A user by the name of "${args.trim()}" was found by ${message.author.username} in DMs.`);
} else if (message.channel.type === "group") {
console.log(`A user by the name of "${args.trim()}" was found by ${message.author.username} in the ${message.channel.name} Group DM.`);
} else {
console.log(`A user by the name of "${args.trim()}" was found by ${message.author.username} in #${message.channel.name} of ${message.guild.name}.`);
}
if (userinfo[6] === "NOW") {
if (userinfo[5] === "?") {
pmsg.edit({ content: "Here is the user I found:", embed: {
color: 3447003,
thumbnail: {
url: userinfo[userinfo.length - 1]
},
fields: [
{
name: "Username",
value: userinfo[0],
inline: true
},