-
Notifications
You must be signed in to change notification settings - Fork 0
/
roboto.js
5130 lines (4680 loc) · 181 KB
/
roboto.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
/** Mr. Roboto Turntable.fm bot
Jake Smith 2021
version 1.0 (forked from chillybot)
*/
/*******************************BeginSetUp*****************************************************************************/
var Bot = require('ttapi');
var AUTH = '#############'; //set the auth of your bot here.
var USERID = '6042b4ffc2dbd9001bb370c5'; //set the userid of your bot here.
var ROOMID = '604063be3f4bfc001be4c546'; //set the roomid of the room you want the bot to go to here.
var playLimit = 3; //set the playlimit here (default 4 songs)
var songLengthLimit = 10.0; //set song limit in minutes
var afkLimit = 20; //set the afk limit in minutes here
var howOftenToRepeatMessage = 15; //how often (in minutes) to repeat the room message (this corresponds to the MESSAGE variable below, only works when MESSAGE = true;)
var roomafkLimit = 10; //set the afk limit for the audience here(in minutes), this feature is off by default
var howManyVotes = 15; //how many awesome's for a song to be automatically added to the bot's playlist(only works when autoSnag = true;)
var howLongStage = 60;
/*how many second's does a dj have to get on stage when it's their turn to dj after waiting in the queue.
The value must be entered in seconds in order to display the correct message, i.e 3 mins = 180 seconds.
Note that people are not removed from the queue when they leave the room so a lower number is preferable in high pop rooms to avoid backup.
(only work when queue = true)
*/
global.masterIds = ['604056db3f4bfc001be4c22f']; //example (clear this before using)
/*This is the master id list, userid's that are put in here will not be affected by the song length limit, artist / song banning, the /skip command, or the dj afk limit.
This is meant to explicitly give extra privileges to yourself and anyone else you want to put in here. It takes userid's as input in string format separated by commas.
You can put the person's name in the array either before or after a userid to tell who it belongs to, it will not affect its ability to function.
*/
//this is for the bot's autodjing(triggers on new song, bot also gets on when no song is playing, unless autodjing is turned off)
var whenToGetOnStage = 2; //when this many or less people djing the bot will get on stage(only if autodjing is enabled)
var whenToGetOffStage = 3; //when this many people are on stage and auto djing is enabled the bot will get off stage(note: the bot counts as one person)
var roomJoinMessage = ''; //the message users will see when they join the room, leave it empty for the default message (only works when greet is turned on)
//example of how to use this, var roomJoinMessage = 'your message goes here';
//these variables are for enabling / disabling the banned artist / song matching
//they correspond to the bannedArtist array below which is where you put both artists and songs regardless or which you are attempting to match for
//if they are both set to false no attempt to match will occur
var matchArtists = true; //set this true to enable banned artist matching
var matchSongs = true; //set this true to enable banned song matching
//note that anything added to the script manually will have to be removed from the script manually
//all the values currently in these arrays are examples and can be removed.
global.bannedArtists = ['dj tiesto', 'skrillex', 'lil wayne', 't-pain', 'tpain', 'katy perry', 'eminem', //banned artist / song list
'porter robinson', 'gorgoroth', 'justin bieber', 'deadmau5', //see the function formatBannedArtists below if you want to
'nosia', 'infected mushroom', //know what its doing
'spongebob squarepants', 'usher'
];
global.bannedUsers = ['#', 'bob', '535253533353', 'joe']; //banned users list, put userids in string form here for permanent banning(put their name after their userid to tell who is banned).
global.bannedFromStage = ['636473737373', 'bob', '535253533353', 'joe']; //put userids in here to ban from djing permanently(put their name after their userid to tell who is banned)
global.vipList = [];
/* this is the vip list, it accepts userids as input, this is for when you have a special guest or guests in your room and you only
want to hear them dj, leave this empty unless you want everyone other than the people whos userids are in the vip list to be automatically kicked from stage.
*/
var isRefreshing = true; //whether or not /refresh can be used or not (true = yes, false = no)
var amountOfTimeToRefresh = 60; //the amount of seconds someone has to use the refresh command(if enabled)
//these variables set features to on or off as the default when the bot starts up,
//most of them can be changed with commands while the bot is running
// true = on, false = off
var HowManyVotesToSkip = 2; //how many votes for a song to get skipped(default value, only works if voteSkip = true)
var getonstage = true; //autodjing(on by default)
var queue = true; //queue(on by default)
var AFK = true; //afk limit(on by default), this is for the dj's on stage
var MESSAGE = true; //room message(on by default), the bot says your room info in intervals of whatever the howOftenToRepeatMessage variable above is set to in minutes
var defaultMessage = true;
/*This corresponds to the MESSAGE variable directly above, if true it will give you the default repeat message along with your room info, if false it will only say your room info.
(only works when MESSAGE = true) (this feature is on by default)
*/
var GREET = true; //room greeting when someone joins the room(on by default)
var voteSkip = false; //voteskipping(off by default)
var roomAFK = false; //audience afk limit(off by default)
var SONGSTATS = true; //song stats after each song(on by default)
var kickTTSTAT = false; //kicks the ttstats bot when it tries to join the room(off by default)
var LIMIT = true; //song length limit (on by default)
var PLAYLIMIT = false; //song play limit, this is for the playLimit variable up above(off by default)
var autoSnag = true; //auto song adding(different from every song adding), tied to howManyVotes up above, (off by default)
var autoBop = true; //choose whether the bot will autobop for each song or not(against the rules but i leave it up to you) (off by default)
var afkThroughPm = true; //choose whether afk warnings(for dj's on stage) will be given through the pm or the chatbox (false = chatbox, true = pm message)
var greetThroughPm = false; //choose whether greeting message is through the pm or the chatbox(false = chatbox, true = pm), (only works when greeting message is turned on) (off by default)
var repeatMessageThroughPm = false;
/*choose whether the repeating room message(the one corresponding to MESSAGE up above) will be through the chatbox or the pm,
(false = through the chatbox, true = through the pm) (MESSAGE must equal true for this to work) (this feature is off by default)
*/
//this is for the event messages
//This cycles through all the different messages that you enter into this array. one message per time cycle, once it gets to the end of your messages it starts over again
var eventMessageRepeatTime = 15; //how long in minutes between event messages(must have EVENTMESSAGE = true to see any messages)
var eventMessageThroughPm = false; //determines whether event message will be pmmed or said in chat, false = chatbox, true = pm box
var EVENTMESSAGE = false; //this disables / enables event message on startup - true = enabled, false = disabled
//the messages in here are examples, it is recommended that you clear them before using
global.eventMessages = ['hello there', //enter your different event messages here, any messages that you want repeated
'message 2' +
' this is an example message, multiple lines should be separate strings added together',
'this is a test'
];
/************************************EndSetUp**********************************************************************/
//do not change the values of any of the global variables below unless you know what you are doing, the discriptions given are for reference only
var defaultPlayLimit = playLimit; //saves the default value for the play limit
var spamLimit = 3; //number of times a user can spam being kicked off the stage within 10 secs
var myId = null; //the userid of the person using the /fanme command, speak event only
var detail = null; //the discription given in the "room" tab of the room that the bot is in
var current = null; //the number of dj's on stage, gets reset every song
var name = null; //the name of the person using the person who activated the speak event
var dj = null; //the name of the currently playing dj
var condition = null; //is the person using a command a moderator? true or false
var index = null; //the index returned when using unban commands
var song = null; //the name of the current song
var album = null; //the album name of the current song
var genre = null; //the genre of the current song
var skipOn = null; //if true causes the bot to skip every song it plays, toggled on and off by commands
var snagSong = false; //if true causes the bot to add every song that plays to its queue
var checkWhoIsDj = null; //the userid of the currently playing dj
var randomOnce = 0; //a flag used to check if the /randomSong command has already been activated, 0 is no, 1 is yes
var voteCountSkip = 0; //the current amount of votes for a song skip, gets reset every song
var votesLeft = HowManyVotesToSkip; //a countdown of the amount of votes needed till a song gets skipped
var sayOnce = true; //makes it so that the queue timeout can only be used once per per person, stops the bot from spamming
var artist = null; //the artist name of the currently playing song
var getSong = null; //the id3 tag id of the currently playing song
var informTimer = null; //holds the timeout for the /inform command, null lets it know that it hasn't already been set
var upVotes = null; //the amount of upvotes or "awesome's" that the currently playing song has recieved
var downVotes = null; //the amount of downvotes or "lame's" that the currently playing song has recieved
var whoSnagged = 0; //the amount of people who have added the currently playing song to their dj queue
var beginTime = null; //the current time in milliseconds when the bot has started, used for the /uptime
var endTime = null; //the current time in milliseconds when the /uptime is actually used
var roomName = null; //the name of the room, example "straight chillin" would be the format for the straight chillin room...
var ttRoomName = null; //the url extension of the room name, example "straight_chillin16" would be the format
var THEME = false; //has a current theme been set? true or false. handled by commands
var whatIsTheme = null; //this holds a string which is set by the /setTheme command
var messageCounter = 0; //this is for the array of messages, it lets it know which message it is currently on, resets to 0 after cycling through all of them
var ALLREADYCALLED = false; //resets votesnagging so that it can be called again
var thisHoldsThePlaylist = null; //holds a copy of the playlist
var netwatchdogTimer = null; // Used to detect internet connection dropping out
var checkActivity = Date.now();
var attemptToReconnect = null; //used for reconnecting to the bots room if its not in there (only works if internet connection is working)
var returnToRoom = true; //used to toggle on and off the bot reconnecting to its room(it toggles off when theres no internet connection because it only works when its connected to turntable.fm)
var wserrorTimeout = null; //this is for the setTimeout in ws error
var errorMessage = null; //the error message you get when trying to connect to the room
var bannedArtistsMatcher; //holds the regular expression for banned artist / song matching
var autoDjingTimer = null; //governs the timer for the bot's auto djing
global.playLimitOfRefresher = []; //holds a copy of the number of plays for people who have used the /refresh command
global.refreshList = []; //this holds the userid's of people who have used the /refresh command
global.refreshTimer = []; //this holds the timers of people who have used the /refresh command
global.modpm = []; //holds the userid's of everyone in the /modpm feature
global.warnme = []; //holds the userid's of everyone using the /warnme feature
global.timer = []; //holds the timeout of everyone who has been spamming the stage, resets their spam count if their timer completes
global.greetingTimer = []; //holds the timeout for people that join the room, if someone rejoins before their timeout completes their timer is reset
global.djs20 = []; //holds the song count that each of the dj's on stage have played
global.people = []; //holds the userid's of everyone who is kicked off stage for the spam limit
global.lastSeen = {}; //holds a date object to be used for the dj afk timer, there are different ones because they have different timeouts
global.lastSeen1 = {}; //holds a date object to be used for the dj afk timer
global.lastSeen2 = {}; //holds a date object to be used for the dj afk timer
global.lastSeen3 = {}; //holds a date object to be used for the audience afk limit
global.lastSeen4 = {}; //holds a date object to be used for the audience afk limit
global.afkPeople = []; //holds the userid of everyone who has used the /afk command
global.blackList = []; //holds the userid of everyone who is in the command based banned from the room list
global.stageList = []; //holds the userid of everyone who is in the command based banned from stage list
global.userIds = []; //holds the userid's of everyone who is in the room
global.checkVotes = []; //holds the userid's of everyone who has voted for the currently playing song to be skipped, is cleared every song
global.theUsersList = []; //holds the name and userid of everyone in the room
global.modList = []; //holds the userid of everyone who is a moderator in the room
global.escortList = []; //holds the userid of everyone who has used the /escortme command, auto removed when the person leaves the stage
global.currentDjs = []; //holds the userid of all the dj's who are on stage currently
global.queueList = []; //holds the name and userid of everyone in the queue
global.queueName = []; //holds just the name of everyone who is in the queue
global.myTime = []; //holds a date object for everyone in the room, which represents the time when they joined the room, resets every time the person rejoins
global.curSongWatchdog = null; //used to hold the timer for stuck songs
global.takedownTimer = null; //used to hold the timer that fires after curSongWatchDog which represents the time a person with a stuck song has left to skip their song
global.lastdj = null; //holds the userid of the currently playing dj
global.songLimitTimer = null; //holds the timer used to remove a dj off stage if they don't skip their song in time, and their song has exceeded the max allowed song time
global.beginTimer = null; //holds the timer the auto removes dj's from the queue if they do not get on stage within the allowed time period
var bot = new Bot(AUTH, USERID, ROOMID); //initializes the bot
bot.listen(process.env.PORT,process.env.IP); //needed for running the bot on a server
bot.on('disconnected', function (data) {
});
var checkIfConnected = function ()
{
if (attemptToReconnect === null) //if a reconnection attempt is already in progress, do not attempt it
{
if (bot._isAuthenticated) // if bot is actually connected to turntable use the speaking method
{
var currentActivity = (Date.now() - checkActivity) / 1000 / 60;
if (currentActivity > 30) //if greater than 30 minutes of no talking
{
bot.speak('ping', function (callback) //attempt to talk
{
if (callback.success === false) //if it fails
{
attempToReconnect();
}
});
}
}
else //else attempt to reconnect right away
{
attempToReconnect();
}
}
};
setInterval(checkIfConnected, 5000);
//makes the bot attempt to reconnect to the room
function attempToReconnect()
{
attemptToReconnect = setInterval(function ()
{
if (bot._isAuthenticated)
{
whichMessage = true;
console.log('it looks like your bot is not in it\'s room. attempting to reconnect now....');
}
else
{
whichMessage = false;
console.log('connection with turntable lost, waiting for connection to come back...');
}
bot.roomRegister(ROOMID, function (data)
{
if (data.success === true)
{
errorMessage = null;
clearInterval(attemptToReconnect);
attemptToReconnect = null;
checkActivity = Date.now();
if (whichMessage)
{
console.log('the bot has reconnected to the room ' +
'specified by your choosen roomid');
}
else
{
console.log('connection with turntable is back!');
}
}
else
{
if (errorMessage === null && typeof data.err === 'string')
{
errorMessage = data.err;
}
}
});
}, 1000 * 10);
};
//whichFunction represents which justSaw object do you want to access
global.justSaw = function (uid, whichFunction)
{
switch (whichFunction)
{
case 'justSaw':
return lastSeen[uid] = Date.now();
break;
case 'justSaw1':
return lastSeen1[uid] = Date.now();
break;
case 'justSaw2':
return lastSeen2[uid] = Date.now();
break;
case 'justSaw3':
return lastSeen3[uid] = Date.now();
break;
case 'justSaw4':
return lastSeen4[uid] = Date.now();
break;
}
}
//whichFunction represents which justSaw object do you want to access
//num is the time in minutes till afk timeout
//userid is the person's userid
global.isAfk = function (userId, num, whichFunction)
{
//which last seen object to use?
switch (whichFunction)
{
case 'isAfk':
var last = lastSeen[userId];
break;
case 'isAfk1':
var last = lastSeen1[userId];
break;
case 'isAfk2':
var last = lastSeen2[userId];
break;
case 'isAfk3':
var last = lastSeen3[userId];
break;
case 'isAfk4':
var last = lastSeen4[userId];
break;
}
var age_ms = Date.now() - last;
var age_m = Math.floor(age_ms / 1000 / 60);
if (age_m >= num)
{
return true;
}
return false;
};
global.updateAfkPostionOfUser = function (userid)
{
//updates the afk position of the speaker.
if (AFK === true || roomAFK === true)
{
justSaw(userid, 'justSaw');
justSaw(userid, 'justSaw1');
justSaw(userid, 'justSaw2');
justSaw(userid, 'justSaw3');
justSaw(userid, 'justSaw4');
}
};
//removes afk dj's after afklimit is up.
global.afkCheck = function ()
{
for (var i = 0; i < currentDjs.length; i++)
{
afker = currentDjs[i]; //Pick a DJ
var isAfkMaster = masterIds.indexOf(afker); //master ids check
var whatIsAfkerName = theUsersList.indexOf(afker) + 1;
if ((isAfk(afker, (afkLimit - 5), 'isAfk1')) && AFK === true)
{
if (afker != USERID && isAfkMaster == -1)
{
if (afkThroughPm === false)
{
bot.speak('@' + theUsersList[whatIsAfkerName] + ' you have 5 minutes left of afk, chat or awesome please.');
}
else
{
bot.pm('you have 5 minutes left of afk, chat or awesome please.', afker);
}
justSaw(afker, 'justSaw1');
}
}
if ((isAfk(afker, (afkLimit - 1), 'isAfk2')) && AFK === true)
{
if (afker != USERID && isAfkMaster == -1)
{
if (afkThroughPm === false)
{
bot.speak('@' + theUsersList[whatIsAfkerName] + ' you have 1 minute left of afk, chat or awesome please.');
}
else
{
bot.pm('you have 1 minute left of afk, chat or awesome please.', afker);
}
justSaw(afker, 'justSaw2');
}
}
if ((isAfk(afker, afkLimit, 'isAfk')) && AFK === true)
{ //if Dj is afk then
if (afker != USERID && isAfkMaster == -1) //checks to see if afker is a mod or a bot or the current dj, if they are is does not kick them.
{
if (afker != checkWhoIsDj)
{
if (afkThroughPm === false)
{
bot.speak('@' + theUsersList[whatIsAfkerName] + ' you are over the afk limit of ' + afkLimit + ' minutes.');
}
else
{
bot.pm('you are over the afk limit of ' + afkLimit + ' minutes.', afker);
}
justSaw(afker, 'justSaw1');
justSaw(afker, 'justSaw2');
justSaw(afker, 'justSaw');
bot.remDj(afker); //remove them
}
}
}
}
};
setInterval(afkCheck, 5000); //This repeats the check every five seconds.
//this removes people on the floor, not the djs
roomAfkCheck = function ()
{
for (var i = 0; i < userIds.length; i++)
{
var afker2 = userIds[i]; //Pick a DJ
var isAfkMod = modList.indexOf(afker2);
var isDj = currentDjs.indexOf(afker2);
if ((isAfk(afker2, (roomafkLimit - 1), 'isAfk3')) && roomAFK === true)
{
if (afker2 != USERID && isDj == -1 && isAfkMod == -1)
{
bot.pm('you have 1 minute left of afk, chat or awesome please.', afker2);
justSaw(afker2, 'justSaw3');
}
}
if ((isAfk(afker2, roomafkLimit, 'isAfk4')) && roomAFK === true)
{ //if person is afk then
if (afker2 != USERID && isAfkMod == -1) //checks to see if afker is a mod or a bot or a dj, if they are is does not kick them.
{
if (isDj == -1)
{
bot.pm('you are over the afk limit of ' + roomafkLimit + ' minutes.', afker2);
bot.boot(afker2, 'you are over the afk limit');
justSaw(afker2, 'justSaw3');
justSaw(afker2, 'justSaw4');
}
}
}
}
};
setInterval(roomAfkCheck, 5000) //This repeats the check every five seconds.
//this function handles removing people from the queue after holding their spot open for a certain amount of time
queueCheck15 = function ()
{
//if queue is turned on once someone leaves the stage the first person
//in line has 60 seconds to get on stage before being remove from the queue
if (queue === true && queueList.length !== 0)
{
if (sayOnce === true && (refreshList.length + currentDjs.length) < 5)
{
sayOnce = false;
if ((howLongStage / 60) < 1) //is it seconds
{
bot.speak('@' + queueName[0] + ' you have ' + howLongStage + ' seconds to get on stage.');
}
else if ((howLongStage / 60) == 1) //is it one minute
{
var minute = Math.floor((howLongStage / 60));
bot.speak('@' + queueName[0] + ' you have ' + minute + ' minute to get on stage.');
}
else if ((howLongStage / 60) > 1) //is it more than one minute
{
var minutes = Math.floor((howLongStage / 60));
bot.speak('@' + queueName[0] + ' you have ' + minutes + ' minutes to get on stage.');
}
beginTimer = setTimeout(function ()
{
queueList.splice(0, 2);
queueName.splice(0, 1);
sayOnce = true;
}, howLongStage * 1000); //timeout variably set
}
}
}
setInterval(queueCheck15, 5000) //repeats the check every five seconds.
vipListCheck = function ()
{
//this kicks all users off stage when the vip list is not empty
if (vipList.length !== 0 && currentDjs.length != vipList.length)
{
for (var p = 0; p < currentDjs.length; p++)
{
var checkIfVip = vipList.indexOf(currentDjs[p]);
if (checkIfVip == -1 && currentDjs[p] != USERID)
{
bot.remDj(currentDjs[p]);
}
}
}
}
setInterval(vipListCheck, 5000) //repeats the check every five seconds.
//this is for the event messages array
global.eventMessagesIterator = function ()
{
if (EVENTMESSAGE == true && eventMessages.length !== 0)
{
if (messageCounter == eventMessages.length)
{
messageCounter = 0; //if end of event messages array reached, reset counter
}
if (eventMessageThroughPm == false) //if set to send messages through chatbox, do so
{
bot.speak(eventMessages[messageCounter] + "");
}
else //else send message through pm
{
for (var jio = 0; jio < userIds.length; jio++)
{
bot.pm(eventMessages[messageCounter] + "", userIds[jio]);
}
}
++messageCounter; //increment message counter
}
}
setInterval(eventMessagesIterator, eventMessageRepeatTime * 60 * 1000) //repeats check
repeatMessage = function ()
{
if (MESSAGE === true && typeof detail !== 'undefined')
{
if (repeatMessageThroughPm === false) //if not doing through the pm
{
if (defaultMessage === true) //if using default message
{
bot.speak('Welcome to ' + roomName + ', ' + detail); //set the message you wish the bot to repeat here i.e rules and such.
}
else
{
bot.speak('' + detail);
}
}
else
{
if (defaultMessage === true)
{
for (var jkl = 0; jkl < userIds.length; jkl++)
{
bot.pm('Welcome to ' + roomName + ', ' + detail, userIds[jkl]); //set the message you wish the bot to repeat here i.e rules and such.
}
}
else
{
for (var lkj = 0; lkj < userIds.length; lkj++)
{
bot.pm('' + detail, userIds[lkj]); //set the message you wish the bot to repeat here i.e rules and such.
}
}
}
}
};
setInterval(repeatMessage, howOftenToRepeatMessage * 60 * 1000) //repeats this message every 15 mins if /messageOn has been used.
//verifies the integrity of the users list every 15 minutes
global.verifyUsersList = function ()
{
//only execute when not disconnected
if (bot._isAuthenticated)
{
bot.roomInfo(false, function (data)
{
if (typeof data.users === 'object')
{
var theUsersListOkay = true; //assume it will not need to be rebuilt
//if the length of the users list does not match
//the amount of people in the room
if (theUsersList.length != (data.users.length * 2))
{
theUsersListOkay = false;
}
//only run this test if it passed the first one
if (theUsersListOkay)
{
//if any undefined values are found
for (var i = 0; i < theUsersList.length; i++)
{
if (typeof theUsersList[i] === 'undefined')
{
theUsersListOkay = false;
break;
}
}
}
//if data got corrupted then rebuild theUsersList array
if (!theUsersListOkay)
{
theUsersList = [];
for (var i = 0; i < data.users.length; i++)
{
if (typeof data.users[i] !== 'undefined')
{
//userid then the name
theUsersList.push(data.users[i].userid, data.users[i].name);
}
}
}
}
});
}
}
setInterval(verifyUsersList, 1000 * 60 * 15); //check every 15 minutes
//governs whether the bot gets on or off the stage automatically (autodjing)
global.autoDjing = function ()
{
if (autoDjingTimer != null)
{
clearTimeout(autoDjingTimer);
autoDjingTimer = null;
}
autoDjingTimer = setTimeout(function ()
{
var isBotAlreadyOnStage = currentDjs.indexOf(USERID);
if (isBotAlreadyOnStage == -1) //if the bot is not already on stage
{
if (currentDjs.length >= 1 && currentDjs.length <= whenToGetOnStage && queueList.length === 0)
{
if (getonstage === true && vipList.length === 0 && refreshList.length === 0)
{
bot.addDj();
}
}
}
else //else it is on stage
{
if (currentDjs.length >= whenToGetOffStage && getonstage === true && checkWhoIsDj != USERID)
{
bot.remDj();
}
}
}, 1000 * 10); //delay for 10 seconds
};
//adds a song to the end of the bots queue if it is not already contained in the bots queue
global.addSongIfNotAlreadyInPlaylist = function (bool)
{
if (thisHoldsThePlaylist !== null && getSong !== null)
{
var found = false;
for (var igh = 0; igh < thisHoldsThePlaylist.length; igh++)
{
if (thisHoldsThePlaylist[igh]._id == getSong)
{
found = true;
break;
}
}
if (!found)
{
bot.playlistAdd(getSong, -1); //add song to the end of the playlist
var tempSongHolder = {
_id: getSong
};
thisHoldsThePlaylist.push(tempSongHolder);
if (bool) //whether the bot will show the heart animation or not
{
bot.snag();
}
}
}
};
global.warnMeCall = function ()
{
if (warnme.length != 0) //is there anyone in the warnme?
{
var whatIsPosition = currentDjs.indexOf(checkWhoIsDj); //what position are they
if (whatIsPosition == currentDjs.length - 1) //if 5th dj is playing, check guy on the left
{
var areTheyNext = warnme.indexOf(currentDjs[0]);
if (areTheyNext != -1) //is the next dj up in the warnme?
{
bot.pm('your song is up next!', currentDjs[0]);
warnme.splice(areTheyNext, 1);
}
}
else
{
var areTheyNext = warnme.indexOf(currentDjs[whatIsPosition + 1]);
if (areTheyNext != -1) //is the next dj up in the warnme?
{
bot.pm('your song is up next!', currentDjs[whatIsPosition + 1]);
warnme.splice(areTheyNext, 1);
}
}
}
}
//checks to see if a command user is contained within the moderator list or not
global.checkIfUserIsMod = function (userid)
{
var modIndex = modList.indexOf(userid);
if (modIndex != -1)
{
condition = true;
}
else
{
condition = false;
}
};
//makes sure the person who pmmed the bot a command is in the room
global.checkToseeIfPmmerIsInRoom = function (userid)
{
var isInRoom = theUsersList.indexOf(userid);
if (isInRoom != -1)
{
isInRoom = true;
}
else
{
isInRoom = false;
}
return isInRoom;
};
//increments a persons spam counter when they get kicked off stage for some reason
//after 10 seconds if it has not just been incremented then the counter is reset
global.incrementSpamCounter = function (userid)
{
if (typeof people[userid] != 'undefined')
{
++people[userid].spamCount;
}
if (timer[userid] !== null)
{
clearTimeout(timer[userid]);
timer[userid] = null;
}
timer[userid] = setTimeout(function ()
{
people[userid] = {
spamCount: 0
};
}, 10 * 1000);
};
//formats the banned artist array to be used in a regex expression
global.formatBannedArtists = function ()
{
if (bannedArtists.length !== 0)
{
var tempArray = [];
var tempString = '(';
//add a backslash in front of all special characters
for (var i = 0; i < bannedArtists.length; i++)
{
tempArray.push(bannedArtists[i].replace(/([-[\]{}()*^=!:+?.,\\^$|#\s])/g, "\\$1"));
}
//join everything into one string
for (var i = 0; i < bannedArtists.length; i++)
{
if (i < bannedArtists.length - 1)
{
tempString += tempArray[i] + '|';
}
else
{
tempString += tempArray[i] + ')';
}
}
//create regular expression
bannedArtistsMatcher = new RegExp('\\b' + tempString + '\\b', 'i');
}
}
global.clearTimers = function ()
{
//this is for the /inform command
if (informTimer !== null)
{
clearTimeout(informTimer);
informTimer = null;
if (typeof theUsersList[theUsersList.indexOf(lastdj) + 1] !== 'undefined')
{
bot.speak("@" + theUsersList[theUsersList.indexOf(lastdj) + 1] + ", Thanks buddy ;-)");
}
else
{
bot.speak('Thanks buddy ;-)');
}
}
//this is for the song length limit
if (songLimitTimer !== null)
{
clearTimeout(songLimitTimer);
songLimitTimer = null;
if (typeof theUsersList[theUsersList.indexOf(lastdj) + 1] !== 'undefined')
{
bot.speak("@" + theUsersList[theUsersList.indexOf(lastdj) + 1] + ", Thanks buddy ;-)");
}
else
{
bot.speak('Thanks buddy ;-)');
}
}
// If watch dog has been previously set,
// clear since we've made it to the next song
if (curSongWatchdog !== null)
{
clearTimeout(curSongWatchdog);
curSongWatchdog = null;
}
// If takedown Timer has been set,
// clear since we've made it to the next song
if (takedownTimer !== null)
{
clearTimeout(takedownTimer);
takedownTimer = null;
if (typeof theUsersList[theUsersList.indexOf(lastdj) + 1] !== 'undefined')
{
bot.speak("@" + theUsersList[theUsersList.indexOf(lastdj) + 1] + ", Thanks buddy ;-)");
}
else
{
bot.speak('Thanks buddy ;-)');
}
}
};
//stuck song detection, song length limit, /inform command
global.checkOnNewSong = function (data)
{
var length = data.room.metadata.current_song.metadata.length;
var masterIndex; //used to tell whether current dj is on the master id's list or not
//clears timers if previously set
clearTimers();
// Set this after processing things from last timer calls
lastdj = data.room.metadata.current_dj;
masterIndex = masterIds.indexOf(lastdj); //master id's check
// Set a new watchdog timer for the current song.
curSongWatchdog = setTimeout(function ()
{
curSongWatchdog = null;
if (typeof theUsersList[theUsersList.indexOf(lastdj) + 1] !== 'undefined')
{
bot.speak("@" + theUsersList[theUsersList.indexOf(lastdj) + 1] + ", you have 20 seconds to skip your stuck song before you are removed");
}
else
{
bot.speak("current dj, you have 20 seconds to skip your stuck song before you are removed");
}
//START THE 20 SEC TIMER
takedownTimer = setTimeout(function ()
{
takedownTimer = null;
bot.remDj(lastdj); // Remove Saved DJ from last newsong call
}, 20 * 1000); // Current DJ has 20 seconds to skip before they are removed
}, (length + 10) * 1000); //Timer expires 10 seconds after the end of the song, if not cleared by a newsong
//this boots the user if their song is over the length limit
if ((length / 60) >= songLengthLimit)
{
if (lastdj == USERID || masterIndex == -1) //if dj is the bot or not a master
{
if (LIMIT === true)
{
if (typeof theUsersList[theUsersList.indexOf(lastdj) + 1] !== 'undefined')
{
bot.speak("@" + theUsersList[theUsersList.indexOf(lastdj) + 1] + ", your song is over " + songLengthLimit + " mins long, you have 20 seconds to skip before being removed.");
}
else
{
bot.speak('current dj, your song is over ' + songLengthLimit + ' mins long, you have 20 seconds to skip before being removed.');
}
//START THE 20 SEC TIMER
songLimitTimer = setTimeout(function ()
{
songLimitTimer = null;
bot.remDj(lastdj); // Remove Saved DJ from last newsong call
}, 20 * 1000); // Current DJ has 20 seconds to skip before they are removed
}
}
}
}
bot.on('ready', function (data)
{
//format the bannedArtists list at runtime
formatBannedArtists();
});
//checks at the beggining of the song
bot.on('newsong', function (data)
{
//resets counters and array for vote skipping
checkVotes = [];
voteCountSkip = 0;
votesLeft = HowManyVotesToSkip;
whoSnagged = 0;
upVotes = 0;
downVotes = 0;
ALLREADYCALLED = false; //resets votesnagging so that it can be called again
//procedure for getting song tags
song = data.room.metadata.current_song.metadata.song;
album = data.room.metadata.current_song.metadata.album;
genre = data.room.metadata.current_song.metadata.genre;
artist = data.room.metadata.current_song.metadata.artist;
getSong = data.room.metadata.current_song._id;
//set information
current = data.room.metadata.djcount; //the number of dj's on stage
detail = data.room.description; //set room description again in case it was changed
checkWhoIsDj = data.room.metadata.current_dj; //used to check who the currently playing dj is.
dj = data.room.metadata.current_song.djname; //used to get current dj's name.
//adds a song to the end of your bots queue