-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathruby-old.js
More file actions
2576 lines (2317 loc) · 96.3 KB
/
ruby-old.js
File metadata and controls
2576 lines (2317 loc) · 96.3 KB
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
// Disables listener limit
require('events').EventEmitter.prototype._maxListeners = 0;
// Discord variables
const Discord = require("discord.js");
const bot = new Discord.Client({disableEveryone: true, fetchAllMembers: true});
// Grabs values from the config file and assigns them to vars
var ConfigFile = require('./config.json');
var token = ConfigFile.discord_token;
var prefix = ConfigFile.prefix;
var soundcloudId = ConfigFile.soundcloud_id;
var nani = require('nani').init(ConfigFile.anilist_id, ConfigFile.anilist_secret);
var mathjs = require('mathjs');
var Entities = require('html-entities').AllHtmlEntities;
var toTitleCase = require('to-title-case');
var fs = require('fs');
var ytdl = require('ytdl-core');
var entities = new Entities();
// because I'm lazy
var coreCraftId = "95907910558683136";
// List to keep track of music in servers, keyed by guild id
var musicConnections = {};
// All country servers and their invite links (~Nyaa utility)
var countryServers = {
// Australia servers
"adelaide": {
name: "Adelaide",
invite: "https://discord.gg/0ZDr5SYHMyBDKbpe",
cooldown: 0
},
"brisbane": {
name: "Brisbane",
invite: "https://discord.gg/0ZD8LAL4hJvEYViS",
cooldown: 0
},
"cairns": {
name: "Cairns",
invite: "https://discord.gg/0eDrq3uuUSAeTK7s",
cooldown: 0
},
"canberra": {
name: "Canberra",
invite: "https://discord.gg/0ZfrQK7nk59RKjY9",
cooldown: 0
},
"darwin": {
name: "Darwin",
invite: "https://discord.gg/0j4lOe5NEJhmzZu8",
cooldown: 0
},
"melbourne": {
name: "Melbourne",
invite: "https://discord.gg/0ZD8H5WEzzfXs2tE",
cooldown: 0
},
"newcastle": {
name: "Newcastle",
invite: "https://discord.gg/0Zfqks79aldG43qh",
cooldown: 0
},
"perth": {
name: "Perth",
invite: "https://discord.gg/0ZRklMgwOCCXdxl8",
cooldown: 0
},
"port macquarie": {
name: "Port Macquarie",
invite: "https://discord.gg/0ZfqZJQHg86OFBNJ",
cooldown: 0
},
"sydney": {
name: "Sydney",
invite: "https://discord.gg/0ZBv6u3Iu4sR8Flo",
cooldown: 0
},
"tasmania": {
name: "Tasmania",
invite: "https://discord.gg/0ZU0Isybnb5N0sdU",
cooldown: 0
},
"townsville": {
name: "Townsville",
invite: "https://discord.gg/0exIe1ZoiENWAcRe",
cooldown: 0
},
// Country servers
"argentina": {
name: "Argentina",
invite: "https://discord.gg/0ZfreIeaue4ZWllZ",
cooldown: 0
},
"austria": {
name: "Austria",
invite: "https://discord.gg/0eDTvUmdTTnO34nD",
cooldown: 0
},
"azerbaijan": {
name: "Azerbaijan",
invite: "https://discord.gg/0eDU8koqZBua6zRi",
cooldown: 0
},
"belarus": {
name: "Belarus",
invite: "https://discord.gg/0eDkryprgZRSodAN",
cooldown: 0
},
"belgium": {
name: "Belgium",
invite: "https://discord.gg/0eDl7zo54KXDezAw",
cooldown: 0
},
"bolivia": {
name: "Bolivia",
invite: "https://discord.gg/0rAx4zNHesc6cG3i",
cooldown: 0
},
"brazil": {
name: "Brazil",
invite: "https://discord.gg/0eDQ03VPUfJgh34L",
cooldown: 0
},
"brunei": {
name: "Brunei",
invite: "https://discord.gg/0eDqt0PylwnNXvc6",
cooldown: 0
},
"bulgaria": {
name: "Bulgaria",
invite: "https://discord.gg/0eDqbBgXMJtpzNqk",
cooldown: 0
},
"cambodia": {
name: "Cambodia",
invite: "https://discord.gg/GVDgJhC",
cooldown: 0
},
"canada": {
name: "Canada",
invite: "https://discord.gg/0ZH4lwpdXig65iRs",
cooldown: 0
},
"chile": {
name: "Chile",
invite: "https://discord.gg/0is99YaNk3iCFaOg",
cooldown: 0
},
"china": {
name: "China",
invite: "https://discord.gg/0eDQD5NHxQfpV1ry",
cooldown: 0
},
"colombia": {
name: "Colombia",
invite: "https://discord.gg/0isAFUvc69ZDi5zv",
cooldown: 0
},
"croatia": {
name: "Croatia",
invite: "https://discord.gg/0eDqMTWZZxGFsQkm",
cooldown: 0
},
"cuba": {
name: "Cuba",
invite: "https://discord.gg/jECXWqf",
cooldown: 0
},
"czech republic": {
name: "Czech Republic",
invite: "https://discord.gg/0eDr4N0H87qO52wO",
cooldown: 0
},
"denmark": {
name: "Denmark",
invite: "https://discord.gg/0eDQQxxTUZV2WRfA",
cooldown: 0
},
"egypt": {
name: "Egypt",
invite: "https://discord.gg/0eDrJgBoZcnhpuBO",
cooldown: 0
},
"estonia": {
name: "Estonia",
invite: "https://discord.gg/0isANMe727dt6Slb",
cooldown: 0
},
"finland": {
name: "Finland",
invite: "https://discord.gg/0eDrUcKfwx2b2mtR",
cooldown: 0
},
"france": {
name: "France",
invite: "https://discord.gg/0ZfrmrAbjCCMK0qU",
cooldown: 0
},
"germany": {
name: "Germany",
invite: "https://discord.gg/0ZftW6tl70oFnyfN",
cooldown: 0
},
"greece": {
name: "Greece",
invite: "https://discord.gg/0eDQvBoidXPxVYV0",
cooldown: 0
},
"guam": {
name: "Guam",
invite: "https://discord.gg/0eDrgRlX8JMsSMJe",
cooldown: 0
},
"hong kong": {
name: "Hong Kong",
invite: "https://discord.gg/0eDQjbu1y5hqL9MP",
cooldown: 0
},
"hungary": {
name: "Hungary",
invite: "https://discord.gg/0eDs2YLWyKrWsoiI",
cooldown: 0
},
"india": {
name: "India",
invite: "https://discord.gg/0eDRr62KdHi5Ucjb",
cooldown: 0
},
"indonesia": {
name: "Indonesia",
invite: "https://discord.gg/0eDRVSi64xalGkJk",
cooldown: 0
},
"ireland": {
name: "Ireland",
invite: "https://discord.gg/0is83mA2NRSjC4Ct",
cooldown: 0
},
"israel": {
name: "Israel",
invite: "https://discord.gg/0bLHcYbMGWFoTmD8",
cooldown: 0
},
"italy": {
name: "Italy",
invite: "https://discord.gg/0eDRHRnaAC9AXWkd",
cooldown: 0
},
"japan": {
name: "Japan",
invite: "https://discord.gg/0dHiutjeu3hAK9Lu",
cooldown: 0
},
"kazakhstan": {
name: "Kazakhstan",
invite: "https://discord.gg/0eDsEUcr2CiwWtU9",
cooldown: 0
},
"lithuania": {
name: "Lithuania",
invite: "https://discord.gg/0isA3w9Pg1PCBJzu",
cooldown: 0
},
"malaysia": {
name: "Malaysia",
invite: "https://discord.gg/0eDRiiX06ruklt61",
cooldown: 0
},
"mexico": {
name: "Mexico",
invite: "https://discord.gg/0rAvVeMaiL45bNax",
cooldown: 0
},
"netherlands": {
name: "Netherlands",
invite: "https://discord.gg/0ZDe2a2hrXXNiRuY",
cooldown: 0
},
"new zealand": {
name: "New Zealand",
invite: "https://discord.gg/0dIAGN8v3Qjm6VKB",
cooldown: 0
},
"norway": {
name: "Norway",
invite: "https://discord.gg/0is8REcaCGQlMMnv",
cooldown: 0
},
"paraguay": {
name: "Paraguay",
invite: "https://discord.gg/0rAwcX1PfGFk9zwh",
cooldown: 0
},
"philippines": {
name: "Philippines",
invite: "https://discord.gg/0is9YPbrO5jEZWl6",
cooldown: 0
},
"poland": {
name: "Poland",
invite: "https://discord.gg/0aEnYYM2Eiv1vWIj",
cooldown: 0
},
"portugal": {
name: "Portugal",
invite: "https://discord.gg/0is9szbE6cDkq8Yn",
cooldown: 0
},
"puerto rico": {
name: "Puerto Rico",
invite: "https://discord.gg/0rNoDqv6j3hT14UH",
cooldown: 0
},
"romania": {
name: "Romania",
invite: "https://discord.gg/0isAY5pA7nPL59JU",
cooldown: 0
},
"russia": {
name: "Russia",
invite: "https://discord.gg/0b1KVm67Vmzy0Giv",
cooldown: 0
},
"serbia": {
name: "Serbia",
invite: "https://discord.gg/0dI9syWXyoRJ12Jn",
cooldown: 0
},
"singapore": {
name: "Singapore",
invite: "https://discord.gg/0dI9JQdkEAtjsSjl",
cooldown: 0
},
"slovakia": {
name: "Slovakia",
invite: "https://discord.gg/0dI8sDtu83gHKelq",
cooldown: 0
},
"south africa": {
name: "South Africa",
invite: "https://discord.gg/0rAw9ICnyIepqwSl",
cooldown: 0
},
"south korea": {
name: "South Korea",
invite: "https://discord.gg/0beSC9ID5k0l1WPt",
cooldown: 0
},
"spain": {
name: "Spain",
invite: "https://discord.gg/0b1JzGvEl0klFn1j",
cooldown: 0
},
"sweden": {
name: "Sweden",
invite: "https://discord.gg/0Zfrwm7kiUThImbK",
cooldown: 0
},
"switzerland": {
name: "Switzerland",
invite: "https://discord.gg/0b1JlqmGy0dCMp4m",
cooldown: 0
},
"taiwan": {
name: "Taiwan",
invite: "https://discord.gg/0b1JYAEdSI0hmwFf",
cooldown: 0
},
"thailand": {
name: "Thailand",
invite: "https://discord.gg/0hTNRzyTmIeh3bPw",
cooldown: 0
},
"turkey": {
name: "Turkey",
invite: "https://discord.gg/0b1JJlYzeLWFJU4E",
cooldown: 0
},
"uae": {
name: "UAE",
invite: "https://discord.gg/0b1JDsT2krXUctNY",
cooldown: 0
},
"uk": {
name: "UK",
invite: "https://discord.gg/0ZRKsDlRUCrMljdi",
cooldown: 0
},
"ukraine": {
name: "Ukraine",
invite: "https://discord.gg/0b1J65hvvp5REfvZ",
cooldown: 0
},
"uruguay": {
name: "Uruguay",
invite: "https://discord.gg/0b1IY52JEs8JRZAs",
cooldown: 0
},
"usa": {
name: "USA",
invite: "https://discord.gg/tmCtmxZ",
cooldown: 0
},
"venezuela": {
name: "Venezuela",
invite: "https://discord.gg/0b1GeMhOWFw0WOvh",
cooldown: 0
},
"vietnam": {
name: "Vietnam",
invite: "https://discord.gg/0Zyk8AMOT1Pzyy7E",
cooldown: 0
}
};
// All the commands are located here
var commands = {
"introduce": {
name: "introduce",
description: "Displays some info about myself.",
extendedhelp: "Tells you a little bit of information about myself.",
process: function(bot, message, suffix) {
var msgArray = [];
msgArray.push("Hello, I'm " + bot.user.username + "! It's a pleasure to meet you ^-^");
msgArray.push("To see what I can do, use `" + prefix + "help`");
msgArray.push("If you have any questions, feel free to ask my creator Visate :blush:");
message.channel.sendMessage(msgArray);
}
},
"help": {
name: "help",
usage: "[command]",
description: "Displays a help message or specific help for a command.",
extendedhelp: "Displays a help message, and can also be used to display specific help for a command.",
process: function(bot, message, suffix) {
// General help message
var member = message.member;
if (!suffix) {
var msgArray = [];
for (var key in commands) {
if (!commands.hasOwnProperty(key)) continue;
let command = commands[key];
if (!checkPerms(command, message)) continue;
let info = prefix + command.name;
if (command.hasOwnProperty('usage')) info += " " + command.usage;
info += "\n\t" + command.description + "\n";
msgArray.push(info);
}
member.sendMessage(":heart: __**Your guide to using Ruby**__ :heart:\n```\n" + msgArray.join("\n") + "```");
message.channel.sendMessage(":mailbox_with_mail: The commands have been direct messaged to you! :heart:");
}
// Searches commands list for command then displays specific help
else if (suffix) {
if (commands.hasOwnProperty(suffix)) {
let command = commands[suffix];
if (!checkPerms(command, message)) {
message.channel.sendMessage("You don't have sufficient permissions to use the command `" + suffix + "`!");
return;
}
let info = "**[Command]:** " + command.name;
info += "\n**[Usage]:** " + command.name;
if (command.hasOwnProperty('usage')) info += " " + command.usage;
info += "\n\n" + command.extendedhelp;
message.channel.sendMessage(info);
}
else {
message.channel.sendMessage("That command doesn't exist! Try again~");
}
}
}
},
"debug": {
name: "debug",
description: "For testing random code defined in the bot.",
extendedhelp: "Tests random code defined in this command to see its result. Only usable by Visate.",
visateOnly: true,
process: function(bot, message, suffix) {
if (message.author.id === '97198953430257664') {
// runs the code
try {
message.channel.sendMessage(eval(suffix));
} catch (err) {
message.channel.sendMessage("```js\n" + err + "\n```");
}
}
}
},
"music": {
name: "music",
alias: "m",
description: "Music module commands, " + prefix + "music help",
extendedhelp: "All music module commands are in this module, use `" + prefix + "music help` to a complete list of all the commands.",
process: function(bot, message, suffix) {
let request = require('request');
let guild = message.guild;
let subCmds = ["join", "leave", "stream", "play", "stop", "pause", "resume", "skip", "np", "queue", "volume"];
let baseCmd = suffix.toLowerCase().split(" ")[0];
let djPerms = checkPerms({modOnly: true}, message);
let connInfo = musicConnections[guild.id];
let connection = null;
if (connInfo !== null && connInfo !== undefined && connInfo.vChannel !== null && connInfo.vChannel !== undefined) {
connection = connInfo.vChannel.connection;
}
let play = (song) => {
if (musicConnections[guild.id] === null || musicConnections[guild.id] === undefined) return;
else if (song === null || song === undefined) {
connInfo.tChannel.sendMessage("Queue is empty! Better add some more songs~");
connInfo.playing = false;
return;
}
connInfo.tChannel.sendMessage(`Playing **${song.title}** (${song.length}) requested by **${song.requestedBy}**`);
let stream;
if (song.source === "youtube") {
stream = ytdl(song.url, {filter: 'audioonly'});
}
else if (song.source === "soundcloud") {
stream = request(song.url);
}
connInfo.dispatcher = connection.playStream(stream, {volume: connInfo.volume / 50, passes: 2});
connInfo.playing = true;
connInfo.dispatcher.on('end', () => {
connInfo.queue.shift();
play(connInfo.queue[0]);
});
connInfo.dispatcher.on('error', (err) => {
connInfo.tChannel.sendMessage(`Error occured during playback: ${err}`);
connInfo.queue.shift();
play(connInfo.queue[0]);
});
};
if (subCmds.includes(baseCmd) && baseCmd !== "join" && (connInfo === null || connInfo === undefined)) {
message.channel.sendMessage(`I haven't joined a voice channel yet! Summon me to a voice channel with \`${prefix}music join\` first!`);
return;
}
if (baseCmd === "join" && djPerms) {
if (message.member.voiceChannel !== null && message.member.voiceChannel !== undefined) {
if (connInfo !== null && connInfo !== undefined && connInfo.vChannel.id === message.member.voiceChannel.id) {
message.channel.sendMessage("I've already joined this voice channel!");
return;
}
message.member.voiceChannel.join();
musicConnections[guild.id] = {
vChannel: message.member.voiceChannel,
tChannel: message.channel,
volume: ConfigFile.default_volume,
dispatcher: null,
streaming: false,
playing: false,
skipVote: 0,
skipRequired: 0,
queue: []
};
message.channel.sendMessage(`Connected to voice channel ${message.member.voiceChannel.name} and binding to ${message.channel}.`);
}
else {
message.channel.sendMessage("Please join a voice channel first then use the command! :heart:");
}
}
else if (baseCmd === "leave" && djPerms) {
if (message.member.voiceChannel !== connInfo.vChannel) return message.channel.sendMessage("You aren't connected to the voice channel!");
if (connection !== null && connection !== undefined) {
connection.disconnect();
}
musicConnections[guild.id] = undefined;
message.channel.sendMessage("Disconnected from voice!");
}
else if (baseCmd === "stream" && djPerms) {
let stream = request('https://stream.r-a-d.io/main.mp3');
connInfo.dispatcher = connection.playStream(stream, {volume: connInfo.volume / 50, passes: 2});
connInfo.streaming = true;
connInfo.playing = false;
connInfo.queue = [];
message.channel.sendMessage("Starting stream from r-a-d.io~");
}
else if (baseCmd === "play" && djPerms) {
let songQuery = suffix.substring(4).trim();
if (songQuery.includes("youtube") || songQuery.includes("youtu.be")) {
// Youtube streaming
ytdl.getInfo(songQuery, (err, info) => {
if (err) {
message.channel.sendMessage("Error occured on adding song!: " + err);
return;
}
let totalSec = parseInt(info['length_seconds'], 10);
let min = ~~(totalSec / 60);
let sec = totalSec % 60;
if (sec < 10) {
sec = `0${sec}`;
}
let song = {
title: info['title'],
requestedBy: message.author.username,
length: `${min}:${sec}`,
url: songQuery,
source: "youtube"
};
connInfo.queue.push(song);
let position = "Up next!";
if (connInfo.queue.length > 1) position = connInfo.queue.length - 1;
message.channel.sendMessage(`Queued **${song.title}** (${song.length}) requested by **${song.requestedBy}**~ Position in queue: ${position}`);
if (!connInfo.playing) play(song);
});
}
else if (songQuery.includes("soundcloud")) {
// Soundcloud streaming
request('https://api.soundcloud.com/resolve?url=' + songQuery + "&client_id=" + soundcloudId, (error, response, body) => {
if (error) {
message.channel.sendMessage("Error occured on adding song!: " + err);
return;
}
else if (!error && response.statusCode === 200) {
let jsonObj = JSON.parse(body);
let milliSec = parseInt(jsonObj['duration'], 10);
let totalSec = ~~(milliSec / 1000);
let min = ~~(totalSec / 60);
let sec = totalSec % 60;
if (sec < 10) {
sec = `0${sec}`;
}
let song = {
title: jsonObj['title'],
requestedBy: message.author.username,
length: `${min}:${sec}`,
url: `${jsonObj['stream_url']}?client_id=${soundcloudId}`,
source: "soundcloud"
};
connInfo.queue.push(song);
let position = "Up next!";
if (connInfo.queue.length > 1) position = connInfo.queue.length - 1;
message.channel.sendMessage(`Queued **${song.title}** (${song.length}) requested by **${song.requestedBy}**~ Position in queue: ${position}`);
if (!connInfo.playing) play(song);
}
});
}
else {
// Youtube search
// temp placeholder
message.channel.sendMessage("Please provide a YouTube or Soundcloud link!");
}
}
else if (baseCmd === "stop" && djPerms) {
if (connInfo) {
message.channel.sendMessage("Music has been stopped!");
connInfo.streaming = false;
connInfo.playing = false;
connInfo.queue = [];
connInfo.dispatcher.end();
}
}
else if (baseCmd === "pause" && djPerms) {
if (connInfo.streaming) return;
message.channel.sendMessage("Paused!");
connInfo.dispatcher.pause();
}
else if (baseCmd === "resume" && djPerms) {
message.channel.sendMessage("Resumed!");
connInfo.dispatcher.resume();
}
else if (baseCmd === "skip") {
if (djPerms) {
message.channel.sendMessage("Skipped!");
connInfo.dispatcher.end();
}
else if (!guild.name.startsWith('~Nyaa')){
let unmutedCount = connInfo.vChannel.members.filter(m => !m.selfDeaf && !m.serverDeaf && m.id !== bot.user.id).size;
connInfo.skipRequired = ~~(unmutedCount * 0.3);
connInfo.skipVote += 1;
if (connInfo.skipVote >= connInfo.skipRequired) {
connInfo.skipVote = 0;
message.channel.sendMessage("Skipped!");
connInfo.dispatcher.end();
}
else {
message.channel.sendMessage(`Vote to skip acknowledged! Required votes to skip: \`${connInfo.skipVote}/${connInfo.skipRequired}\``);
}
}
}
else if (baseCmd === "np") {
if (connInfo.streaming) {
request("https://r-a-d.io/api", function(error, response, body) {
if (!error && response.statusCode === 200) {
let jsonObj = JSON.parse(body);
message.channel.sendMessage(`Now streaming from r-a-d.io in ${connInfo.vChannel.name}: **${jsonObj['main']['np']}**`);
}
});
}
else if (connInfo.playing) {
let milliSec = connInfo.dispatcher.time;
let totalSec = ~~(milliSec / 1000);
let min = ~~(totalSec / 60);
let sec = totalSec % 60;
if (sec < 10) {
sec = `0${sec}`;
}
message.channel.sendMessage(`Now playing in ${connInfo.vChannel.name}: **${connInfo.queue[0].title}** requested by **${connInfo.queue[0].requestedBy}** \`[${min}:${sec}/${connInfo.queue[0].length}]\``);
}
else {
message.channel.sendMessage(`Nothing is playing right now!`);
}
}
else if (baseCmd === "queue") {
if (connInfo.streaming) {
request("https://r-a-d.io/api", function(error, response, body) {
if (!error && response.statusCode === 200) {
let jsonObj = JSON.parse(body);
let streamQueue = jsonObj['main']['queue'];
let msgArray = [];
msgArray.push(`Now streaming from r-a-d.io in ${connInfo.vChannel.name}: **${jsonObj['main']['np']}**\n`);
msgArray.push(`__Upcoming songs:__`);
for (let i in streamQueue) {
msgArray.push(`**${parseInt(i, 10) + 1}:** ${streamQueue[i]['meta']}`);
}
message.channel.sendMessage(msgArray.join("\n"));
}
})
}
else if (connInfo.playing) {
let playQueue = connInfo.queue;
let msgArray = [];
let milliSec = connInfo.dispatcher.time;
let totalSec = ~~(milliSec / 1000);
let min = ~~(totalSec / 60);
let sec = totalSec % 60;
if (sec < 10) {
sec = `0${sec}`;
}
msgArray.push(`Now playing in ${connInfo.vChannel.name}: **${playQueue[0].title}** requested by **${playQueue[0].requestedBy}** \`[${min}:${sec}/${playQueue[0].length}]\`\n`);
if (playQueue.length > 1) {
msgArray.push(`__Upcoming songs:__`);
for (let i = 1; i < playQueue.length; i++) {
msgArray.push(`**${i}:** ${playQueue[i].title} (${playQueue[i].length}) requested by ${playQueue[i].requestedBy}`);
}
}
message.channel.sendMessage(msgArray.join("\n"));
}
else {
message.channel.sendMessage("Nothing is playing right now!");
}
}
else if (baseCmd === "volume") {
let volumeQuery = Math.round(parseInt(suffix.substring(6), 10));
if (djPerms && volumeQuery !== "" && !isNaN(volumeQuery)) {
if (volumeQuery > 100) volumeQuery = 100;
else if (volumeQuery < 0) volumeQuery = 0;
connInfo.volume = volumeQuery;
if (connInfo.dispatcher !== null && connInfo.dispatcher !== undefined) connInfo.dispatcher.setVolume(volumeQuery / 50);
}
let filled = "▓";
let unfilled = "░";
let count = Math.round(connInfo.volume / 5);
let volumeBar = Array(count + 1).join(filled) + Array(21 - count).join(unfilled);
message.channel.sendMessage(`Volume: ${connInfo.volume} [${volumeBar}]`);
}
else {
if (baseCmd === "help") {
let cmdName = "";
let usage = "";
let information = "";
let subCmd = suffix.substring(5).trim();
if (subCmd === "join") {
}
}
}
}
},
"restart": {
name: "restart",
description: "Restarts Ruby.",
extendedhelp: "Restarts Ruby by sending an exit code, only works if bot was launched with forever.",
visateOnly: true,
process: function(bot, message, suffix) {
message.channel.sendMessage("Be right back~ :heart:").then(() => {
process.exit(0);
});
}
},
"shutdown": {
name: "shutdown",
description: "Shuts down Ruby.",
extendedhelp: "Shuts down Ruby by sending exit code 21.",
visateOnly: true,
process: function(bot, message, suffix) {
message.channel.sendMessage("Bye bye~ :heart:").then(() => {
process.exit(21);
});
}
},
"purge": {
name: "purge",
usage: "<number of messages>",
description: "Deletes a certain amount of messages from chat.",
extendedhelp: "I will delete a certain amount of messages from chat.",
upOnly: true,
requiredPerms: ["MANAGE_MESSAGES"],
process: function(bot, message, suffix) {
if (!suffix) {
message.channel.sendMessage("Please define an amount of messages for me to delete!");
return;
}
if (isNaN(suffix)) {
message.channel.sendMessage("Please define an amount of messages for me to delete!");
return;
}
suffix = parseInt(suffix, 10);
/*if (!message.channel.permissionsFor(message.author).hasPermission("MANAGE_MESSAGES")) {
message.channel.sendMessage("Sorry, you don't have permission to delete messages!");
return;
}
if (!message.channel.permissionsFor(bot.user).hasPermission("MANAGE_MESSAGES")) {
message.channel.sendMessage("I don't have permission to delete messages here!");
return;
}*/
if (suffix > 2000) return message.channel.sendMessage("Sorry, I cannot delete more than 2000 messages.");
else if (suffix > 100) {
let delMsgs = (id) => {
let delCount = 0;
if (msgsCount > 100) {
msgsCount -= 100;
delCount = 100;
} else if (msgsCount > 0 && msgsCount <= 100) {
delCount = msgsCount;
msgsCount = 0;
}
if (delCount > 0) {
channel.fetchMessages({limit: delCount, before: id}).then(msgs => {
channel.bulkDelete(msgs).then(() => delMsgs(msgs.last().id));
});
}
}
let channel = message.channel;
let collector = channel.createCollector(m => m.author === message.author, {time: 30000});
let msgsCount = suffix;
channel.sendMessage(`You are about to delete ${suffix} messages. This action is not reversible. Are you sure you want to continue? (yes/no)`);
collector.on('message', message => {
if (message.content.toLowerCase() === "yes") collector.stop('delete');
else if (message.content.toLowerCase() === "no") collector.stop('abort');
});
collector.on('end', (collection, reason) => {
if (reason === "abort") return channel.sendMessage("Cancelled~");
else if (reason === "time") return channel.sendMessage("Time's up! Purge cancelled~");
else if (reason === "delete") {
msgsCount += 2;
let lastmsg = collection.last();
delMsgs(lastmsg.id);
lastmsg.delete();
}
});
}
else if (suffix > 0) {
message.delete().then(msg => msg.channel.bulkDelete(suffix));
}
}
},
"togglemode": {
name: "togglemode",
description: "In case of a Nyaabot outage, allow Ruby to take over.",
extendedhelp: "In case of a Nyaabot outage, this allows Ruby to perform the tasks that Nyaabot normally would.",
upOnly: true,
nyaaOnly: true,
process: function(bot, message, suffix) {
if (ConfigFile.backup_mode) {
ConfigFile.backup_mode = false;
}
else if (!ConfigFile.backup_mode) {
ConfigFile.backup_mode = true;
}
fs.writeFileSync('./config.json', JSON.stringify(ConfigFile, null, 2));
if (ConfigFile.backup_mode) {
message.channel.sendMessage("I'm ready! ^-^");
}
else if (!ConfigFile.backup_mode) {
message.channel.sendMessage("My job here is done. ^-^");
}
}
},
"tablepanic": {
name: "tablepanic",
description: "In case of a tablebot outage, allow Ruby to take over.",
extendedhelp: "In case of a tablebot outage, this allows Ruby to perform the tasks that tablebot normally would.",
upOnly: true,
nyaaOnly: true,
process: function(bot, message, suffix) {
if (ConfigFile.tablepanic) {
ConfigFile.tablepanic = false;
}
else if (!ConfigFile.tablepanic) {
ConfigFile.tablepanic = true;
}
fs.writeFileSync('./config.json', JSON.stringify(ConfigFile, null, 2));
if (ConfigFile.tablepanic) {
message.channel.sendMessage("Everybody panic!");
}
else if (!ConfigFile.tablepanic) {
message.channel.sendMessage("Alright panic over, back to normal friends ^-^");