forked from basicBot/source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basicBot.js
3756 lines (3562 loc) · 179 KB
/
basicBot.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
/**
*Copyright 2015 bscBot
*Modifications (including forks) of the code to fit personal needs are allowed only for personal use and should refer back to the original source.
*This software is not for profit, any extension, or unauthorised person providing this software is not authorised to be in a position of any monetary gain from this use of this software. Any and all money gained under the use of the software (which includes donations) must be passed on to the original author.
*/
(function () {
/*window.onerror = function() {
var room = JSON.parse(localStorage.getItem("basicBotRoom"));
window.location = 'https://stg.plug.dj' + room.name;
};*/
API.getWaitListPosition = function(id){
if(typeof id === 'undefined' || id === null){
id = API.getUser().id;
}
var wl = API.getWaitList();
for(var i = 0; i < wl.length; i++){
if(wl[i].id === id){
return i;
}
}
return -1;
};
var kill = function () {
clearInterval(basicBot.room.autodisableInterval);
clearInterval(basicBot.room.afkInterval);
basicBot.status = false;
};
// This socket server is used solely for statistical and troubleshooting purposes.
// This server may not always be up, but will be used to get live data at any given time.
var socket = function () {
function loadSocket() {
SockJS.prototype.msg = function(a){this.send(JSON.stringify(a))};
sock = new SockJS('https://benzi.io:4964/socket');
sock.onopen = function() {
console.log('Connected to socket!');
sendToSocket();
};
sock.onclose = function() {
console.log('Disconnected from socket, reconnecting every minute ..');
var reconnect = setTimeout(function(){ loadSocket() }, 60 * 1000);
};
sock.onmessage = function(broadcast) {
var rawBroadcast = broadcast.data;
var broadcastMessage = rawBroadcast.replace(/["\\]+/g, '');
API.chatLog(broadcastMessage);
console.log(broadcastMessage);
};
}
if (typeof SockJS == 'undefined') {
$.getScript('https://cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js', loadSocket);
} else loadSocket();
}
var sendToSocket = function () {
var basicBotSettings = basicBot.settings;
var basicBotRoom = basicBot.room;
var basicBotInfo = {
time: Date.now(),
version: basicBot.version
};
var data = {users:API.getUsers(),userinfo:API.getUser(),room:location.pathname,basicBotSettings:basicBotSettings,basicBotRoom:basicBotRoom,basicBotInfo:basicBotInfo};
return sock.msg(data);
};
var storeToStorage = function () {
localStorage.setItem("basicBotsettings", JSON.stringify(basicBot.settings));
localStorage.setItem("basicBotRoom", JSON.stringify(basicBot.room));
var basicBotStorageInfo = {
time: Date.now(),
stored: true,
version: basicBot.version
};
localStorage.setItem("basicBotStorageInfo", JSON.stringify(basicBotStorageInfo));
};
var subChat = function (chat, obj) {
if (typeof chat === "undefined") {
API.chatLog("There is a chat text missing.");
console.log("There is a chat text missing.");
return "[Error] No text message found.";
// TODO: Get missing chat messages from source.
}
var lit = '%%';
for (var prop in obj) {
chat = chat.replace(lit + prop.toUpperCase() + lit, obj[prop]);
}
return chat;
};
var loadChat = function (cb) {
if (!cb) cb = function () {
};
$.get("https://rawgit.com/bscBot/source/master/lang/langIndex.json", function (json) {
var link = basicBot.chatLink;
if (json !== null && typeof json !== "undefined") {
langIndex = json;
link = langIndex[basicBot.settings.language.toLowerCase()];
if (basicBot.settings.chatLink !== basicBot.chatLink) {
link = basicBot.settings.chatLink;
}
else {
if (typeof link === "undefined") {
link = basicBot.chatLink;
}
}
$.get(link, function (json) {
if (json !== null && typeof json !== "undefined") {
if (typeof json === "string") json = JSON.parse(json);
basicBot.chat = json;
cb();
}
});
}
else {
$.get(basicBot.chatLink, function (json) {
if (json !== null && typeof json !== "undefined") {
if (typeof json === "string") json = JSON.parse(json);
basicBot.chat = json;
cb();
}
});
}
});
};
var retrieveSettings = function () {
var settings = JSON.parse(localStorage.getItem("basicBotsettings"));
if (settings !== null) {
for (var prop in settings) {
basicBot.settings[prop] = settings[prop];
}
}
};
var retrieveFromStorage = function () {
var info = localStorage.getItem("basicBotStorageInfo");
if (info === null) API.chatLog(basicBot.chat.nodatafound);
else {
var settings = JSON.parse(localStorage.getItem("basicBotsettings"));
var room = JSON.parse(localStorage.getItem("basicBotRoom"));
var elapsed = Date.now() - JSON.parse(info).time;
if ((elapsed < 1 * 60 * 60 * 1000)) {
API.chatLog(basicBot.chat.retrievingdata);
for (var prop in settings) {
basicBot.settings[prop] = settings[prop];
}
basicBot.room.users = room.users;
basicBot.room.afkList = room.afkList;
basicBot.room.historyList = room.historyList;
basicBot.room.mutedUsers = room.mutedUsers;
//basicBot.room.autoskip = room.autoskip;
basicBot.room.roomstats = room.roomstats;
basicBot.room.messages = room.messages;
basicBot.room.queue = room.queue;
basicBot.room.newBlacklisted = room.newBlacklisted;
API.chatLog(basicBot.chat.datarestored);
}
}
var json_sett = null;
var roominfo = document.getElementById("room-settings");
info = roominfo.textContent;
var ref_bot = "@basicBot=";
var ind_ref = info.indexOf(ref_bot);
if (ind_ref > 0) {
var link = info.substring(ind_ref + ref_bot.length, info.length);
var ind_space = null;
if (link.indexOf(" ") < link.indexOf("\n")) ind_space = link.indexOf(" ");
else ind_space = link.indexOf("\n");
link = link.substring(0, ind_space);
$.get(link, function (json) {
if (json !== null && typeof json !== "undefined") {
json_sett = JSON.parse(json);
for (var prop in json_sett) {
basicBot.settings[prop] = json_sett[prop];
}
}
});
}
};
String.prototype.splitBetween = function (a, b) {
var self = this;
self = this.split(a);
for (var i = 0; i < self.length; i++) {
self[i] = self[i].split(b);
}
var arr = [];
for (var i = 0; i < self.length; i++) {
if (Array.isArray(self[i])) {
for (var j = 0; j < self[i].length; j++) {
arr.push(self[i][j]);
}
}
else arr.push(self[i]);
}
return arr;
};
String.prototype.startsWith = function(str) {
return this.substring(0, str.length) === str;
};
function linkFixer(msg) {
var parts = msg.splitBetween('<a href="', '<\/a>');
for (var i = 1; i < parts.length; i = i + 2) {
var link = parts[i].split('"')[0];
parts[i] = link;
}
var m = '';
for (var i = 0; i < parts.length; i++) {
m += parts[i];
}
return m;
};
function decodeEntities(s) {
var str, temp = document.createElement('p');
temp.innerHTML = s;
str = temp.textContent || temp.innerText;
temp = null;
return str;
};
var botCreator = "The Basic Team";
var botMaintainer = "Benzi"
var botCreatorIDs = ["3851534", "4105209"];
var basicBot = {
version: "2.8.15",
status: false,
name: "basicBot",
loggedInID: null,
scriptLink: "https://rawgit.com/bscBot/source/master/basicBot.js",
cmdLink: "http://git.io/245Ppg",
chatLink: "https://rawgit.com/bscBot/source/master/lang/en.json",
chat: null,
loadChat: loadChat,
retrieveSettings: retrieveSettings,
retrieveFromStorage: retrieveFromStorage,
settings: {
botName: "basicBot",
language: "english",
chatLink: "https://rawgit.com/bscBot/source/master/lang/en.json",
scriptLink: "https://rawgit.com/bscBot/source/master/basicBot.js",
roomLock: false, // Requires an extension to re-load the script
startupCap: 1, // 1-200
startupVolume: 0, // 0-100
startupEmoji: false, // true or false
autowoot: true,
autoskip: false,
smartSkip: true,
cmdDeletion: true,
maximumAfk: 120,
afkRemoval: true,
maximumDc: 60,
bouncerPlus: true,
blacklistEnabled: true,
lockdownEnabled: false,
lockGuard: false,
maximumLocktime: 10,
cycleGuard: true,
maximumCycletime: 10,
voteSkip: false,
voteSkipLimit: 10,
historySkip: false,
timeGuard: true,
maximumSongLength: 10,
autodisable: true,
commandCooldown: 30,
usercommandsEnabled: true,
thorCommand: false,
thorCooldown: 10,
skipPosition: 3,
skipReasons: [
["theme", "This song does not fit the room theme. "],
["op", "This song is on the OP list. "],
["history", "This song is in the history. "],
["mix", "You played a mix, which is against the rules. "],
["sound", "The song you played had bad sound quality or no sound. "],
["nsfw", "The song you contained was NSFW (image or sound). "],
["unavailable", "The song you played was not available for some users. "]
],
afkpositionCheck: 15,
afkRankCheck: "ambassador",
motdEnabled: false,
motdInterval: 5,
motd: "Temporary Message of the Day",
filterChat: true,
etaRestriction: false,
welcome: true,
opLink: null,
rulesLink: null,
themeLink: null,
fbLink: null,
youtubeLink: null,
website: null,
intervalMessages: [],
messageInterval: 5,
songstats: true,
commandLiteral: "!",
blacklists: {
NSFW: "https://rawgit.com/bscBot/custom/master/blacklists/NSFWlist.json",
OP: "https://rawgit.com/bscBot/custom/master/blacklists/OPlist.json",
BANNED: "https://rawgit.com/bscBot/custom/master/blacklists/BANNEDlist.json"
}
},
room: {
name: null,
chatMessages: [],
users: [],
afkList: [],
mutedUsers: [],
bannedUsers: [],
skippable: true,
usercommand: true,
allcommand: true,
afkInterval: null,
//autoskip: false,
autoskipTimer: null,
autodisableInterval: null,
autodisableFunc: function () {
if (basicBot.status && basicBot.settings.autodisable) {
API.sendChat('!afkdisable');
API.sendChat('!joindisable');
}
},
queueing: 0,
queueable: true,
currentDJID: null,
historyList: [],
cycleTimer: setTimeout(function () {
}, 1),
roomstats: {
accountName: null,
totalWoots: 0,
totalCurates: 0,
totalMehs: 0,
launchTime: null,
songCount: 0,
chatmessages: 0
},
messages: {
from: [],
to: [],
message: []
},
queue: {
id: [],
position: []
},
blacklists: {
},
newBlacklisted: [],
newBlacklistedSongFunction: null,
roulette: {
rouletteStatus: false,
participants: [],
countdown: null,
startRoulette: function () {
basicBot.room.roulette.rouletteStatus = true;
basicBot.room.roulette.countdown = setTimeout(function () {
basicBot.room.roulette.endRoulette();
}, 60 * 1000);
API.sendChat(basicBot.chat.isopen);
},
endRoulette: function () {
basicBot.room.roulette.rouletteStatus = false;
var ind = Math.floor(Math.random() * basicBot.room.roulette.participants.length);
var winner = basicBot.room.roulette.participants[ind];
basicBot.room.roulette.participants = [];
var pos = Math.floor((Math.random() * API.getWaitList().length) + 1);
var user = basicBot.userUtilities.lookupUser(winner);
var name = user.username;
API.sendChat(subChat(basicBot.chat.winnerpicked, {name: name, position: pos}));
setTimeout(function (winner, pos) {
basicBot.userUtilities.moveUser(winner, pos, false);
}, 1 * 1000, winner, pos);
}
},
usersUsedThor: []
},
User: function (id, name) {
this.id = id;
this.username = name;
this.jointime = Date.now();
this.lastActivity = Date.now();
this.votes = {
woot: 0,
meh: 0,
curate: 0
};
this.lastEta = null;
this.afkWarningCount = 0;
this.afkCountdown = null;
this.inRoom = true;
this.isMuted = false;
this.lastDC = {
time: null,
position: null,
songCount: 0
};
this.lastKnownPosition = null;
},
userUtilities: {
getJointime: function (user) {
return user.jointime;
},
getUser: function (user) {
return API.getUser(user.id);
},
updatePosition: function (user, newPos) {
user.lastKnownPosition = newPos;
},
updateDC: function (user) {
user.lastDC.time = Date.now();
user.lastDC.position = user.lastKnownPosition;
user.lastDC.songCount = basicBot.room.roomstats.songCount;
},
setLastActivity: function (user) {
user.lastActivity = Date.now();
user.afkWarningCount = 0;
clearTimeout(user.afkCountdown);
},
getLastActivity: function (user) {
return user.lastActivity;
},
getWarningCount: function (user) {
return user.afkWarningCount;
},
setWarningCount: function (user, value) {
user.afkWarningCount = value;
},
lookupUser: function (id) {
for (var i = 0; i < basicBot.room.users.length; i++) {
if (basicBot.room.users[i].id === id) {
return basicBot.room.users[i];
}
}
return false;
},
lookupUserName: function (name) {
for (var i = 0; i < basicBot.room.users.length; i++) {
var match = basicBot.room.users[i].username.trim() == name.trim();
if (match) {
return basicBot.room.users[i];
}
}
return false;
},
voteRatio: function (id) {
var user = basicBot.userUtilities.lookupUser(id);
var votes = user.votes;
if (votes.meh === 0) votes.ratio = 1;
else votes.ratio = (votes.woot / votes.meh).toFixed(2);
return votes;
},
getPermission: function (obj) { //1 requests
var u;
if (typeof obj === "object") u = obj;
else u = API.getUser(obj);
for (var i = 0; i < botCreatorIDs.length; i++) {
if (botCreatorIDs[i].indexOf(u.id) > -1) return 10;
}
if (u.gRole < 2) return u.role;
else {
switch (u.gRole) {
case 2:
return 7;
case 3:
return 8;
case 4:
return 9;
case 5:
return 10;
}
}
return 0;
},
moveUser: function (id, pos, priority) {
var user = basicBot.userUtilities.lookupUser(id);
var wlist = API.getWaitList();
if (API.getWaitListPosition(id) === -1) {
if (wlist.length < 50) {
API.moderateAddDJ(id);
if (pos !== 0) setTimeout(function (id, pos) {
API.moderateMoveDJ(id, pos);
}, 1250, id, pos);
}
else {
var alreadyQueued = -1;
for (var i = 0; i < basicBot.room.queue.id.length; i++) {
if (basicBot.room.queue.id[i] === id) alreadyQueued = i;
}
if (alreadyQueued !== -1) {
basicBot.room.queue.position[alreadyQueued] = pos;
return API.sendChat(subChat(basicBot.chat.alreadyadding, {position: basicBot.room.queue.position[alreadyQueued]}));
}
basicBot.roomUtilities.booth.lockBooth();
if (priority) {
basicBot.room.queue.id.unshift(id);
basicBot.room.queue.position.unshift(pos);
}
else {
basicBot.room.queue.id.push(id);
basicBot.room.queue.position.push(pos);
}
var name = user.username;
return API.sendChat(subChat(basicBot.chat.adding, {name: name, position: basicBot.room.queue.position.length}));
}
}
else API.moderateMoveDJ(id, pos);
},
dclookup: function (id) {
var user = basicBot.userUtilities.lookupUser(id);
if (typeof user === 'boolean') return basicBot.chat.usernotfound;
var name = user.username;
if (user.lastDC.time === null) return subChat(basicBot.chat.notdisconnected, {name: name});
var dc = user.lastDC.time;
var pos = user.lastDC.position;
if (pos === null) return basicBot.chat.noposition;
var timeDc = Date.now() - dc;
var validDC = false;
if (basicBot.settings.maximumDc * 60 * 1000 > timeDc) {
validDC = true;
}
var time = basicBot.roomUtilities.msToStr(timeDc);
if (!validDC) return (subChat(basicBot.chat.toolongago, {name: basicBot.userUtilities.getUser(user).username, time: time}));
var songsPassed = basicBot.room.roomstats.songCount - user.lastDC.songCount;
var afksRemoved = 0;
var afkList = basicBot.room.afkList;
for (var i = 0; i < afkList.length; i++) {
var timeAfk = afkList[i][1];
var posAfk = afkList[i][2];
if (dc < timeAfk && posAfk < pos) {
afksRemoved++;
}
}
var newPosition = user.lastDC.position - songsPassed - afksRemoved;
if (newPosition <= 0) return subChat(basicBot.chat.notdisconnected, {name: name});
var msg = subChat(basicBot.chat.valid, {name: basicBot.userUtilities.getUser(user).username, time: time, position: newPosition});
basicBot.userUtilities.moveUser(user.id, newPosition, true);
return msg;
}
},
roomUtilities: {
rankToNumber: function (rankString) {
var rankInt = null;
switch (rankString) {
case "admin":
rankInt = 10;
break;
case "ambassador":
rankInt = 7;
break;
case "host":
rankInt = 5;
break;
case "cohost":
rankInt = 4;
break;
case "manager":
rankInt = 3;
break;
case "bouncer":
rankInt = 2;
break;
case "residentdj":
rankInt = 1;
break;
case "user":
rankInt = 0;
break;
}
return rankInt;
},
msToStr: function (msTime) {
var ms, msg, timeAway;
msg = '';
timeAway = {
'days': 0,
'hours': 0,
'minutes': 0,
'seconds': 0
};
ms = {
'day': 24 * 60 * 60 * 1000,
'hour': 60 * 60 * 1000,
'minute': 60 * 1000,
'second': 1000
};
if (msTime > ms.day) {
timeAway.days = Math.floor(msTime / ms.day);
msTime = msTime % ms.day;
}
if (msTime > ms.hour) {
timeAway.hours = Math.floor(msTime / ms.hour);
msTime = msTime % ms.hour;
}
if (msTime > ms.minute) {
timeAway.minutes = Math.floor(msTime / ms.minute);
msTime = msTime % ms.minute;
}
if (msTime > ms.second) {
timeAway.seconds = Math.floor(msTime / ms.second);
}
if (timeAway.days !== 0) {
msg += timeAway.days.toString() + 'd';
}
if (timeAway.hours !== 0) {
msg += timeAway.hours.toString() + 'h';
}
if (timeAway.minutes !== 0) {
msg += timeAway.minutes.toString() + 'm';
}
if (timeAway.minutes < 1 && timeAway.hours < 1 && timeAway.days < 1) {
msg += timeAway.seconds.toString() + 's';
}
if (msg !== '') {
return msg;
} else {
return false;
}
},
booth: {
lockTimer: setTimeout(function () {
}, 1000),
locked: false,
lockBooth: function () {
API.moderateLockWaitList(!basicBot.roomUtilities.booth.locked);
basicBot.roomUtilities.booth.locked = false;
if (basicBot.settings.lockGuard) {
basicBot.roomUtilities.booth.lockTimer = setTimeout(function () {
API.moderateLockWaitList(basicBot.roomUtilities.booth.locked);
}, basicBot.settings.maximumLocktime * 60 * 1000);
}
},
unlockBooth: function () {
API.moderateLockWaitList(basicBot.roomUtilities.booth.locked);
clearTimeout(basicBot.roomUtilities.booth.lockTimer);
}
},
afkCheck: function () {
if (!basicBot.status || !basicBot.settings.afkRemoval) return void (0);
var rank = basicBot.roomUtilities.rankToNumber(basicBot.settings.afkRankCheck);
var djlist = API.getWaitList();
var lastPos = Math.min(djlist.length, basicBot.settings.afkpositionCheck);
if (lastPos - 1 > djlist.length) return void (0);
for (var i = 0; i < lastPos; i++) {
if (typeof djlist[i] !== 'undefined') {
var id = djlist[i].id;
var user = basicBot.userUtilities.lookupUser(id);
if (typeof user !== 'boolean') {
var plugUser = basicBot.userUtilities.getUser(user);
if (rank !== null && basicBot.userUtilities.getPermission(plugUser) <= rank) {
var name = plugUser.username;
var lastActive = basicBot.userUtilities.getLastActivity(user);
var inactivity = Date.now() - lastActive;
var time = basicBot.roomUtilities.msToStr(inactivity);
var warncount = user.afkWarningCount;
if (inactivity > basicBot.settings.maximumAfk * 60 * 1000) {
if (warncount === 0) {
API.sendChat(subChat(basicBot.chat.warning1, {name: name, time: time}));
user.afkWarningCount = 3;
user.afkCountdown = setTimeout(function (userToChange) {
userToChange.afkWarningCount = 1;
}, 90 * 1000, user);
}
else if (warncount === 1) {
API.sendChat(subChat(basicBot.chat.warning2, {name: name}));
user.afkWarningCount = 3;
user.afkCountdown = setTimeout(function (userToChange) {
userToChange.afkWarningCount = 2;
}, 30 * 1000, user);
}
else if (warncount === 2) {
var pos = API.getWaitListPosition(id);
if (pos !== -1) {
pos++;
basicBot.room.afkList.push([id, Date.now(), pos]);
user.lastDC = {
time: null,
position: null,
songCount: 0
};
API.moderateRemoveDJ(id);
API.sendChat(subChat(basicBot.chat.afkremove, {name: name, time: time, position: pos, maximumafk: basicBot.settings.maximumAfk}));
}
user.afkWarningCount = 0;
}
}
}
}
}
}
},
smartSkip: function (reason) {
var dj = API.getDJ();
var id = dj.id;
var waitlistlength = API.getWaitList().length;
var locked = false;
basicBot.room.queueable = false;
if (waitlistlength == 50) {
basicBot.roomUtilities.booth.lockBooth();
locked = true;
}
setTimeout(function (id) {
API.moderateForceSkip();
setTimeout(function () {
if (typeof reason !== 'undefined') {
API.sendChat(reason);
}
}, 500);
basicBot.room.skippable = false;
setTimeout(function () {
basicBot.room.skippable = true
}, 5 * 1000);
setTimeout(function (id) {
basicBot.userUtilities.moveUser(id, basicBot.settings.skipPosition, false);
basicBot.room.queueable = true;
if (locked) {
setTimeout(function () {
basicBot.roomUtilities.booth.unlockBooth();
}, 1000);
}
}, 1500, id);
}, 1000, id);
},
changeDJCycle: function () {
var toggle = $(".cycle-toggle");
if (toggle.hasClass("disabled")) {
toggle.click();
if (basicBot.settings.cycleGuard) {
basicBot.room.cycleTimer = setTimeout(function () {
if (toggle.hasClass("enabled")) toggle.click();
}, basicBot.settings.cycleMaxTime * 60 * 1000);
}
}
else {
toggle.click();
clearTimeout(basicBot.room.cycleTimer);
}
// TODO: Use API.moderateDJCycle(true/false)
},
intervalMessage: function () {
var interval;
if (basicBot.settings.motdEnabled) interval = basicBot.settings.motdInterval;
else interval = basicBot.settings.messageInterval;
if ((basicBot.room.roomstats.songCount % interval) === 0 && basicBot.status) {
var msg;
if (basicBot.settings.motdEnabled) {
msg = basicBot.settings.motd;
}
else {
if (basicBot.settings.intervalMessages.length === 0) return void (0);
var messageNumber = basicBot.room.roomstats.songCount % basicBot.settings.intervalMessages.length;
msg = basicBot.settings.intervalMessages[messageNumber];
}
API.sendChat('/me ' + msg);
}
},
updateBlacklists: function () {
for (var bl in basicBot.settings.blacklists) {
basicBot.room.blacklists[bl] = [];
if (typeof basicBot.settings.blacklists[bl] === 'function') {
basicBot.room.blacklists[bl] = basicBot.settings.blacklists();
}
else if (typeof basicBot.settings.blacklists[bl] === 'string') {
if (basicBot.settings.blacklists[bl] === '') {
continue;
}
try {
(function (l) {
$.get(basicBot.settings.blacklists[l], function (data) {
if (typeof data === 'string') {
data = JSON.parse(data);
}
var list = [];
for (var prop in data) {
if (typeof data[prop].mid !== 'undefined') {
list.push(data[prop].mid);
}
}
basicBot.room.blacklists[l] = list;
})
})(bl);
}
catch (e) {
API.chatLog('Error setting' + bl + 'blacklist.');
console.log('Error setting' + bl + 'blacklist.');
console.log(e);
}
}
}
},
logNewBlacklistedSongs: function () {
if (typeof console.table !== 'undefined') {
console.table(basicBot.room.newBlacklisted);
}
else {
console.log(basicBot.room.newBlacklisted);
}
},
exportNewBlacklistedSongs: function () {
var list = {};
for (var i = 0; i < basicBot.room.newBlacklisted.length; i++) {
var track = basicBot.room.newBlacklisted[i];
list[track.list] = [];
list[track.list].push({
title: track.title,
author: track.author,
mid: track.mid
});
}
return list;
}
},
eventChat: function (chat) {
chat.message = linkFixer(chat.message);
chat.message = decodeEntities(chat.message);
chat.message = chat.message.trim();
basicBot.room.chatMessages.push([chat.cid, chat.message, chat.sub, chat.timestamp, chat.type, chat.uid, chat.un]);
for (var i = 0; i < basicBot.room.users.length; i++) {
if (basicBot.room.users[i].id === chat.uid) {
basicBot.userUtilities.setLastActivity(basicBot.room.users[i]);
if (basicBot.room.users[i].username !== chat.un) {
basicBot.room.users[i].username = chat.un;
}
}
}
if (basicBot.chatUtilities.chatFilter(chat)) return void (0);
if (!basicBot.chatUtilities.commandCheck(chat))
basicBot.chatUtilities.action(chat);
},
eventUserjoin: function (user) {
var known = false;
var index = null;
for (var i = 0; i < basicBot.room.users.length; i++) {
if (basicBot.room.users[i].id === user.id) {
known = true;
index = i;
}
}
var greet = true;
var welcomeback = null;
if (known) {
basicBot.room.users[index].inRoom = true;
var u = basicBot.userUtilities.lookupUser(user.id);
var jt = u.jointime;
var t = Date.now() - jt;
if (t < 10 * 1000) greet = false;
else welcomeback = true;
}
else {
basicBot.room.users.push(new basicBot.User(user.id, user.username));
welcomeback = false;
}
for (var j = 0; j < basicBot.room.users.length; j++) {
if (basicBot.userUtilities.getUser(basicBot.room.users[j]).id === user.id) {
basicBot.userUtilities.setLastActivity(basicBot.room.users[j]);
basicBot.room.users[j].jointime = Date.now();
}
}
if (basicBot.settings.welcome && greet) {
welcomeback ?
setTimeout(function (user) {
API.sendChat(subChat(basicBot.chat.welcomeback, {name: user.username}));
}, 1 * 1000, user)
:
setTimeout(function (user) {
API.sendChat(subChat(basicBot.chat.welcome, {name: user.username}));
}, 1 * 1000, user);
}
},
eventUserleave: function (user) {
var lastDJ = API.getHistory()[0].user.id;
for (var i = 0; i < basicBot.room.users.length; i++) {
if (basicBot.room.users[i].id === user.id) {
basicBot.userUtilities.updateDC(basicBot.room.users[i]);
basicBot.room.users[i].inRoom = false;
if (lastDJ == user.id){
var user = basicBot.userUtilities.lookupUser(basicBot.room.users[i].id);
basicBot.userUtilities.updatePosition(user, 0);
user.lastDC.time = null;
user.lastDC.position = user.lastKnownPosition;
}
}
}
},
eventVoteupdate: function (obj) {
for (var i = 0; i < basicBot.room.users.length; i++) {
if (basicBot.room.users[i].id === obj.user.id) {
if (obj.vote === 1) {
basicBot.room.users[i].votes.woot++;
}
else {
basicBot.room.users[i].votes.meh++;
}
}
}
var mehs = API.getScore().negative;
var woots = API.getScore().positive;
var dj = API.getDJ();
var timeLeft = API.getTimeRemaining();
var timeElapsed = API.getTimeElapsed();
if (basicBot.settings.voteSkip) {
if ((mehs - woots) >= (basicBot.settings.voteSkipLimit)) {
API.sendChat(subChat(basicBot.chat.voteskipexceededlimit, {name: dj.username, limit: basicBot.settings.voteSkipLimit}));
if (basicBot.settings.smartSkip && timeLeft > timeElapsed){
basicBot.roomUtilities.smartSkip();
}
else {
API.moderateForceSkip();
}
}
}
},
eventCurateupdate: function (obj) {
for (var i = 0; i < basicBot.room.users.length; i++) {
if (basicBot.room.users[i].id === obj.user.id) {
basicBot.room.users[i].votes.curate++;
}
}
},
eventDjadvance: function (obj) {
if (basicBot.settings.autowoot) {
$("#woot").click(); // autowoot
}
var user = basicBot.userUtilities.lookupUser(obj.dj.id)
for(var i = 0; i < basicBot.room.users.length; i++){
if(basicBot.room.users[i].id === user.id){
basicBot.room.users[i].lastDC = {
time: null,
position: null,
songCount: 0
};
}
}
var lastplay = obj.lastPlay;
if (typeof lastplay === 'undefined') return;
if (basicBot.settings.songstats) {
if (typeof basicBot.chat.songstatistics === "undefined") {
API.sendChat("/me " + lastplay.media.author + " - " + lastplay.media.title + ": " + lastplay.score.positive + "W/" + lastplay.score.grabs + "G/" + lastplay.score.negative + "M.")
}
else {
API.sendChat(subChat(basicBot.chat.songstatistics, {artist: lastplay.media.author, title: lastplay.media.title, woots: lastplay.score.positive, grabs: lastplay.score.grabs, mehs: lastplay.score.negative}))
}
}
basicBot.room.roomstats.totalWoots += lastplay.score.positive;
basicBot.room.roomstats.totalMehs += lastplay.score.negative;
basicBot.room.roomstats.totalCurates += lastplay.score.grabs;
basicBot.room.roomstats.songCount++;
basicBot.roomUtilities.intervalMessage();
basicBot.room.currentDJID = obj.dj.id;
var blacklistSkip = setTimeout(function () {
var mid = obj.media.format + ':' + obj.media.cid;
for (var bl in basicBot.room.blacklists) {
if (basicBot.settings.blacklistEnabled) {
if (basicBot.room.blacklists[bl].indexOf(mid) > -1) {
API.sendChat(subChat(basicBot.chat.isblacklisted, {blacklist: bl}));
if (basicBot.settings.smartSkip){
return basicBot.roomUtilities.smartSkip();
}
else {
return API.moderateForceSkip();
}
}
}
}
}, 2000);
var newMedia = obj.media;
var timeLimitSkip = setTimeout(function () {
if (basicBot.settings.timeGuard && newMedia.duration > basicBot.settings.maximumSongLength * 60 && !basicBot.room.roomevent) {
var name = obj.dj.username;
API.sendChat(subChat(basicBot.chat.timelimit, {name: name, maxlength: basicBot.settings.maximumSongLength}));
if (basicBot.settings.smartSkip){