This repository has been archived by the owner on Jun 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
/
index.js
1614 lines (1525 loc) · 87.8 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
const ytdl = require('ytdl-core');
const {YTSearcher} = require('ytsearcher');
const ytpl = require('ytpl');
const Discord = require('discord.js');
const PACKAGE = require('./package.json');
exports.start = (client, options) => {
try {
if (process.version.slice(1).split('.')[0] < 8) console.error(new Error(`[MusicBot] node v8 or higher is needed, please update`));
function moduleAvailable(name) {
try {
require.resolve(name);
return true;
} catch(e){}
return false;
};
if (moduleAvailable("ffmpeg-binaries")) console.error(new Error("[MUSIC] ffmpeg-binaries was found, this will likely cause problems"));
if (!moduleAvailable("ytdl-core") || !moduleAvailable("ytpl") || !moduleAvailable("ytsearcher")) console.error(new Error("[MUSIC] one or more youtube specific modules not found, this module will not work"));
class Music {
constructor(client, options) {
// Data Objects
this.commands = new Map();
this.commandsArray = [];
this.aliases = new Map();
this.queues = new Map();
this.client = client;
// Play Command options
this.play = {
enabled: (options.play == undefined ? true : (options.play && typeof options.play.enabled !== 'undefined' ? options.play && options.play.enabled : true)),
run: "playFunction",
alt: (options && options.play && options.play.alt) || [],
help: (options && options.play && options.play.help) || "Queue a song/playlist by URL or name.",
name: (options && options.play && options.play.name) || "play",
usage: (options && options.play && options.play.usage) || null,
exclude: Boolean((options && options.play && options.play.exclude)),
masked: "play"
};
// Help Command options
this.help = {
enabled: (options.help == undefined ? true : (options.help && typeof options.help.enabled !== 'undefined' ? options.help && options.help.enabled : true)),
run: "helpFunction",
alt: (options && options.help && options.help.alt) || [],
help: (options && options.help && options.help.help) || "Help for commands.",
name: (options && options.help && options.help.name) || "help",
usage: (options && options.help && options.help.usage) || null,
exclude: Boolean((options && options.help && options.help.exclude)),
masked: "help"
};
// Pause Command options
this.pause = {
enabled: (options.pause == undefined ? true : (options.pause && typeof options.pause.enabled !== 'undefined' ? options.pause && options.pause.enabled : true)),
run: "pauseFunction",
alt: (options && options.pause && options.pause.alt) || [],
help: (options && options.pause && options.pause.help) || "Pauses playing music.",
name: (options && options.pause && options.pause.name) || "pause",
usage: (options && options.pause && options.pause.usage) || null,
exclude: Boolean((options && options.pause && options.pause.exclude)),
masked: "pause"
};
// Resume Command options
this.resume = {
enabled: (options.resume == undefined ? true : (options.resume && typeof options.resume.enabled !== 'undefined' ? options.resume && options.resume.enabled : true)),
run: "resumeFunction",
alt: (options && options.resume && options.resume.alt) || [],
help: (options && options.resume && options.resume.help) || "Resumes a paused queue.",
name: (options && options.resume && options.resume.name) || "resume",
usage: (options && options.resume && options.resume.usage) || null,
exclude: Boolean((options && options.resume && options.resume.exclude)),
masked: "resume"
};
// Leave Command options
this.leave = {
enabled: (options.leave == undefined ? true : (options.leave && typeof options.leave.enabled !== 'undefined' ? options.leave && options.leave.enabled : true)),
run: "leaveFunction",
alt: (options && options.leave && options.leave.alt) || [],
help: (options && options.leave && options.leave.help) || "Leaves the voice channel.",
name: (options && options.leave && options.leave.name) || "leave",
usage: (options && options.leave && options.leave.usage) || null,
exclude: Boolean((options && options.leave && options.leave.exclude)),
masked: "leave"
};
// Queue Command options
this.queue = {
enabled: (options.queue == undefined ? true : (options.queue && typeof options.queue.enabled !== 'undefined' ? options.queue && options.queue.enabled : true)),
run: "queueFunction",
alt: (options && options.queue && options.queue.alt) || [],
help: (options && options.queue && options.queue.help) || "View the current queue.",
name: (options && options.queue && options.queue.name) || "queue",
usage: (options && options.queue && options.queue.usage) || null,
exclude: Boolean((options && options.queue && options.queue.exclude)),
masked: "queue"
};
// Nowplaying Command options
this.np = {
enabled: (options.np == undefined ? true : (options.np && typeof options.np.enabled !== 'undefined' ? options.np && options.np.enabled : true)),
run: "npFunction",
alt: (options && options.np && options.np.alt) || [],
help: (options && options.np && options.np.help) || "Shows the now playing text.",
name: (options && options.np && options.np.name) || "np",
usage: (options && options.np && options.np.usage) || null,
exclude: Boolean((options && options.np && options.np.exclude)),
masked: "np"
};
// Loop Command options
this.loop = {
enabled: (options.loop == undefined ? true : (options.loop && typeof options.loop.enabled !== 'undefined' ? options.loop && options.loop.enabled : true)),
run: "loopFunction",
alt: (options && options.loop && options.loop.alt) || [],
help: (options && options.loop && options.loop.help) || "Sets the loop state for the queue.",
name: (options && options.loop && options.loop.name) || "loop",
usage: (options && options.loop && options.loop.usage) || null,
exclude: Boolean((options && options.loop && options.loop.exclude)),
masked: "loop"
};
// Search Command options
this.search = {
enabled: (options.search == undefined ? true : (options.search && typeof options.search.enabled !== 'undefined' ? options.search && options.search.enabled : true)),
run: "searchFunction",
alt: (options && options.search && options.search.alt) || [],
help: (options && options.search && options.search.help) || "Searchs for up to 10 videos from YouTube.",
name: (options && options.search && options.search.name) || "search",
usage: (options && options.search && options.search.usage) || null,
exclude: Boolean((options && options.search && options.search.exclude)),
masked: "search"
};
// Clear Command options
this.clearqueue = {
enabled: (options.clearqueue == undefined ? true : (options.clearqueue && typeof options.clearqueue.enabled !== 'undefined' ? options.clearqueue && options.clearqueue.enabled : true)),
run: "clearFunction",
alt: (options && options.clear && options.clear.alt) || [],
help: (options && options.clear && options.clear.help) || "Clears the entire queue.",
name: (options && options.clear && options.clear.name) || "clear",
usage: (options && options.clear && options.clear.usage) || null,
exclude: Boolean((options && options.clearqueue && options.clearqueue.exclude)),
masked: "clearqueue"
};
// Volume Command options
this.volume = {
enabled: (options.volume == undefined ? true : (options.volume && typeof options.volume.enabled !== 'undefined' ? options.volume && options.volume.enabled : true)),
run: "volumeFunction",
alt: (options && options.volume && options.volume.alt) || [],
help: (options && options.volume && options.volume.help) || "Changes the volume output of the bot.",
name: (options && options.volume && options.volume.name) || "volume",
usage: (options && options.volume && options.volume.usage) || null,
exclude: Boolean((options && options.volume && options.volume.exclude)),
masked: "volume"
};
this.remove = {
enabled: (options.remove == undefined ? true : (options.remove && typeof options.remove.enabled !== 'undefined' ? options.remove && options.remove.enabled : true)),
run: "removeFunction",
alt: (options && options.remove && options.remove.alt) || [],
help: (options && options.remove && options.remove.help) || "Remove a song from the queue by position in the queue.",
name: (options && options.remove && options.remove.name) || "remove",
usage: (options && options.remove && options.remove.usage) || "{{prefix}}remove [position]",
exclude: Boolean((options && options.remove && options.remove.exclude)),
masked: "remove"
};
// Skip Command options
this.skip = {
enabled: (options.skip == undefined ? true : (options.skip && typeof options.skip.enabled !== 'undefined' ? options.skip && options.skip.enabled : true)),
run: "skipFunction",
alt: (options && options.skip && options.skip.alt) || [],
help: (options && options.skip && options.skip.help) || "Skip a song or songs with `skip [number]`",
name: (options && options.skip && options.skip.name) || "skip",
usage: (options && options.skip && options.skip.usage) || null,
exclude: Boolean((options && options.skip && options.skip.exclude)),
masked: "skip"
};
this.shuffle = {
enabled: (options.shuffle == undefined ? true : (options.shuffle && typeof options.shuffle.enabled !== 'undefined' ? options.shuffle && options.shuffle.enabled : true)),
run: "shuffleFunction",
alt: (options && options.shuffle && options.shuffle.alt) || [],
help: (options && options.shuffle && options.shuffle.help) || "Shuffle the queue",
name: (options && options.shuffle && options.shuffle.name) || "shuffle",
usage: (options && options.shuffle && options.shuffle.usage) || null,
exclude: Boolean((options && options.shuffle && options.shuffle.exclude)),
masked: "shuffle"
};
this.deleteQueue = {
enabled: (options.deleteQueue == undefined ? true : (options.deleteQueue && typeof options.deleteQueue.enabled !== 'undefined' ? options.deleteQueue && options.deleteQueue.enabled : true)),
run: "deleteQueueFunction",
alt: (options && options.deleteQueue && options.deleteQueue.alt) || [],
help: (options && options.deleteQueue && options.deleteQueue.help) || "Delete and re-make an ongoing queue",
name: (options && options.deleteQueue && options.deleteQueue.name) || "deletequeue",
usage: (options && options.deleteQueue && options.deleteQueue.usage) || null,
exclude: Boolean((options && options.deleteQueue && options.deleteQueue.exclude)),
masked: "deletequeue"
};
this.embedColor = (options && options.embedColor) || 'GREEN';
this.anyoneCanSkip = (options && typeof options.anyoneCanSkip !== 'undefined' ? options && options.anyoneCanSkip : false);
this.anyoneCanLeave = (options && typeof options.anyoneCanLeave !== 'undefined' ? options && options.anyoneCanLeave : false);
this.djRole = (options && options.djRole) || "DJ";
this.anyoneCanPause = (options && typeof options.anyoneCanPause !== 'undefined' ? options && options.anyoneCanPause : false);
this.anyoneCanAdjust = (options && typeof options.anyoneCanAdjust !== 'undefined' ? options && options.anyoneCanAdjust : false);
this.youtubeKey = (options && options.youtubeKey);
this.botPrefix = (options && options.botPrefix) || "!";
this.defVolume = (options && options.defVolume) || 50;
if (options.maxQueueSize === 0) {
this.maxQueueSize = 0;
} else {
this.maxQueueSize = (options && options.maxQueueSize) || 50;
}
this.ownerOverMember = (options && typeof options.ownerOverMember !== 'undefined' ? options && options.ownerOverMember : false);
this.botAdmins = (options && options.botAdmins) || [];
this.ownerID = (options && options.ownerID);
this.logging = (options && typeof options.logging !== 'undefined' ? options && options.logging : true);
this.requesterName = (options && typeof options.requesterName !== 'undefined' ? options && options.requesterName : true);
this.inlineEmbeds = (options && typeof options.inlineEmbeds !== 'undefined' ? options && options.inlineEmbeds : false);
this.clearOnLeave = (options && typeof options.clearOnLeave !== 'undefined' ? options && options.clearOnLeave : true);
this.messageHelp = (options && typeof options.messageHelp !== 'undefined' ? options && options.messageHelp : false);
this.dateLocal = (options && options.dateLocal) || 'en-US';
this.bigPicture = (options && typeof options.bigPicture !== 'undefined' ? options && options.bigPicture : false);
this.messageNewSong = (options && typeof options.messageNewSong !== 'undefined' ? options && options.messageNewSong : true);
this.insertMusic = (options && typeof options.insertMusic !== 'undefined' ? options && options.insertMusic : false);
this.defaultPrefix = (options && options.defaultPrefix) || "!";
this.channelWhitelist = (options && options.channelWhitelist) || [];
this.channelBlacklist = (options && options.channelBlacklist) || [];
this.minShuffle = (options && options.shuffle) || 3;
this.bitRate = (options && options.bitRate) || "120000";
this.userSearching = new Map();
// Cooldown Settings
this.cooldown = {
enabled: (options && options.cooldown ? options && options.cooldown.enabled : true),
timer: parseInt((options && options.cooldown && options.cooldown.timer) || 10000),
exclude: (options && options.cooldown && options.cooldown.exclude) || ["volume","queue","pause","resume","np"]
};
this.musicPresence = options.musicPresence || false;
this.clearPresence = options.clearPresence || false;
this.nextPresence = (options && options.nextPresence) || null;
this.recentTalk = new Set();
}
checkVoice(mem, bot) {
return new Promise((resolve, reject) => {
if (!mem || !bot) reject("invalid args");
if (!mem.voice.channel) reject("You're not in a voice channel!");
if (bot.voice.channel) {
if (bot.voice.channel.id == mem.voice.channel.id) resolve(mem.voice.channel)
else reject("You're in a different voice channel!")
} else {
resolve(mem.voice.channel);
};
});
};
async updatePositions(obj, server) {
return new Promise((resolve, reject) => {
if (!server) reject("stage 0: no server passed for @updatePositions");
if (!obj) resolve(this.getQueue(server));
if (obj.working == true) reject("The queue is already performing a task!");
if (server != "000000") {
obj.working = true;
this.queues.set(server, obj);
}
try {
var songs = typeof obj == "object" ? Array.from(obj.songs) : [];
} catch (e) {
console.log("aidjbasiubd");
};
try {
if (!songs || songs.length <= 0 || typeof obj.songs != "object") {
if (this.debug) console.log("[MUSICBOT] @updatePositions: songs object was invalid, reseting queue for "+ obj.id);
this.queues.set(obj.id, {songs: [], last: obj.last ? obj.last : null, loop: obj.loop ? obj.loop : "none", id: obj.id, volume: this.defVolume, oldSongs: [],working: false, needsRefresh: false})
resolve([])
}
let mm = 0;
var newsongs = [];
songs.forEach(s => {
try {
// console.log(s);
if (!s) return;
if (s.position !== mm) s.position = mm;
newsongs.push(s);
mm++;
} catch (e) {
console.log(e);
};
});
} catch (e) {
console.log(e);
if (server != "000000") {
obj.working = false;
this.queues.set(server, obj);
}
reject("stage 1: @updatePositions " + e)
};
obj.songs = newsongs;
obj.last.position = 0;
if (server != "000000") {
obj.working = false;
this.queues.set(server, obj);
}
setTimeout(() => {
resolve(obj);
}, 2000)
});
};
isAdmin(member) {
if (member.roles.find(r => r.name == this.djRole)) return true;
if (this.ownerOverMember && member.id === this.botOwner) return true;
if (this.botAdmins.includes(member.id)) return true;
return member.hasPermission("ADMINISTRATOR");
};
canSkip(member, queue) {
if (this.anyoneCanSkip) return true;
else if (this.botAdmins.includes(member.id)) return true;
else if (this.ownerOverMember && member.id === this.botOwner) return true;
else if (queue.last.requester === member.id) return true;
else if (this.isAdmin(member)) return true;
else return false;
};
canAdjust(member, queue) {
if (this.anyoneCanAdjust) return true;
else if (this.botAdmins.includes(member.id)) return true;
else if (this.ownerOverMember && member.id === this.botOwner) return true;
else if (queue.last.requester === member.id) return true;
else if (this.isAdmin(member)) return true;
else return false;
};
getQueue(server) {
if (!this.queues.has(server)) {
this.queues.set(server, {songs: [], last: null, loop: "none", id: server,volume: this.defVolume, oldSongs: [],working: false, needsRefresh: false});
};
return this.queues.get(server);
};
setLast(server, last) {
return new Promise((resolve, reject) => {
if (this.queues.has(server)) {
let q = this.queues.get(server);
q.last = last;
this.queues.set(server, q);
resolve(this.queues.get(server));
} else {
reject("no server queue");
};
});
};
emptyQueue(server) {
return new Promise((resolve, reject) => {
if (!server || typeof server != "string") reject("no server id passed or passed obj was no a string @emptyQueue")
this.queues.set(server, {songs: [], last: null, loop: "none", id: server, volume: this.defVolume, oldSongs: [],working: false, needsRefresh: false});
resolve(this.queues.get(server));
});
};
async updatePresence(queue, client, clear) {
return new Promise((resolve, reject) => {
if (this.nextPresence !== null) clear = false;
if (!queue || !client) reject("invalid arguments");
if (queue.songs.length > 0 && queue.last) {
client.user.setPresence({
game: {
name: "🎵 | " + queue.last.title,
type: 'PLAYING'
}
});
resolve(client.user.presence);
} else {
if (clear) {
client.user.setPresence({ game: { name: null} });
resolve(client.user.presence);
} else {
if (this.nextPresence !== null) {
let props;
if (this.nextPresence.status && ["online","dnd","idle","invisible"].includes(this.nextPresence.status)) props.status = this.nextPresence.status;
if (this.nextPresence.afk && typeof this.nextPresence.afk == "boolean") props.afk = this.nextPresence.afk;
if (this.nextPresence.game && typeof this.nextPresence.game == "string") props.game = {name: this.nextPresence.game}
else if (this.nextPresence.game && typeof this.nextPresence.game == "object") props.game = this.nextPresence.game;
client.user.setPresence(props).catch((res) => {
console.error("[MUSICBOT] Could not update presence\n" + res);
client.user.setPresence({ game: { name: null} });
resolve(client.user.presence);
}).then((res) => {
resolve(res);
});
} else {
client.user.setPresence({
game: {
name: "🎵 | nothing",
type: 'PLAYING'
}
});
}
resolve(client.user.presence);
};
};
});
};
updatePrefix(server, prefix) {
if (typeof prefix == undefined) prefix = this.defaultPrefix;
if (typeof this.botPrefix != "object") this.botPrefix = new Map();
this.botPrefix.set(server, {prefix: prefix});
};
};
var musicbot = new Music(client, options);
if (musicbot.insertMusic == true) client.music = musicbot;
else exports.bot = musicbot;
musicbot.searcher = new YTSearcher(musicbot.youtubeKey);
musicbot.changeKey = (key) => {
return new Promise((resolve, reject) => {
if (!key || typeof key !== "string") reject("key must be a string");
musicbot.youtubeKey = key;
musicbot.searcher.key = key;
resolve(musicbot);
});
};
client.on("ready", () => {
console.log(`------- Music Bot -------\n> Version: ${PACKAGE.version}\n> Extra Logging: ${musicbot.logging}.\n> Node.js Version: ${process.version}\n------- Music Bot -------`);
if (musicbot.cooldown.exclude.includes("skip")) console.warn(`[MUSIC] Excluding SKIP CMD from cooldowns can cause issues.`);
if (musicbot.cooldown.exclude.includes("remove")) console.warn(`[MUSIC] Excluding REMOVE CMD from cooldowns can cause issues.`);
setTimeout(() => { if (musicbot.musicPresence == true && musicbot.client.guilds.length > 1) console.warn(`[MUSIC] MusicPresence is enabled with more than one server!`); }, 2000);
});
client.on("message", (msg) => {
if (msg.author.bot || musicbot.channelBlacklist.includes(msg.channel.id)) return;
if (musicbot.channelWhitelist.length > 0 && !musicbot.channelWhitelist.includes(msg.channel.id)) return;
const message = msg.content.trim();
const prefix = typeof musicbot.botPrefix == "object" ? (musicbot.botPrefix.has(msg.guild.id) ? musicbot.botPrefix.get(msg.guild.id).prefix : musicbot.defaultPrefix) : musicbot.botPrefix;
const command = message.substring(prefix.length).split(/[ \n]/)[0].trim();
const suffix = message.substring(prefix.length + command.length).trim();
const args = message.slice(prefix.length + command.length).trim().split(/ +/g);
if (message.startsWith(prefix) && msg.channel.type == "text") {
if (musicbot.commands.has(command)) {
let tCmd = musicbot.commands.get(command);
if (tCmd.enabled) {
if (!musicbot.cooldown.enabled == true && !musicbot.cooldown.exclude.includes(tCmd.masked)) {
if (musicbot.recentTalk.has(msg.author.id)) {
if (musicbot.cooldown.enabled == true && !musicbot.cooldown.exclude.includes(tCmd.masked)) return msg.channel.send(musicbot.note("fail", "You must wait to use music commands again."));
}
musicbot.recentTalk.add(msg.author.id);
setTimeout(() => { musicbot.recentTalk.delete(msg.author.id) }, musicbot.cooldown.timer);
}
return musicbot[tCmd.run](msg, suffix, args);
}
} else if (musicbot.aliases.has(command)) {
let aCmd = musicbot.aliases.get(command);
if (aCmd.enabled) {
if (!musicbot.cooldown.enabled == true && !musicbot.cooldown.exclude.includes(aCmd.masked)) {
if (musicbot.recentTalk.has(msg.author.id)) {
if (musicbot.cooldown.enabled == true && !musicbot.cooldown.exclude.includes(aCmd.masked)) return msg.channel.send(musicbot.note("fail", "You must wait to use music commands again."));
}
musicbot.recentTalk.add(msg.author.id);
setTimeout(() => { musicbot.recentTalk.delete(msg.author.id) }, musicbot.cooldown.timer);
}
return musicbot[aCmd.run](msg, suffix, args);
}
};
};
});
musicbot.playFunction = (msg, suffix, args, ignore) => {
if (msg.member.voice.channel === undefined) return msg.channel.send(musicbot.note('fail', `You're not in a voice channel.`));
if (!suffix) return msg.channel.send(musicbot.note('fail', 'No video specified!'));
let q = musicbot.getQueue(msg.guild.id);
let vc = client.voice.connections.find(val => val.channel.guild.id == msg.member.guild.id)
if (vc && vc.channel.id != msg.member.voice.channel.id) return msg.channel.send(musicbot.note('fail', `You must be in the same voice channel as me.`));
if (q.songs.length >= musicbot.maxQueueSize && musicbot.maxQueueSize !== 0) return msg.channel.send(musicbot.note('fail', 'Maximum queue size reached!'));
var searchstring = suffix.trim();
if (searchstring.includes("https://youtu.be/") || searchstring.includes("https://www.youtube.com/") && searchstring.includes("&")) searchstring = searchstring.split("&")[0];
if (searchstring.startsWith('http') && searchstring.includes("list=")) {
msg.channel.send(musicbot.note("search", `Searching playlist items~`));
var playid = searchstring.toString()
.split('list=')[1];
if (playid.toString()
.includes('?')) playid = playid.split('?')[0];
if (playid.toString()
.includes('&t=')) playid = playid.split('&t=')[0];
ytpl(playid, {limit: musicbot.maxQueueSize}, function(err, playlist) {
if(err) return msg.channel.send(musicbot.note('fail', `Something went wrong fetching that playlist!`));
if (playlist.items.length <= 0) return msg.channel.send(musicbot.note('fail', `Couldn't get any videos from that playlist.`));
if (playlist.total_items >= musicbot.maxQueueSize && musicbot.maxQueueSize != 0) return msg.channel.send(musicbot.note('fail', `Too many videos to queue. A maximum of ` + musicbot.maxQueueSize + ` is allowed.`));
var index = 0;
var ran = 0;
var queue = musicbot.getQueue(msg.guild.id);
playlist.items.forEach(async (video) => {
ran++;
if (queue.songs.length == (musicbot.maxQueueSize + 1) && musicbot.maxQueueSize !== 0 || !video) return;
video.url = video.url_simple ? video.url_simple : `https://www.youtube.com/watch?v=` + video.id;
musicbot.playFunction(msg, video.url, [], true);
index++;
if (ran >= playlist.items.length) {
console.log(queue);
if (queue.songs.length >= 1) musicbot.executeQueue(msg, queue);
if (index == 0) msg.channel.send(musicbot.note('fail', `Coudln't get any songs from that playlist!`))
else if (index == 1) msg.channel.send(musicbot.note('note', `Queued one song.`));
else if (index > 1) msg.channel.send(musicbot.note('note', `Queued ${index} songs.`));
}
});
});
} else {
if (!ignore) msg.channel.send(musicbot.note("search", `\`Searching: ${searchstring}\`~`));
new Promise(async (resolve, reject) => {
let result = await musicbot.searcher.search(searchstring, { type: 'video' }).catch((err) => {
var errorMsg = err.message;
if (errorMsg.includes('\"reason\": \"dailyLimitExceeded\",')) {
errorMsg = errorMsg.slice(errorMsg.indexOf('Daily Limit Exceeded. '));
errorMsg = errorMsg.slice(0, errorMsg.indexOf('\",'));
if (!ignore) msg.channel.send(musicbot.note("fail", "**Unable to complete playback:**\n" + errorMsg));
return;
} else if (errorMsg.includes('\"reason\": \"quotaExceeded\",')) {
if (!ignore) msg.channel.send(musicbot.note("fail", "Unable to complete playback! Google API quota exceeded!"));
return;
} else {
if (!ignore) msg.channel.send(musicbot.note("fail", "Unknown error occurred! Playback could not be completed, check the logs for more details."));
return console.log(err);
}
});
if (result === undefined) return;
resolve(result.first)
}).then((res) => {
if (!res) return msg.channel.send(musicbot.note("fail", "Something went wrong. Try again!"));
res.requester = msg.author.id;
if (searchstring.startsWith("https://www.youtube.com/") || searchstring.startsWith("https://youtu.be/")) res.url = searchstring;
res.channelURL = `https://www.youtube.com/channel/${res.channelId}`;
res.queuedOn = new Date().toLocaleDateString(musicbot.dateLocal, { weekday: 'long', hour: 'numeric' });
if (musicbot.requesterName) res.requesterAvatarURL = msg.author.displayAvatarURL();
const queue = musicbot.getQueue(msg.guild.id)
res.position = queue.songs.length ? queue.songs.length : 0;
queue.songs.push(res);
if (!ignore) {
if (msg.channel.permissionsFor(msg.guild.me).has('EMBED_LINKS')) {
const embed = new Discord.RichEmbed();
try {
embed.setAuthor('Adding To Queue', client.user.avatarURL());
var songTitle = res.title.replace(/\\/g, '\\\\')
.replace(/\`/g, '\\`')
.replace(/\*/g, '\\*')
.replace(/_/g, '\\_')
.replace(/~/g, '\\~')
.replace(/`/g, '\\`');
embed.setColor(musicbot.embedColor);
embed.addField(res.channelTitle, `[${songTitle}](${res.url})`, musicbot.inlineEmbeds);
embed.addField("Queued On", res.queuedOn, musicbot.inlineEmbeds);
if (!musicbot.bigPicture) embed.setThumbnail(`https://img.youtube.com/vi/${res.id}/maxresdefault.jpg`);
if (musicbot.bigPicture) embed.setImage(`https://img.youtube.com/vi/${res.id}/maxresdefault.jpg`);
const resMem = client.users.cache.get(res.requester);
if (musicbot.requesterName && resMem) embed.setFooter(`Requested by ${client.users.cache.get(res.requester).username}`, res.requesterAvatarURL);
if (musicbot.requesterName && !resMem) embed.setFooter(`Requested by \`UnknownUser (ID: ${res.requester})\``, res.requesterAvatarURL);
msg.channel.send({
embed
});
} catch (e) {
console.error(`[${msg.guild.name}] [playCmd] ` + e.stack);
};
} else {
try {
var songTitle = res.title.replace(/\\/g, '\\\\')
.replace(/\`/g, '\\`')
.replace(/\*/g, '\\*')
.replace(/_/g, '\\_')
.replace(/~/g, '\\~')
.replace(/`/g, '\\`');
msg.channel.send(`Now Playing: **${songTitle}**\nRequested By: ${client.users.cache.get(res.requester).username}\nQueued On: ${res.queuedOn}`)
} catch (e) {
console.error(`[${msg.guild.name}] [npCmd] ` + e.stack);
};
};
};
if (queue.songs.length === 1 || !client.voice.connections.find(val => val.channel.guild.id == msg.guild.id)) musicbot.executeQueue(msg, queue);
}).catch((res) => {
console.log(new Error(res));
});
};
};
musicbot.helpFunction = (msg, suffix, args) => {
const prefix = typeof musicbot.botPrefix == "object" ? (musicbot.botPrefix.has(msg.guild.id) ? musicbot.botPrefix.get(msg.guild.id).prefix : musicbot.defaultPrefix) : musicbot.botPrefix;
let command = suffix.trim();
if (!suffix) {
if (msg.channel.permissionsFor(msg.guild.me)
.has('EMBED_LINKS')) {
const embed = new Discord.RichEmbed();
embed.setAuthor("Commands", client.user.avatarURL());
embed.setDescription(`Use \`${prefix}${musicbot.help.name} command name\` for help on usage. Anyone with a role named \`${musicbot.djRole}\` can use any command.`);
// embed.addField(musicbot.helpCmd, musicbot.helpHelp);
const newCmds = Array.from(musicbot.commands);
let index = 0;
let max = musicbot.commandsArray.length;
embed.setColor(musicbot.embedColor);
for (var i = 0; i < musicbot.commandsArray.length; i++) {
if (!musicbot.commandsArray[i].exclude) embed.addField(musicbot.commandsArray[i].name, musicbot.commandsArray[i].help);
index++;
if (index == max) {
if (musicbot.messageHelp) {
let sent = false;
msg.author.send({
embed
})
.then(() => {
sent = true;
});
setTimeout(() => {
if (!sent) return msg.channel.send({
embed
});
}, 1200);
} else {
return msg.channel.send({
embed
});
};
}
};
} else {
var cmdmsg = `= Music Commands =\nUse ${prefix}${musicbot.help.name} [command] for help on a command. Anyone with a role named \`${musicbot.djRole}\` can use any command.\n`;
let index = 0;
let max = musicbot.commandsArray.length;
for (var i = 0; i < musicbot.commandsArray.length; i++) {
if (!musicbot.commandsArray[i].disabled || !musicbot.commandsArray[i].exclude) {
cmdmsg = cmdmsg + `\n• ${musicbot.commandsArray[i].name}: ${musicbot.commandsArray[i].help}`;
index++;
if (index == musicbot.commandsArray.length) {
if (musicbot.messageHelp) {
let sent = false;
msg.author.send(cmdmsg, {
code: 'asciidoc'
})
.then(() => {
sent = true;
});
setTimeout(() => {
if (!sent) return msg.channel.send(cmdmsg, {
code: 'asciidoc'
});
}, 500);
} else {
return msg.channel.send(cmdmsg, {
code: 'asciidoc'
});
};
}
};
};
};
} else if (musicbot.commands.has(command) || musicbot.aliases.has(command)) {
if (msg.channel.permissionsFor(msg.guild.me)
.has('EMBED_LINKS')) {
const embed = new Discord.RichEmbed();
command = musicbot.commands.get(command) || musicbot.aliases.get(command);
if (command.exclude) return msg.channel.send(musicbot.note('fail', `${suffix} is not a valid command!`));
embed.setAuthor(command.name, msg.client.user.avatarURL());
embed.setDescription(command.help);
if (command.alt.length > 0) embed.addField(`Aliases`, command.alt.join(", "), musicbot.inlineEmbeds);
if (command.usage && typeof command.usage == "string") embed.addField(`Usage`, command.usage.replace(/{{prefix}})/g, prefix), musicbot.inlineEmbeds);
embed.setColor(musicbot.embedColor);
msg.channel.send({
embed
});
} else {
command = musicbot.commands.get(command) || musicbot.aliases.get(command);
if (command.exclude) return msg.channel.send(musicbot.note('fail', `${suffix} is not a valid command!`));
var cmdhelp = `= ${command.name} =\n`;
cmdhelp = cmdhelp + `\n${command.help}`;
if (command.usage !== null) cmdhelp = cmdhelp + `\nUsage: ${command.usage.replace(/{{prefix}})/g, prefix)}`;
if (command.alt.length > 0) cmdhelp = cmdhelp + `\nAliases: ${command.alt.join(", ")}`;
msg.channel.send(cmdhelp, {
code: 'asciidoc'
});
};
} else {
msg.channel.send(musicbot.note('fail', `${suffix} is not a valid command!`));
};
};
musicbot.skipFunction = (msg, suffix, args) => {
if (!msg.member.voice.channel) return msg.channel.send(musicbot.note('fail', `You're not in a voice channel.`));
const voiceConnection = client.voice.connections.find(val => val.channel.guild.id == msg.guild.id);
if (voiceConnection === null) return msg.channel.send(musicbot.note('fail', 'No music being played.'));
if (voiceConnection && voiceConnection.channel.id != msg.member.voice.channel.id) return msg.channel.send(musicbot.note('fail', `You must be in the same voice channel as me.`));
const queue = musicbot.getQueue(msg.guild.id);
if (!musicbot.canSkip(msg.member, queue)) return msg.channel.send(musicbot.note('fail', `You cannot skip this as you didn't queue it.`));
if (musicbot.queues.get(msg.guild.id).loop == "song") return msg.channel.send(musicbot.note("fail", "Cannot skip while loop is set to single."));
const dispatcher = voiceConnection.player.dispatcher;
if (!dispatcher || dispatcher === null) {
if (musicbot.logging) return console.log(new Error(`dispatcher null on skip cmd [${msg.guild.name}] [${msg.author.username}]`));
return msg.channel.send(musicbot.note("fail", "Something went wrong running skip."));
};
if (voiceConnection.paused) dispatcher.destroy();
dispatcher.destroy();
msg.channel.send(musicbot.note("note", "Skipped song."));
};
musicbot.pauseFunction = (msg, suffix, args) => {
if (!msg.member.voice.channel) return msg.channel.send(musicbot.note('fail', `You're not in a voice channel.`));
const voiceConnection = client.voice.connections.find(val => val.channel.guild.id == msg.guild.id);
if (voiceConnection === null) return msg.channel.send(musicbot.note('fail', 'No music being played.'));
if (voiceConnection && voiceConnection.channel.id != msg.member.voice.channel.id) return msg.channel.send(musicbot.note('fail', `You must be in the same voice channel as me.`));
if (!musicbot.isAdmin(msg.member) && !musicbot.anyoneCanPause) return msg.channel.send(musicbot.note('fail', 'You cannot pause queues.'));
const dispatcher = voiceConnection.player.dispatcher;
if (dispatcher.paused) return msg.channel.send(musicbot.note(`fail`, `Music already paused!`))
else dispatcher.pause();
msg.channel.send(musicbot.note('note', 'Playback paused.'));
};
musicbot.resumeFunction = (msg, suffix, args) => {
if (!msg.member.voice.channel) return msg.channel.send(musicbot.note('fail', `You're not in a voice channel.`));
const voiceConnection = client.voice.connections.find(val => val.channel.guild.id == msg.guild.id);
if (voiceConnection === null) return msg.channel.send(musicbot.note('fail', 'No music being played.'));
if (voiceConnection && voiceConnection.channel.id != msg.member.voice.channel.id) return msg.channel.send(musicbot.note('fail', `You must be in the same voice channel as me.`));
if (!musicbot.isAdmin(msg.member) && !musicbot.anyoneCanPause) return msg.channel.send(musicbot.note('fail', `You cannot resume queues.`));
const dispatcher = voiceConnection.player.dispatcher;
if (!dispatcher.paused) return msg.channel.send(musicbot.note('fail', `Music already playing.`))
else dispatcher.resume();
msg.channel.send(musicbot.note('note', 'Playback resumed.'));
};
musicbot.leaveFunction = (msg, suffix) => {
if (musicbot.isAdmin(msg.member) || musicbot.anyoneCanLeave === true) {
if (!msg.member.voice.channel) return msg.channel.send(musicbot.note('fail', `You're not in a voice channel.`));
const voiceConnection = client.voice.connections.find(val => val.channel.guild.id == msg.guild.id);
if (voiceConnection === null) return msg.channel.send(musicbot.note('fail', 'I\'m not in a voice channel.'));
if (voiceConnection && voiceConnection.channel.id != msg.member.voice.channel.id) return msg.channel.send(musicbot.note('fail', `You must be in the same voice channel as me.`));
musicbot.emptyQueue(msg.guild.id).then(() => {
if (!voiceConnection.player.dispatcher) return;
voiceConnection.player.dispatcher.destroy();
voiceConnection.disconnect();
msg.channel.send(musicbot.note('note', 'Successfully left the voice channel.'));
}).catch((res) => {
console.log("["+msg.guild.id+"] " + res);
musicbot.queues.delete(msg.guild.id);
musicbot.queues.set(msg.guild.id, {songs: [], last: null, loop: "none", id: msg.guild.id, volume: musicbot.defVolume, oldSongs: [],working: false, needsRefresh: false});
})
} else {
const chance = Math.floor((Math.random() * 100) + 1);
if (chance <= 10) return msg.channel.send(musicbot.note('fail', `I'm afraid I can't let you do that, ${msg.author.username}.`))
else return msg.channel.send(musicbot.note('fail', 'Sorry, you\'re not allowed to do that.'));
}
}
musicbot.npFunction = (msg, suffix, args) => {
const voiceConnection = client.voice.connections.find(val => val.channel.guild.id == msg.guild.id);
if (voiceConnection === null) return msg.channel.send(musicbot.note('fail', 'No music is being played.'));
const queue = musicbot.getQueue(msg.guild.id, true);
const dispatcher = voiceConnection.player.dispatcher;
if (musicbot.queues.get(msg.guild.id).songs.length <= 0) return msg.channel.send(musicbot.note('note', 'Queue empty.'));
if (msg.channel.permissionsFor(msg.guild.me)
.has('EMBED_LINKS')) {
const embed = new Discord.RichEmbed();
try {
embed.setAuthor('Now Playing', client.user.avatarURL());
var songTitle = queue.last.title.replace(/\\/g, '\\\\')
.replace(/\`/g, '\\`')
.replace(/\*/g, '\\*')
.replace(/_/g, '\\_')
.replace(/~/g, '\\~')
.replace(/`/g, '\\`');
embed.setColor(musicbot.embedColor);
embed.addField(queue.last.channelTitle, `[${songTitle}](${queue.last.url})`, musicbot.inlineEmbeds);
embed.addField("Queued On", queue.last.queuedOn, musicbot.inlineEmbeds);
if (!musicbot.bigPicture) embed.setThumbnail(`https://img.youtube.com/vi/${queue.last.id}/maxresdefault.jpg`);
if (musicbot.bigPicture) embed.setImage(`https://img.youtube.com/vi/${queue.last.id}/maxresdefault.jpg`);
const resMem = client.users.cache.get(queue.last.requester);
if (musicbot.requesterName && resMem) embed.setFooter(`Requested by ${client.users.cache.get(queue.last.requester).username}`, queue.last.requesterAvatarURL);
if (musicbot.requesterName && !resMem) embed.setFooter(`Requested by \`UnknownUser (ID: ${queue.last.requester})\``, queue.last.requesterAvatarURL);
msg.channel.send({
embed
});
} catch (e) {
console.error(`[${msg.guild.name}] [npCmd] ` + e.stack);
};
} else {
try {
var songTitle = queue.last.title.replace(/\\/g, '\\\\')
.replace(/\`/g, '\\`')
.replace(/\*/g, '\\*')
.replace(/_/g, '\\_')
.replace(/~/g, '\\~')
.replace(/`/g, '\\`');
msg.channel.send(`Now Playing: **${songTitle}**\nRequested By: ${client.users.cache.get(queue.last.requester).username}\nQueued On: ${queue.last.queuedOn}`)
} catch (e) {
console.error(`[${msg.guild.name}] [npCmd] ` + e.stack);
};
}
};
musicbot.deleteQueueFunction = async (msg, suffix, args) => {
if (!musicbot.isAdmin(msg.member)) return msg.channel.send(musicbot.note("fail", "Only and Admin can do this."));
const voiceConnection = client.voice.connections.find(val => val.channel.guild.id == msg.guild.id);
musicbot.emptyQueue(msg.guild.id).then(() => {
if (voiceConnection !== null) {
const dispatcher = voiceConnection.player.dispatcher;
dispatcher.destroy()
}
return msg.channel.send(musicbot.note("note", "The queue should now be emptied."))
}).catch(async (res) => {
console.log("["+msg.guild.id+"] " + e);
// force the queue delete
musicbot.queues.delete(msg.guild.id);
musicbot.queues.set(msg.guild.id, {songs: [], last: null, loop: "none", id: msg.guild.id, volume: musicbot.defVolume, oldSongs: [],working: false, needsRefresh: false});
if (voiceConnection !== null) {
const dispatcher = voiceConnection.player.dispatcher;
dispatcher.destroy()
}
msg.channel.send(musicbot.note("note", "The queue should now be deleted."))
})
}
musicbot.queueFunction = (msg, suffix, args) => {
if (!msg.member.voice.channel) return msg.channel.send(musicbot.note('fail', `You're not in a voice channel.`));
const voiceConnection = client.voice.connections.find(val => val.channel.guild.id == msg.guild.id);
if (voiceConnection === null) return msg.channel.send(musicbot.note('fail', 'No music being played.'));
if (voiceConnection && voiceConnection.channel.id != msg.member.voice.channel.id) return msg.channel.send(musicbot.note('fail', `You must be in the same voice channel as me.`));
if (!musicbot.queues.has(msg.guild.id)) return msg.channel.send(musicbot.note("fail", "Could not find a queue for this server."));
else if (musicbot.queues.get(msg.guild.id).songs.length <= 0) return msg.channel.send(musicbot.note("fail", "Queue is empty."));
const queue = musicbot.queues.get(msg.guild.id);
if (suffix) {
let video = queue.songs.find(s => s.position == parseInt(suffix) - 1);
if (!video) return msg.channel.send(musicbot.note("fail", "Couldn't find that video."));
const embed = new Discord.RichEmbed()
.setAuthor('Queued Song', client.user.avatarURL())
.setColor(musicbot.embedColor)
.addField(video.channelTitle, `[${video.title.replace(/\\/g, '\\\\').replace(/\`/g, '\\`').replace(/\*/g, '\\*').replace(/_/g, '\\_').replace(/~/g, '\\~').replace(/`/g, '\\`')}](${video.url})`, musicbot.inlineEmbeds)
.addField("Queued On", video.queuedOn, musicbot.inlineEmbeds)
.addField("Position", video.position + 1, musicbot.inlineEmbeds);
if (!musicbot.bigPicture) embed.setThumbnail(`https://img.youtube.com/vi/${video.id}/maxresdefault.jpg`);
if (musicbot.bigPicture) embed.setImage(`https://img.youtube.com/vi/${video.id}/maxresdefault.jpg`);
const resMem = client.users.cache.get(video.requester);
if (musicbot.requesterName && resMem) embed.setFooter(`Requested by ${client.users.cache.get(video.requester).username}`, video.requesterAvatarURL);
if (musicbot.requesterName && !resMem) embed.setFooter(`Requested by \`UnknownUser (ID: ${video.requester})\``, video.requesterAvatarURL);
msg.channel.send({embed});
} else {
if (queue.songs.length > 11) {
let pages = [];
let page = 1;
const newSongs = queue.songs.musicArraySort(10);
newSongs.forEach(s => {
var i = s.map((video, index) => (
`**${video.position + 1}:** __${video.title.replace(/\\/g, '\\\\').replace(/\`/g, '\\`').replace(/\*/g, '\\*').replace(/_/g, '\\_').replace(/~/g, '\\~').replace(/`/g, '\\`')}__`
)).join('\n\n');
if (i !== undefined) pages.push(i)
});
const embed = new Discord.RichEmbed();
embed.setAuthor('Queued Songs', client.user.avatarURL());
embed.setColor(musicbot.embedColor);
embed.setFooter(`Page ${page} of ${pages.length}`);
embed.setDescription(pages[page - 1]);
msg.channel.send(embed).then(m => {
m.react('⏪').then( r => {
m.react('⏩')
let forwardsFilter = m.createReactionCollector((reaction, user) => reaction.emoji.name === '⏩' && user.id === msg.author.id, { time: 120000 });
let backFilter = m.createReactionCollector((reaction, user) => reaction.emoji.name === '⏪' && user.id === msg.author.id, { time: 120000 });
forwardsFilter.on('collect', r => {
if (page === pages.length) return;
page++;
embed.setDescription(pages[page - 1]);
embed.setFooter(`Page ${page} of ${pages.length}`, msg.author.displayAvatarURL());
m.edit(embed);
})
backFilter.on('collect', r => {
if (page === 1) return;
page--;
embed.setDescription(pages[page - 1]);
embed.setFooter(`Page ${page} of ${pages.length}`);
m.edit(embed);
})
})
})
} else {
try {
var newSongs = musicbot.queues.get(msg.guild.id).songs.map((video, index) => (`**${video.position + 1}:** __${video.title.replace(/\\/g, '\\\\').replace(/\`/g, '\\`').replace(/\*/g, '\\*').replace(/_/g, '\\_').replace(/~/g, '\\~').replace(/`/g, '\\`')}__`)).join('\n\n');
const embed = new Discord.RichEmbed();
embed.setAuthor('Queued Songs', client.user.avatarURL());
embed.setColor(musicbot.embedColor);
embed.setDescription(newSongs);
embed.setFooter(`Page 1 of 1`, msg.author.displayAvatarURL());
return msg.channel.send(embed);
} catch (e) {
console.log("["+msg.guild.id+"] " + e);
return msg.channel.send(msicbot.note("fail", "Something went wrong mapping out the queue! Please delete the queue if this persists."));
};
};
};
};
musicbot.searchFunction = (msg, suffix, args) => {
if (msg.member.voice.channel === undefined) return msg.channel.send(musicbot.note('fail', `You're not in a voice channel.`));
let vc = client.voice.connections.find(val => val.channel.guild.id == msg.member.guild.id)
if (vc && vc.channel.id != msg.member.voice.channel.id) return msg.channel.send(musicbot.note('fail', `You must be in the same voice channel as me.`));
let us = `${msg.guild.id}-${msg.author.id}`;
if (musicbot.userSearching.has(us)) return msg.channel.send(musicbot.note("fail", `You already have a search on-going for \`${musicbot.userSearching.get(us).title}\`.\nYou may type \`cancel\` to cancel it.`));
if (!suffix) return msg.channel.send(musicbot.note('fail', 'No video specified!'));
const queue = musicbot.getQueue(msg.guild.id);
if (queue.songs.length >= musicbot.maxQueueSize && musicbot.maxQueueSize !== 0) return msg.channel.send(musicbot.note('fail', 'Maximum queue size reached!'));
musicbot.userSearching.set(us, {guild: msg.guild.id, user: msg.author.id, title: suffix})
let searchstring = suffix.trim();
msg.channel.send(musicbot.note('search', `Searching: \`${searchstring}\``))
.then(response => {
musicbot.searcher.search(searchstring, {
type: 'video'
})
.then(searchResult => {
if (!searchResult.totalResults || searchResult.totalResults === 0) return response.edit(musicbot.note('fail', 'Failed to get search results.'));
const startTheFun = async (videos, max) => {
if (msg.channel.permissionsFor(msg.guild.me).has('EMBED_LINKS')) {
const embed = new Discord.RichEmbed();
embed.setTitle(`Choose Your Video`);
embed.setColor(musicbot.embedColor);
var index = 0;
videos.forEach(function(video) {
index++;
embed.addField(`${index} (${video.channelTitle})`, `[${musicbot.note('font', video.title)}](${video.url})`, musicbot.inlineEmbeds);
});
embed.setFooter(`Search by: ${msg.author.username}`, msg.author.displayAvatarURL());
msg.channel.send({
embed
})
.then(firstMsg => {
var filter = null;
if (max === 0) {
filter = m => m.author.id === msg.author.id &&
m.content.includes('1') ||
m.content.trim() === (`cancel`);
} else if (max === 1) {
filter = m => m.author.id === msg.author.id &&
m.content.includes('1') ||
m.content.includes('2') ||
m.content.trim() === (`cancel`);
} else if (max === 2) {
filter = m => m.author.id === msg.author.id &&
m.content.includes('1') ||
m.content.includes('2') ||
m.content.includes('3') ||
m.content.trim() === (`cancel`);
} else if (max === 3) {
filter = m => m.author.id === msg.author.id &&
m.content.includes('1') ||
m.content.includes('2') ||
m.content.includes('3') ||
m.content.includes('4') ||
m.content.trim() === (`cancel`);
} else if (max === 4) {
filter = m => m.author.id === msg.author.id &&
m.content.includes('1') ||
m.content.includes('2') ||
m.content.includes('3') ||
m.content.includes('4') ||
m.content.includes('5') ||
m.content.trim() === (`cancel`);
} else if (max === 5) {
filter = m => m.author.id === msg.author.id &&
m.content.includes('1') ||
m.content.includes('2') ||
m.content.includes('3') ||
m.content.includes('4') ||
m.content.includes('5') ||
m.content.includes('6') ||
m.content.trim() === (`cancel`);
} else if (max === 6) {
filter = m => m.author.id === msg.author.id &&
m.content.includes('1') ||
m.content.includes('2') ||
m.content.includes('3') ||
m.content.includes('4') ||