forked from basicBot/custom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
1509 lines (1426 loc) · 48.3 KB
/
extension.js
File metadata and controls
1509 lines (1426 loc) · 48.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
(function(){
const YTAPIkey = 'AIzaSyC8pk0f57a_UcAIbHdrvRhsmHSG1KZk2SM';
const giphyKey = 'dc6zaTOxFJmzC';
const roomRE = /(plug\.dj\/)(?!enjoy-the-drop\b|about\b|ba\b|forgot-password\b|founders\b|giftsub\/\d|jobs\b|legal\b|merch\b|partners\b|plot\b|privacy\b|purchase\b|subscribe\b|team\b|terms\b|press\b|_\/|@\/|!\/)(.+)/i;
const tuneStrings = [
"%%DJ%%, %%USER%% would like you to know that this is a great tune!",
"%%DJ%%, %%USER%% thinks this is an awesome track!",
"%%DJ%%, keep playing such great tracks because %%USER%% seems to like them!",
"%%USER%% absolutely love this music %%DJ%%!",
"%%DJ%%, %%USER%% is really enjoying this track!",
"%%DJ%%, %%USER%% is dancing his feet off to this track!",
'%%DJ%% DUDE, this is awesome!" -from %%USER%%',
"%%DJ%% That's a banger! -%%USER%%",
"%%DJ%% thanks to you %%USER%% is an absolute fan of this music!"
];
const propsStrings = [
"%%DJ%% Aye mate, %%USER%% wants to set sails with you 👍",
"[%%USER%%] %%DJ%% Damn, you're on 🔥!",
"%%DJ%%, %%USER%% wants you to know that you're a great DJ!",
"%%DJ%%, %%USER%% has bought you some 💐 for your awesome play!",
"Hey %%DJ%%, I think %%USER%% really likes you 😘",
"Hey %%DJ%%, you really set the dancefloor on fire!"
];
/*const modules = {
roomInfo: _.find(require.s.contexts._.defined,m=>m&&m.attributes&&m.attributes.shouldCycle)
};*/
function subChat(chat, obj) {
if (typeof chat === 'undefined') return chat;
var lit = '%%';
for (var prop in obj) {
chat = chat.replace(lit + prop.toUpperCase() + lit, obj[prop]);
}
return chat;
}
function getGiphyID(options, callback) {
$.getJSON("https://tv.giphy.com/v1/gifs/random?",
{
format: 'json',
api_key: giphyKey,
rating: options.rating,
tag: options.fixedtag
},
function(response) {
callback(response.data.id);
}
);
}
function getRandomGiphyID(rating, callback) {
$.getJSON("https://tv.giphy.com/v1/gifs/random?",
{
format: 'json',
api_key: giphyKey,
rating: rating
},
function(response) {
callback(response.data.id);
}
);
}
/*function toggleCycle() {
let shouldCycle = modules.roomInfo.attributes.shouldCycle;
let disableCycle = shouldCycle && API.getUsers().length >= 10;
let enableCycle = !shouldCycle && API.getUsers().length <= 8;
if (disableCycle) API.moderateDJCycle(false);
else if (enableCycle) API.moderateDJCycle(true);
}*/
function waitlistBan(options, callback) {
if (typeof options.reason === 'undefined') options.reason = 1;
$.ajax({
url: '/_/booth/waitlistban',
type: 'POST',
data: JSON.stringify({'userID':options.ID,'reason':options.reason,'duration':options.duration}),
contentType: 'application/json',
error: function(err) {
if (typeof callback !== 'function') return;
switch(err.responseJSON.data[0]) {
case 'You are not authorized to access this resource.':
callback('/me [@%%USER%%] I am somehow not authorized to do this :thinking:');
break;
case 'Not a valid ban duration':
callback('/me [@%%USER%%] Please make sure that the duration of the ban is correct.');
break;
case 'Not a valid ban reason':
callback('/me [@%%USER%%] Please make sure that the reason of the ban is correct.');
break;
case 'Not in a room':
console.error('Trying to waitlist ban while not being in a room?!');
break;
case 'Nice try buddy, bouncers can\'t perm ban':
callback('/me [@%%USER%%] As a bouncer, I cannot permanently ban a user.');
break;
case 'That user is too powerful to ban':
callback('/me [@%%USER%%] Trying to ban an Admin/BA ? Well no luck here..');
break;
case 'Cannot ban a >= ranking user':
callback('/me [@%%USER%%] You can\'t ban users with an equal or higher rank than you!');
break;
case 'Not a moderator':
callback('/me [@%%USER%%] I need to be bouncer minimum to perform this action.');
break;
case 'Trying to ban yourself?':
callback('/me [@%%USER%%] Hey! Don\'t try to ban me!');
break;
default:
callback('/me [@%%USER%%] An error occured, please try again.');
break;
}
}
});
}
API.moderateForceQuit = function() {
if (API.hasPermission(null, API.ROLE.BOUNCER)) {
$.ajax({
url: '/_/booth/remove/'+API.getDJ().id,
method: 'DELETE'
});
}
};
API.moderateMoveDJ = (ID, pos) => {
API.enabled &&
API.hasPermission(null, API.ROLE.MANAGER) &&
pos >= 0 && pos <= API.getWaitList().length &&
API.getUser(ID).id &&
API.getWaitListPosition(ID) + 1 !== pos &&
$.ajax({
url: '/_/booth/move',
type: 'POST',
data: JSON.stringify({
position: pos-1,
userID: ID
}),
error: (err) => console.error(err),
dataType: 'json',
contentType: 'application/json'
});
};
Number.prototype.spaceOut = function() {
if (isNaN(this) || this < 999) return this;
return (this).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
};
// Loto stuff
window.cooldown = {
gif: 0,
loto: JSON.parse(localStorage.getItem('loto-CD')) || []
};
const lotoBlacklist = [
4613422, // WiBla
6553384, // <~ Tene ~>
31256054, // miguou888
30051880, // Fana
];
const emote = [
// [Emote, value, %chance]
['💀', 0, 90], // skull
['💊', 0, 90], // pill
['💣', 0, 90], // bomb
['👾', 0, 90], // space_invader
['📦', 0, 90], // package
[':troll:', 0, 90], // 90% chance to lose
['🍒', 1000, 90], // 10%
['🍇', 2500, 96], // 4%
['⚡', 5000, 99.4], // 0.6%
['🎲', 25000, 99.8], // 0.2%
['👑', 50000, 99.9], // 0.1%
['🎁', 100000, 99.999] // 0.001%
];
function generateEmote(msg) {
let chanceMultiplier;
if (lotoBlacklist.indexOf(msg.uid) > -1) chanceMultiplier = 96.999;
else chanceMultiplier = 100;
let rdm = Math.random()*chanceMultiplier; // 0 - 99.999999999999999
for (let i = emote.length-1; i >= 0; i--) {
if (rdm >= emote[i][2]) return emote[i];
else if (i <= 5) return emote[Math.floor(Math.random()*6)];
}
}
function loto(msg) {
var row1 = generateEmote(msg);
var row2 = generateEmote(msg);
var row3 = generateEmote(msg);
var earn = row1[1] + row2[1] + row3[1];
row1 = row1[0];
row2 = row2[0];
row3 = row3[0];
// Jackpot
if (row1 == row2 && row2 == row3) {
// Only applies to win emotes
if (['💀', '💊', '💣', '👾', '📦', ':troll:'].indexOf(row1) === -1) {
earn *= 3;
row3 += ' Jackpot ! PPs multiplied by 3 !';
}
}
// Two same values
else if (row1 == row2 || row1 == row3 || row2 == row3) {
// No need to verify the third value since either the first or second contains at least one item of the pair
if (['💀', '💊', '💣', '👾', '📦', ':troll:'].indexOf(row1) === -1 &&
['💀', '💊', '💣', '👾', '📦', ':troll:'].indexOf(row2) === -1) {
earn *= 2;
row3 += ' Pair ! PPs multiplied by 2 !';
}
}
if (earn <= 0) API.sendChat(`/me ${row1}|${row2}|${row3} @${msg.un}, you lost, retry tomorrow !`);
else {
if (earn >= 1000) earn = (earn /= 1000) + 'k';
API.sendChat(`/me ${row1}|${row2}|${row3} @${msg.un}, you won ${earn}PP ! 🎉`);
}
}
// Hangmann stuff
String.prototype.replaceAt = function(index, replacement) {
return this.substr(0, index) + replacement + this.substr(index + replacement.length);
};
const words = [
'chorus',
'maestro',
'piano',
'music',
'symphony',
'rythm',
'requiem',
'serenade',
'sonata',
'soprano',
'vibrato',
'virtuoso',
'magnetophone',
'microphone',
'xylophone',
'guitare',
'table',
'television',
'drawer',
'computer',
'laptop',
'house',
'church',
'fruits',
'kiwi',
'vegetable',
'speakers',
'games',
'video-games',
'keyboard',
'coins',
'money',
'happy',
'sharing',
'disco',
'country',
'paper',
'mysterious',
'sphinx',
'egypt',
'cryotherapy',
'geranium',
'cryptography',
'citrus',
'nymph'
];
const abc = 'abcdefghijklmnopqrstuvwxyz';
var penduActive = false;
var secret = '';
var underline = '';
var guess = 10;
var guessed = [];
var hangMessaged = [];
function startPendu() {
if (!penduActive) {
penduActive = true;
secret = words[Math.floor(Math.random()*words.length)];
for (var i = 0; i < secret.length; i++) {
underline += secret.charAt(i) === '-' ? '-' : '_';
}
API.sendChat(`A new hangman has started! ${underline} ${guess} guesses left!`);
} else {
API.sendChat('A hangman is already active!');
}
}
function resetPendu() {
penduActive = false;
underline = '';
secret = '';
guess = 10;
guessed = [];
hangMessaged.forEach((cid) => {API.moderateDeleteChat(cid);});
hangMessaged = [];
}
// Live stuff
const playlistID = '10722938';
var errorState = 0;
function getCurrentLive(callback) {
$.ajax({
url: `/_/playlists/${playlistID}/media`,
method: 'GET',
dataType: 'json',
success: function(data) {
errorState = 0;
let medias = data.data;
medias.forEach((media) => {
if ([media.author, media.title].indexOf('24/7 Monstercat Radio') > -1) callback(media);
});
},
error: function() {
if (errorState === 0) {
getCurrentLive(callback);
errorState = 1;
} else {
API.sendChat('/me [Error @WiBla] Could not get Current live.');
}
}
});
}
function isUnavailable(media, callback) {
$.ajax({
url: `https://www.googleapis.com/youtube/v3/videos?id=${media.cid}&key=${YTAPIkey}&part=snippet,status`,
type: 'GET',
success: function(data) {
errorState = 0;
if (data.items.length === 0 ||
(data.items.length == 1 && ['processed', 'uploaded'].indexOf(data.items[0].status.uploadStatus) < 0)) {
callback(true, media);
}
else callback(false, media);
},
error: function() {
if (errorState === 0) {
isUnavailable(media, callback);
errorState = 1;
} else {
API.sendChat('/me [Error @WiBla] Could not check live availability.');
}
}
});
}
function deleteMedia(media, callback) {
$.ajax({
url: `/_/playlists/${playlistID}/media/delete`,
method: 'POST',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({
ids: [media.id]
}),
success: function() {
errorState = 0;
callback();
},
error: function() {
if (errorState === 0) {
deleteMedia(media, callback);
errorState = 1;
} else {
API.sendChat('/me [Error @WiBla] Could not delete current live.');
}
}
});
}
function getNewLive(callback) {
$.ajax({
url: 'https://content.googleapis.com/youtube/v3/search?'+
'type=video'+
'&eventType=live'+
'&q='+encodeURI('24/7 Monstercat Radio')+
'&maxResults=25'+
'&part=snippet'+
'&key=AIzaSyC8pk0f57a_UcAIbHdrvRhsmHSG1KZk2SM',
type: 'GET',
dataType: 'json',
contentType: 'application/json',
success: function(data) {
errorState = 0;
if (data.items.length === 0) return;
data.items.forEach((item) => {
if (item.snippet.channelId === "UCJ6td3C9QlPO9O_J5dF4ZzA") {
callback({
cid: item.id.videoId,
author: item.snippet.title.split(' - ')[0],
title: item.snippet.title.split(' - ').slice(1).join(' - '),
image: item.snippet.thumbnails.default.url,
duration: 86400,
format: 1,
id: 1
});
}
});
},
error: function() {
if (errorState === 0) {
getNewLive(callback);
errorState = 1;
} else {
API.sendChat('/me [Error @WiBla] Could not get new live.');
}
}
});
}
function addMedia(media, callback) {
$.ajax({
url: `/_/playlists/${playlistID}/media/insert`,
method: 'POST',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({
media: [media],
append: false
}),
success: function() {
errorState = 0;
callback();
},
error: function() {
if (errorState === 0) {
addMedia(media, callback);
errorState = 1;
} else {
API.sendChat('/me [Error @WiBla] Could not add live.');
}
}
});
}
function extend() {
if (!window.bot) return setTimeout(extend, 1000);
var bot = window.bot;
bot.retrieveSettings();
function playLive() {
if (API.getDJ() !== undefined || API.getWaitList().length !== 0 || !bot.settings.playLive) return;
let liveWarn = ' Join the waitlist and I\'ll stop playing!';
let _welcome = bot.chat.welcome;
let _welcomeback = bot.chat.welcomeback;
let _ss = bot.settings.smartSkip;
let _hs = bot.settings.smartSkip;
let _tg = bot.settings.smartSkip;
bot.settings.smartSkip = false;
bot.settings.historySkip = false;
bot.settings.timeGuard = false;
bot.chat.welcome += liveWarn;
bot.chat.welcomeback += liveWarn;
if (API.djJoin() === 0) {
// only listen to updates once the bot has joined the booth
API.once(API.WAIT_LIST_UPDATE, () => {
API.once(API.WAIT_LIST_UPDATE, () => {
bot.settings.smartSkip = _ss;
bot.settings.historySkip = _hs;
bot.settings.timeGuard = _tg;
bot.chat.welcome = _welcome;
bot.chat.welcomeback = _welcomeback;
$.ajax({url:'/_/booth',type:'DELETE'});
});
});
}
}
function naModSkip(name) {
API.sendChat(subChat(bot.chat.notavailable, {
name: name
}));
if (bot.settings.smartSkip) {
return bot.roomUtilities.smartSkip();
} else {
return API.moderateForceSkip();
}
}
function storeToStorage() {
localStorage.setItem('basicBotsettings', JSON.stringify(bot.settings));
localStorage.setItem('basicBotRoom', JSON.stringify(bot.room));
var basicBotStorageInfo = {
time: Date.now(),
stored: true,
version: bot.version
};
localStorage.setItem('basicBotStorageInfo', JSON.stringify(basicBotStorageInfo));
}
function skip() {
if (API.getWaitList().length === 0) API.moderateForceQuit();
else if (bot.settings.smartSkip) bot.roomUtilities.smartSkip();
else API.moderateForceSkip();
}
bot.commands.gif18Command = {
command: ['gif18', 'giphy18'],
rank: 'bouncer',
type: 'startsWith',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
if ((new Date().getTime() - cooldown.gif)/1000/60 < 1) return void (0); // if less than a minute
else {
var msg = chat.message;
if (msg.length !== cmd.length) {
var tag = msg.substr(cmd.length + 1);
var fixedtag = tag.replace(/ /g,"+");
var commatag = tag.replace(/ /g,", ");
getGiphyID({rating: 'nsfw', fixedtag: fixedtag}, function(id) {
if (typeof id !== 'undefined') {
cooldown.gif = new Date().getTime();
API.sendChat('/me ['+chat.un+'] [Tags: '+commatag+'] http:\/\/i.giphy.com\/'+id+'.gif');
} else {
API.sendChat('/me ['+chat.un+'] [Tags: '+commatag+'] Invalid tags, try something different.');
}
});
}
else {
getRandomGiphyID('nsfw', function(id) {
if (typeof id !== 'undefined') {
cooldown.gif = new Date().getTime();
API.sendChat('/me ['+chat.un+'] [Random GIF] http:\/\/i.giphy.com\/'+id+'.gif');
} else {
API.sendChat('/me ['+chat.un+'] Invalid request, try again.');
}
});
}
}
}
};
bot.commands.gifCommand = {
command: ['gif', 'giphy'],
rank: 'user',
type: 'startsWith',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
if ((new Date().getTime() - cooldown.gif)/1000/60 < 1) return void (0); // if less than a minute
else {
var msg = chat.message;
if (msg.length !== cmd.length) {
var tag = msg.substr(cmd.length + 1);
var fixedtag = tag.replace(/ /g,"+");
var commatag = tag.replace(/ /g,", ");
getGiphyID({rating: 'pg-13', fixedtag: fixedtag}, function(id) {
if (typeof id !== 'undefined') {
cooldown.gif = new Date().getTime();
API.sendChat('/me ['+chat.un+'] [Tags: '+commatag+'] http:\/\/i.giphy.com\/'+id+'.gif');
} else {
API.sendChat('/me ['+chat.un+'] [Tags: '+commatag+'] Invalid tags, try something different.');
}
});
}
else {
getRandomGiphyID('pg-13', function(id) {
if (typeof id !== 'undefined') {
cooldown.gif = new Date().getTime();
API.sendChat('/me ['+chat.un+'] [Random GIF] http:\/\/i.giphy.com\/'+id+'.gif');
} else {
API.sendChat('/me ['+chat.un+'] Invalid request, try again.');
}
});
}
}
}
};
bot.commands.kickCommand = {
command: 'kick',
rank: 'bouncer',
type: 'startsWith',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
else {
var msg = chat.message;
var lastSpace = msg.lastIndexOf(' ');
var time;
var name;
if (lastSpace === msg.indexOf(' ')) {
time = 15;
name = msg.substring(cmd.length + 2);
}
else {
time = msg.substring(lastSpace + 1);
name = msg.substring(cmd.length + 2, lastSpace);
}
var user = null;
var users = API.getUsers();
for (var i = 0; i < users.length; i++) {
var match = users[i].username.trim() == name.trim();
if (match) {
user = users[i];
}
}
if (typeof user === null) return API.sendChat('/me [@'+chat.un+'] No user specified.');
var permFrom = API.getUser(chat.uid).role;
var permTokick = API.getUser(user.id).role;
if (permFrom <= permTokick) return API.sendChat('/me [@'+chat.un+'] you can\'t kick users with an equal or higher rank than you!');
if (!isNaN(time)) {
var duration;
if (time>=24*60*60) duration = 'f';
else if (time>=60*60) duration = 'd';
else duration = 'h';
$.ajax({
type: 'POST',
url: 'https://plug.dj/_/bans/add',
data: JSON.stringify({'userID':user.id,'reason':1,'duration':duration}),
dataType: 'json',
contentType: 'application/json',
error: function(e) {console.log(e);},
success: function(){
API.sendChat('/me '+user.username+' was kicked for '+time+' seconds.');
setTimeout(function(){
$.ajax({
type: 'DELETE',
url: 'https://plug.dj/_/bans/'+user.id,
error: function(e) {console.log(e);},
success: function(){
API.sendChat('/me '+user.username+' was successfully unbaned.');
}
});
}, time*1000);
}
});
} else API.sendChat('/me [@'+chat.un+'] Invalid time specified');
}
}
};
bot.commands.waitlistBanCommand = {
command: ['wlban', 'wlBan', 'waitlistban', 'waitlistBan'],
rank: 'bouncer',
type: 'startsWith',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
if (chat.message === cmd) return API.sendChat(`/me [@${chat.un}] Please provide a user and duration.`);
else {
let cmdRegEx = /(?: @?)(.*\b)(?:( [smlf]$)|(15mins?|15m|(?:one|une|1)? ?(?:hour|heure)|1?h)|((?:one|un|1)? ?(?:day|jour))|(forever|toujours?))/gi;
let match = cmdRegEx.exec(chat.message);
if (match === null) return API.sendChat(`/me [@${chat.un} something went wrong, are you sure you specified a correct user and duration?`);
let ID = match[1];
let duration = '';
if (isNaN(ID)) {
let users = API.getUsers();
for (var i = 0; i < users.length; i++) {
if (users[i].username === ID) ID = users[i].id;
}
if (isNaN(ID)) return API.sendChat(`/me [@${chat.un}] Wrong user specified. Is that user ghosting?`);
}
// If we're not using s,m,l, or f
if (match[3] === '') {
// The regExp is build in a way that each duration has its own match so we just see the one that isn't empty and correlate the wanted duration
if (match[4] !== '') duration = 's';
else if (match[5] !== '') duration = 'm';
else if (match[6] !== '') duration = 'l';
else if (match[7] !== '') duration = 'l';
}
if ('smlf'.indexOf(duration) === -1) duration = 's';
if (duration === 'f' && (API.getUser(chat.uid).role < API.ROLE.MANAGER && API.getUser(chat.uid).gRole === API.ROLE.NONE))
API.sendChat(`/me [@${chat.un}] You do not have sufficent permissions to ban a user indefinitely.`);
waitlistBan(
{ID: ID, duration: duration},
(error) => API.sendChat(error.split('%%USER%%').join(chat.un))
);
}
}
};
bot.commands.linkCommand = {
command: 'link',
rank: 'user',
type: 'exact',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
else {
var thisMedia = API.getMedia();
if (thisMedia.format == 1) API.sendChat('/me [@'+chat.un+'] Link to current song: https://youtu.be/'+thisMedia.cid);
else {
var sound = SC.get('/tracks/' + thisMedia.cid);
// setInterval is used because SC doesn't return immediately the track
var uInt = setInterval(function() {
if (typeof sound._result === "undefined") return;
API.sendChat('/me [@'+chat.un+'] Link to current song: '+sound._result.permalink_url);
clearInterval(uInt);
}, 10);
}
}
}
};
bot.commands.englishCommand = {
command: ['english', 'en'],
rank: 'residentdj',
type: 'startsWith',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
else {
if (chat.message.length === cmd.length) return API.sendChat('/me No user specified.');
var name = chat.message.substring(cmd.length + 2);
var user = bot.userUtilities.lookupUserName(name);
if (typeof user === 'boolean') return API.sendChat('/me Invalid user specified.');
var lang = bot.userUtilities.getUser(user).language;
var ch = '/me @' + name + ' ';
if (lang === 'en') {
ch += 'Please, speak either French or English.';
API.sendChat(ch);
} else {
$.ajax({
type: 'GET',
url: 'https://translate.googleapis.com/translate_a/single?client=gtx&dt=t'+
'&sl=en'+
'&tl='+lang+
"&q="+ encodeURI('Please, speak either French or English.'),
success: function(data) {
ch += data[0][0][0];
API.sendChat(ch);
},
error: function(err) {
ch += err.responseText.split('"')[1];
API.sendChat(ch);
}
});
}
}
}
};
bot.commands.clearlocalstorageCommand = {
command: ['clearLS', 'clearls'],
rank: 'manager',
type: 'exact',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
else {
var plugSettings = localStorage.getItem('settings');
var lotoCDLS = localStorage.getItem('loto-CD');
localStorage.clear();
if (plugSettings !== null) localStorage.setItem('settings', plugSettings);
if (lotoCDLS !== null) localStorage.setItem('loto-CD', lotoCDLS);
API.sendChat('/me [@'+chat.un+'] localStorage cleared ! Be right back..');
location.reload();
}
}
};
bot.commands.helpCommand = {
command: 'help',
rank: 'user',
type: 'exact',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
else {
API.sendChat(subChat(bot.chat.starterhelp, {link: "https://i.imgur.com/1Y0nvoq.jpg"}));
}
}
};
bot.commands.mehCommand = {
command: 'meh',
rank: 'bouncer',
type: 'exact',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void(0);
if (!bot.commands.executable(this.rank, chat)) return void(0);
else {
$('.btn-meh').click();
API.sendChat('http://i.imgur.com/NGpjdvp.gif');
}
}
};
bot.commands.event = {
command: ['event', 'roomevent'],
rank: 'manager',
type: 'exact',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
else {
bot.room.roomevent = !bot.room.roomevent;
if (bot.room.roomevent) {
bot.settings.afkRemoval = false;
bot.settings.blacklistEnabled = false;
bot.settings.filterSongs = false;
bot.settings.lockGuard = false;
bot.settings.timeGuard = false;
bot.settings.cycleGuard = false;
bot.settings.voteSkip = false;
bot.settings.historySkip = false;
bot.settings.thorCommand = false;
} else {
bot.settings.afkRemoval = settings.afkRemoval;
bot.settings.blacklistEnabled = settings.blacklistEnabled;
bot.settings.filterSongs = settings.filterSongs;
bot.settings.lockGuard = settings.lockGuard;
bot.settings.timeGuard = settings.timeGuard;
bot.settings.cycleGuard = settings.cycleGuard;
bot.settings.voteSkip = settings.voteSkip;
bot.settings.historySkip = settings.historySkip;
bot.settings.thorCommand = settings.thorCommand;
}
API.sendChat(`/me [@${chat.un}] Event mode ${(bot.room.roomevent ? 'enabled. Things like historySkip or timeGuard have been disabled.' : 'disabled.')}`);
}
}
};
bot.commands.toggleSongFilter = {
command: ['songFilter', 'toggleSongFilter'],
rank: 'manager',
type: 'exact',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
else {
bot.settings.filterSongs = !bot.settings.filterSongs;
API.sendChat(`/me [@${chat.un}] Song filtering ${(bot.settings.filterSongs ? 'enabled' : 'disabled')}!`);
}
}
};
bot.commands.toggleLivePlay = {
command: ['live', 'toggleLive'],
rank: 'manager',
type: 'exact',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
else {
bot.settings.playLive = !bot.settings.playLive;
API.sendChat(`/me [@${chat.un}] Live play ${(bot.settings.playLive ? 'enabled' : 'disabled')}!`);
}
}
};
bot.commands.bot = {
command: 'bot',
rank: 'bouncer',
type: 'startsWith',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
else {
var msg = chat.message;
if (msg.length === cmd.length) return API.sendChat("I am indeed a bot.");
var name = msg.substr(cmd.length + 1);
if (msg.length > cmd.length + 1) {
API.sendChat("/me " + name + ", I am a bot, you can try to talk to me but I won't answer unless you use commands.");
}
}
}
};
bot.commands.staff = {
command: 'staff',
rank: 'user',
type: 'startsWith',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
else {
if (API.getUsers().filter(u => (u.role >= API.ROLE.MANAGER && u.id !== 5285179)).length > 0) {
API.sendChat(`/me [@${chat.un}] @staff ${chat.message.substr(cmd.length + 1)}`);
}
}
}
};
bot.commands.blocop = {
command: 'blocop',
rank: 'user',
type: 'startsWith',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
else {
var msg = chat.message;
if (msg.length === cmd.length) return API.sendChat('/me [@'+chat.un+'] No user specified');
var name = msg.substr(cmd.length + 1).replace('@','');
if (name.length > 0) {
var audience = API.getUsers();
for (var i = 0; i < audience.length; i++) {
if (audience[i].rawun == name) return API.sendChat('/me Le bloc opératoire N°404 est disponible pour une ablation de côtes ' + name + '.');
}
API.sendChat('/me [@'+chat.un+'] There is no user by this name.');
}
}
}
};
bot.commands.loto = {
command: 'loto',
rank: 'user',
type: 'exact',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
else {
if (chat.uid === 4613422) return loto(chat); // testing stuff
// Check if grey users have been in the room for at least 15mins before trying the loto
if (!API.hasPermission(chat.uid, API.ROLE.DJ) ||
(Date.now() - bot.room.roomstats.launchTime) <= 1000 * 60 * 30) {
let userJoinTime = bot.room.users.filter(user => user.id === chat.uid)[0].jointime;
let minutesInRoom = (Date.now() - userJoinTime) / 1000 / 60;
if (minutesInRoom < 30) return API.sendChat(`/me [@${chat.un}] you need to be in the room for at least 30 minutes before attempting the loto!`);
}
if (cooldown.loto.length) {
for (var i = 0; i < cooldown.loto.length; i++) {
if (i+1 >= cooldown.loto.length && chat.uid !== cooldown.loto[i][1]) {
cooldown.loto.push([chat.un, chat.uid, new Date().getTime()]);
localStorage.setItem('loto-CD', JSON.stringify(cooldown.loto));
return loto(chat);
}
else if (chat.uid == cooldown.loto[i][1]) {
var day = new Date(cooldown.loto[i][2]).getDate();
var now = new Date();
if (day !== now.getDate()) {
cooldown.loto[i][2] = now.getTime();
localStorage.setItem('loto-CD', JSON.stringify(cooldown.loto));
return loto(chat);
} else {
return API.sendChat('/me @'+chat.un+' you already played today !');
}
}
}
} else {
cooldown.loto.push([chat.un, chat.uid, new Date().getTime()]);
localStorage.setItem('loto-CD', JSON.stringify(cooldown.loto));
loto(chat);
}
}
}
};
bot.commands.tune = {
command: 'tune',
rank: 'user',
type: 'exact',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
else {
var users = {
dj: '@'+API.getDJ().username,
user: chat.un
};
var string = tuneStrings[Math.floor(Math.random()*tuneStrings.length)];
// Self tuning your own track are you ?
if (users.dj.substr(1) === users.user) return API.sendChat('/me Le bloc opératoire N°404 est disponible pour une ablation de côtes ' + users.dj + '.');
for (var key in users) {
string = string.split('%%'+key.toUpperCase()+'%%').join(users[key]);
}
API.sendChat('/me ' + string);
}
}
};
bot.commands.props = {
command: 'props',
rank: 'user',
type: 'exact',
functionality: function (chat, cmd) {
if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
if (!bot.commands.executable(this.rank, chat)) return void (0);
else {
var users = {
dj: '@'+API.getDJ().username,
user: chat.un
};
var string = propsStrings[Math.floor(Math.random()*propsStrings.length)];
// Self proping are you ?
if (users.dj.substr(1) === users.user) return API.sendChat(`/me You shall not give yourself props ${users.dj}.`);