-
Notifications
You must be signed in to change notification settings - Fork 0
/
BruceBuffer_18JUL13_backup.js
733 lines (608 loc) · 26.1 KB
/
BruceBuffer_18JUL13_backup.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
console.log("START - Listening on http://127.0.0.1:8888");
//___OPENING SERVER STUFF__________________________________________________________
// requires node's http module
var http = require('http');
// creates a new httpServer instance
http.createServer(function (req, res) {
// this is the callback, or request handler for the httpServer
// respond to the browser, write some headers so the
// browser knows what type of content we are sending
res.writeHead(200, {'Content-Type': 'text/html'});
//QA - Checkpoint A
res.write('<h1>Things are working at checkpoint A.</h1>');
//___START BOT STUFF__________________________________________________________
var Bot = require('./index');
res.write('<h1>Things are working at checkpoint B.</h1>');
var AUTH = 'vzYqJzImNcvheHERMcsJuJCS'; // Bruce Buffer
var USERID = '502196a3eb35c174e3000023'; // Bruce Buffer
var ROOMID = '4f9ac260eb35c15fcc0001e1'; // Grotto
//BOTS
// Bruce Buffer
// AUTH = vzYqJzImNcvheHERMcsJuJCS
// USERID = 502196a3eb35c174e3000023
//ROOM IDs
// Easy Grotto: 4f9ac260eb35c15fcc0001e1
// Goodle Days: 5019e9cdaaa5cd4000000082
// The Drunk Room: 4f55f37a0c4cc8054f710976;
var bot = new Bot(AUTH, USERID, ROOMID);
res.write('<h1>Things are working at checkpoint C.</h1>');
/***************************************************************************
* SPEAK
* This section listens for when people say things, and responds accordingly
*
*/
bot.on('speak', function (data) {
// Get the data
var name = data.name;
var userId = data.userid;
var text = data.text;
// Respond to various incarnations of "hello bruce" command
if (text.toLowerCase().match(/^(hello|hi|hey|yo|sup|what\'?s up|howdy) bruce/)) {
//This array is loaded with responses to greetings from people in the room.
//Teh function selects a random saying from the above array and say it to the room
var greetingArray = ['yo dude - ready to rage?','Hey! What\'s the good word @'+name+'?', 'Howdy @'+name, 'wuzzzzzzuuuppppppp', 'Don\'t beat around the bush '+name+'... you gonna pass that shit?','whalecum to the party','Quit bogarting that joint!','You realize you are talking to nothing more than a text file, right? ugh...','less talk more tunes '+name+'!','Hey '+name+'. Wanna get high?','hey '+name+' I\'m glad your here. Sit down, take a load off.','It wasn\'t me I swear! Blame @stillwaterlive!!','sup brah?','Hello '+name+', we\'ve been expecting you.','hey I just got a fresh batch of nitrous brownies. Want one?'];
bot.speak(greetingArray[getRandomIndex(greetingArray)]);
}
// Log Playlist - for QA purposes
if (text.toLowerCase().match(/^logpl/)) {
logPlaylist();
bot.speak('logged');
}
// Respond to 'UFC' with Bruce Buffer's signature scream
if (text.toLowerCase().match(/^ufc$/)) {
bot.speak('LET\'S GET READY TO RUMMMMBBBBBLLLLEEEEE!');
}
// Say Playlist Length
if (text.toLowerCase().match(/^\/playlistlength/)) {
speakPlaylistLength();
}
// Respond to various incarnations of "hello bruce" command
if (text.toLowerCase().match(/^(thanks|thank you) bruce/)) {
var thanksArray = ['You\'re very welcome, '+name,'no problemo','sure thing','you owe me one!'];
bot.speak(thanksArray[getRandomIndex(thanksArray)]);
}
// Make the bot DJ with the "/botParty" command
if (text.toLowerCase().match(/^\/botparty/)) {
isRoomMod(userId, function(isMod) {
if(isMod){
//If this person is a mod, the bot will DJ
bot.addDj();
} else {
//Otherwise if they aren't a mod and don't have permission, tell them
bot.speak('You can\'t tell me what to do, @'+name+'!');
}
});
}
// Remove the bot from the DJ booth with the "/stepDown" command
if (text.toLowerCase().match(/^\/stepdown/)) {
isRoomMod(userId, function(isMod) {
if(isMod){
//If this person is a mod, the bot will DJ
bot.remDj();
} else {
//Otherwise if they aren't a mod and don't have permission, tell them
bot.speak('You can\'t tell me what to do, @'+name+'!');
}
});
}
// Tell the bot to add a song to its playlist with the "/addSong" command
if (text.toLowerCase().match(/^\/addsong/)) {
isRoomMod(userId, function(isMod) {
if(isMod){
//This will make the bot snag any songs that make him dance
getCurrentSongId(function(currSongId){
console.log("This song is: "+currSongId); //QA
addCurrentSongToPlaylist(currSongId, function(added){
console.log("The song was added: "+added); //QA
//This makes the bot tell the room if he snagged it or not
if(added == true){
bot.speak('Ah great choice, '+name+'. Consider it added.');
}else{
bot.speak('got it already, nice try.');
}
});//addCurrentSongtoPlaylist
}); //getCurrentSongId
} else {
//Otherwise if they aren't a mod and don't have permission, tell them
bot.speak('You can\'t tell me what to do, @'+name+'!');
}
});
}
/* // Shuffle up the Bot's playlist with the "/shuffle" command
if (text.toLowerCase().match(/^\/shuffle/)) {
isRoomMod(userId, function(isMod) {
if(isMod){
//If this person is a mod, the playlist will get shuffled up
shuffleBotPlaylist();
bot.speak('Thanks for the shake @'+name+' - I got some fresh tunes for y\'all now!');
} else {
//Otherwise if they aren't a mod and don't have permission, tell them
bot.speak('You can\'t tell me what to do, @'+name+'!');
}
});
}
*/
/* // Remove the current song from the bot's playlist with the "/trashsong" command
if (text.toLowerCase().match(/^\/trashsong/)) {
isRoomMod(userId, function(isMod) {
//If this person is a mod...
if(isMod){
//and if the bot is the active DJ...
getActiveDjId(function(isActive){
if (USERID == isActive){
//remove song from bot's playlist
bot.playlistRemove();
bot.speak('Frankly, I didn\'t like that song either');
} else{
bot.speak('Let\'s wait to hear what I have queued up before you pull the trigger @'+name);
}
});//getActiveDjId
} else {
//Otherwise if they aren't a mod and don't have permission, tell them
bot.speak('You can\'t tell me what to do, @'+name+'!');
}
});
}*/
// If the bot is DJing, tell him to skip his song with the "/skipSong" command
if (text.toLowerCase().match(/^\/skipsong/)) {
isRoomMod(userId, function(isMod) {
if(isMod){
//If this person is a mod, the bot will DJ
bot.skip();
} else {
//Otherwise if they aren't a mod and don't have permission, tell them
bot.speak('You can\'t tell me what to do, @'+name+'!');
}
});
}
// Respond to "/commands" command
if (text.toLowerCase().match(/^\/commands$/)) {
bot.speak('My Standard Commands: q+, q-, q?, q.shift, q.clear, UFC, /commands ...I also appreciate when people say hi!');
bot.speak('My DJ Commands: /botParty, /botDown, /skipSong, /playlistLength /addsong .... these are for mods only at the moment.');
}
});
res.write('<h1>Things are working at checkpoint D.</h1>');
/***************************************************************************
* BONUS POINT - "YEEHAW" TEXT BASED
*This section gives the DJ a bonus point if 50% of people say any phrase that includes "yeehaw"
*
*/
/* << REMOVE THIS TO ACTIVE THIS SECTION (and the other one at the bottom)
bonusBopCount = new Array();
bot.on('speak', function (data) {
var text = data.text;
var name = data.name;
var userId = data.userid;
// Any command with "yeehaw" will increase the bop count by 1
//The bop count length is indicated by the length of the array 'bonusBopCount' which stores each user's name that yeehaws to prevents a single user from using multiple yeehaws
if (text.toLowerCase().match(/yeehaw/)) {
console.log('yeehaw'); //QA
//Index is the position in the queue that this person's name is found.
//If its not found, -1 is returned.
var index = bonusBopCount.indexOf(name);
//If the persons name is not already in the array, increase the bop count and add them
if(index == -1){
bonusBopCount.push(name);
console.log('bonusBotCount = '+bonusBopCount.length); //QA
} else{
console.log('Repeat! bonusBotCount ='+bonusBopCount.length); //QA
}
}
getHeadCount(function(count) {
//Threshold is 50% of the user count
var threshold = .5*count;
//If more than 50% of users give their bonus vote, the bot will bop!
if(bonusBopCount.length >= threshold){
bot.vote('up');
}
});
}); //Close bot.on('speak')
// Reset bonusBopCount per new song
bot.on('newsong', function (data) {
bonusBopCount = [];
});
REMOVE THIS TO ACTIVE THIS SECTION >> */
/***************************************************************************
* BONUS POINT - AWESOME BASED
*This section gives the DJ a bonus point if 2+ people say any phrase that includes "yeehaw"
*
*/
bot.on('update_votes', function (data) {
getHeadCount(function(headCount) {
//Get current number of upvotes
var upVotes = data.room.metadata.upvotes;
//Threshold is 50% of the user count
var threshold = .5*headCount;
console.log('the threshold is: '+threshold);//QA
console.log('the bop count is: '+upVotes);//QA
//If more than 50% of users give their bonus vote, the bot will bop!
if(upVotes - threshold < 1 && upVotes - threshold >= 0 && headCount > 2){
//If the bot is the active DJ, then just show some love
getActiveDjId(function(isActive){
if (USERID == isActive){
bot.speak("Thanks for the love y\'all");
}else{
//If the bot is not the active DJ, then Bop and add to playlist if its a new song
bot.vote('up');
console.log('bonus! ');//QA
//This array is loaded with responses to greetings from people in the room.
var danceArray = ['I just wanna dance!','Jonesin\' on this track!','sick beat',':ok_hand: a-okay!','Shake ya boot-ay!!','thats the one!','yup.','this song is making my virtual head shake','I\'m only crying cause this song speaks to me :blush:',':+1:'];
//Select a random saying from the above array and say it to the room
bot.speak(danceArray[getRandomIndex(danceArray)]);
}//If USERID == activeDj
});//getActiveDJ
}//If votes > 50%
}); //getHeadCount
});//bot.on('update_votes')
res.write('<h1>Things are working at checkpoint E.</h1>');
/***************************************************************************
* END OF SONG STATS
* When a song is over, Bruce will tell the room how many awesomes
*
* https://github.com/alaingilbert/Turntable-API/blob/master/turntable_data/endsong.js
*
*/
bot.on('endsong', function (data) {
var ups = data.room.metadata.upvotes;
var downs = data.room.metadata.downvotes;
var listeners = data.room.metadata.listeners;
var album = data.room.metadata.current_song.metadata.album;
var artist = data.room.metadata.current_song.metadata.artist;
var song = data.room.metadata.current_song.metadata.song;
bot.speak('That was '+artist+' playing '+song+' (album: '+album+'). It got '+ups+' awesomes and '+downs+' lames with '+listeners+' people listening.');
});
/***************************************************************************
* BOT MODERATOR MESSAGE
* When someone is a moderator in the array AND types in "/mod", the bot displays a message.
*
*/
// Define global variable "modList" as an array of USERIDs
var modList = ['4dfb617b4fe7d061df013786', 'xxxxxxxxxxxxxxxxxxxxxxxx']; //Scruggs
// When someone is a bot moderator in the array AND types in "/botmod", the bot displays a message.
bot.on('speak', function (data) {
var name = data.name;
var text = data.text;
var userid = data.userid;
for (var i=0; i<modList.length; i++) {
if (userid == modList[i]) {
// Respond to "/botmod" command
if (text.match(/^\/botmod/)) {
bot.speak('Yo @'+data.name+', it looks like you are a bot moderator!');
}
// If a botmod PMs the bot and starts with "/msg", the bot will
if (text.match(/^\/msg /)) {
bot.speak(text.substring(3));
}
break;
}
}
});
// When someone is a bot moderator in the array AND pm's the bot a note that starts with "/msg ", the bot says the message to the room.
bot.on('pmmed', function (data) {
var text = data.text;
var senderid = data.senderid;
for (var i=0; i<modList.length; i++) {
if (senderid == modList[i]) {
// If a botmod PMs the bot and starts with "/msg ", the bot will say it to the room!
if (text.match(/^\/msg /)) {
bot.speak(text.substring(5));
}
break;
}
}
});
res.write('<h1>Things are working at checkpoint F.</h1>');
/***************************************************************************
* BLACKLIST
* This portion of code blocks ttstats bots and anyone in the array
*
*/
// When someone enters the room, the bot checks whether or not that user is a ttstats bot
bot.on('registered', function (data) {
var user = data.user[0];
var name = user.name;
var userId = user.userid;
var bootArray = ['BAM!','Smell ya later!','HOO RAH!','you smell awful', 'i don\'t give reasons','i laugh in the face of danger', 'spy!','Take that!','AND STAY OUT!','Sing by the window, I\'ll help you out','git r dun!','and don\'t call me either!','good luck getting home - I slashed your tires'];
if (name.toLowerCase().match(/ttstats/)) {
bot.bootUser(user.userid, bootArray[getRandomIndex(bootArray)]);
}
//Example: bot.speak(bootArray[getRandomIndex(bootArray)]);
});
/***************************************************************************
* QUEUE
* This is the q.
* Regular Commands: q+ q- q?
* Mod Commands: q.shift q.clear
*
* Other Functions:
* 1. When first in queue steps up
* 2. When not first in q steps up
* 3. When someone in q leaves room
4. When a seat opens up
*/
// Define global variable "queue" as an array of users
var queue = new Array();
// When someone speaks, listen to see if it is one of the q commands
bot.on('speak', function (data) {
var name = data.name;
var text = data.text;
var userId = data.userid;
// q+ :: Add to Queue
if (text.toLowerCase().match(/^q\+$/)) {
//First we look to see if they are already a DJ.
//Index is the position in the queue that this person's name is found.
//If its not found, -1 is returned.
var index = queue.indexOf(name);
isCurrentDJ(userId, function(isDJ) {
//If the user is already in the queue
if(isDJ){
//Tell them they are already in there
bot.speak('You are already a DJ, '+name);
} else if(index > -1){
//Otherwise if they are already a DJ tell them that
bot.speak('You are already on the list, '+name);
}else{
//Otherise if they are not in the queue add user to end of queue
queue.push(name);
//Tell them about it and the updated q
bot.speak(name+' has been added to queue.');
}
});
}
// q- :: Remove from Queue
if (text.toLowerCase().match(/^q\-$/)) {
//Index is the position in the array that this person's name is found.
//If its not found, -1 is returned.
var index = queue.indexOf(name);
//If the user is in the queue
if(index > -1){
//REMOVE THEM
queue.splice(index,1)
//Tell them that they've been removed
bot.speak(name+' has been removed from the queue.');
} else{
//Otherise tell them they are not on the queue
bot.speak(name+' is not in the queue.');
}
}
// q? :: Display q
if (text.toLowerCase().match(/^q\?$/)) {
//If the queue is not empty
if(queue.length > 0){
//Define displayQ variable
var displayQ = "";
//Logic to show queue
var i;
for(i=0; i < queue.length; i++){
var placeInQ = i + 1;
displayQ += ' ['+placeInQ+'] '+ queue[i];
}
//Reply with the queue list
bot.speak('Queue: '+ displayQ);
}else{
//Otherwise say there is no queue.
bot.speak('The queue is empty. Type q+ to add youself.');
console.log('User typed "q?"');
}
}
// q.shift :: Remove the first person from the queue, but only if triggered by a room mod
if (text.toLowerCase().match(/^q\.shift$/)) {
isRoomMod(userId, function(isMod) {
//If the user is already in the queue
if(isMod){
//If this person is a mod, shift the queue (aka remove the first person off the queue.)
queue.shift();
} else {
//Otherwise if they aren't a mod and don't have permission, tell them
bot.speak('You can\'t tell me what to do, @'+name+'!');
}
});
}
// q.clear :: Clear the queue entirely
if (text.toLowerCase().match(/^q\.clear$/)) {
isRoomMod(userId, function(isMod) {
//If the user is already in the queue
if(isMod){
//If this person is a mod, shift the queue (aka remove the first person off the queue.)
queue = [];
} else {
//Otherwise if they aren't a mod and don't have permission, tell them
bot.speak('You can\'t tell me what to do, @'+name+'!');
}
});
}
}); //Closes the speak listener for the Queue script
//When a user leaves the room, if they are on the q you have to remove them
// on('deregistered', function ([data](https://github.com/alaingilbert/Turntable-API/blob/master/turntable_data/deregistered.js)) { })
bot.on('deregistered', function (data) {
var user = data.user[0];
var name = user.name;
var userId = user.userid;
//Index is the position in the array that this person's name is found.
//If its not found, -1 is returned.
var index = queue.indexOf(name);
//If the user is in the queue
if(index > -1){
//REMOVE THEM
queue.splice(index,1)
//Tell the room that the person left and has been removed
bot.speak(name+' is too good to q- before (s)he left the room. What a dick! Good thing I\'m here :)');
}
});
//When a user steps up to become a DJ, if they are first in line allow it, otherwise remove them from the table and tell them why.
// on('add_dj', function ([data](https://github.com/alaingilbert/Turntable-API/blob/master/turntable_data/add_dj.js)) { })
bot.on('add_dj', function (data) {
var user = data.user[0];
var name = user.name;
var userId = user.userid;
var firstInLine = queue[0];
console.log('This user is first in line: '+firstInLine); //QA
console.log('This user just stepped up to DJ: '+name); //QA
if(queue.length > 0){
if(name == firstInLine){
queue.shift();
console.log('This is the right DJ'); //QA
} else{
bot.remDj(userId);
bot.speak('Nice try @'+name+', but it is actually @'+firstInLine+'\'s turn! If you aren\' already in the queue, type \'q+\' to get on there.');
console.log('This is the wrong DJ'); //QA
}
}
});
//When a DJ steps down, alert the next person in line to get up there
// on('rem_dj', function ([data](https://github.com/alaingilbert/Turntable-API/blob/master/turntable_data/rem_dj.js)) { })
bot.on('rem_dj', function (data) {
var name = data.name;
var userId = data.userid;
var firstInLine = queue[0];
if(queue.length > 0){
bot.speak('Hey @'+firstInLine+' I hope you\'re ready cause it\'s your turn to lay down something nasty!');
}
});
/***************************************************************************
* STANDALONE FUNCTIONS
* The following functions are used for the Queue Script, and I'm sure will also be reused elsewhere.
*/
// FUNCTION :: isRoomMod(user_id, callback) ::
//Function to determine if the user is currently a DJ
function isRoomMod(user_id, callback){
bot.roomInfo(false, function (data) {
var roomModList = data.room.metadata.moderator_id;
for (i = 0; i < roomModList.length; i++){
if (roomModList[i] == user_id){
console.log('recognized as a room moderator');
return callback(true);
}
}
callback(false);
});
}
// FUNCTION :: isCurrentDJ(user_id, callback) ::
//Function to determine if the user is currently a DJ
function isCurrentDJ(user_id, callback){
bot.roomInfo(false, function (data) {
var djList = data.room.metadata.djs;
for (i = 0; i < djList.length; i++){
if (djList[i] == user_id){
return callback(true);
}
}
callback(false);
});
}
// FUNCTION :: getHeadCount(callback) ::
//Function to determine how many users are in the room
function getHeadCount(callback){
bot.roomInfo(false, function (data) {
var userList = data.users;
return callback(userList.length);
});
}
// FUNCTION :: getCurrentSongId(callback) ::
//Function to fetch the current songId
function getCurrentSongId(callback){
bot.roomInfo(true, function (data) {
var songId = data.room.metadata.current_song._id;
return callback(songId);
});
}
// FUNCTION :: getActiveDj(callback) ::
//Function to fetch the DJ that is currently spinning
function getActiveDjId(callback){
bot.roomInfo(true, function (data) {
var activeDj = data.room.metadata.current_dj;
console.log("Active DJ:"+activeDj);
return callback(activeDj);
});
}
// FUNCTION :: addCurrentSongToPlaylist(callback) ::
//This function will add the the given song ID to the bot's playlist, if it doesn't already exist
//CALLBACK VAR -- TRUE if the song was added -- FALSE if the song already existed
function addCurrentSongToPlaylist(songId, callback){
bot.playlistAll(function (data) {
//Grab the bot's playlist
var playList = data.list;
//Variabe to determine if the bot already has this song
var exist = 0;
//Loop through the bot's playlist. If the current song is already there, set exist=1
for (var i=0; i<playList.length; i++) {
if(songId == playList[i]._id){
exist = 1;
}
}
console.log("Exist: "+exist); //QA
//If the bot does not already have the song, add it to the end of the playlist
if(exist == 0){
bot.playlistAdd(songId, playList.length);
bot.snag();
console.log("Song is not already in playlist, ADD! Total Tracks: "+playList.length); //QA
return callback(true);
}else{
//Otherwise if the bot already has the song, tell the room
console.log("Song already in playlist, NOT added Total Tracks: "+playList.length);
return callback(false);
}
});
}
// FUNCTION :: getAwesomeCount(callback) ::
//Function to determine how many awesomes a song has
function getAwesomeCount(callback){
bot.roomInfo(false, function (data) {
var upvotes = data.room.metadata.upvotes;
return callback(upvotes);
});
}
// FUNCTION :: getRandomArbitaryNumber(min, max) ::
//Returns a random number between the min and the max
function getRandomArbitaryNumber (min, max) {
return Math.random() * (max - min) + min;
}
// FUNCTION :: shuffleBotPlaylist() ::
//Takes a random 20% of songs in the bot's playlist and moves them to the top of the playlist
//WARNING - THIS FUNCTION DELETES SONGS!! DO NOT USE!!
function shuffleBotPlaylist () {
bot.playlistAll(function (data) {
//Grab the bot's playlist
var playList = data.list;
//Get 20% of the list length
var percentageOfPlaylist = Math.round(playList.length * .2);
console.log("% of playlist: "+playList.length+" /2 = "+percentageOfPlaylist); //QA
//Take a random 50 songs and bring them to the top of the playlist
for (var i=0; i<percentageOfPlaylist; i++) {
//get a random song index
var s = Math.round(getRandomArbitaryNumber(1,playList.length-1));
console.log("rando: "+s); //QA
//Bring that song to the top
bot.playlistReorder(s, 0);
}
console.log(data); //QA
});
}
// FUNCTION :: getRandomIndex(theArray) ::
//Pass in an array and this function will return a random index for the array
function getRandomIndex (theArray) {
return Math.round(getRandomArbitaryNumber(0,theArray.length-1));
}
// FUNCTION :: speakPlaylistLength() ::
//Tells the room how many songs the bot has queued up
function speakPlaylistLength () {
bot.playlistAll(function (data) {
//Grab the bot's playlist
var playList = data.list;
//Return length
bot.speak("I currently have "+playList.length+" songs in my playlist sucka!");
});
}
// FUNCTION :: logPlaylist() ::
//This is really just for QA purposes - it logs the bots entire playlist
function logPlaylist() {
bot.playlistAll(function (data) {
console.log(data); //QA
});
}
res.write('<h1>Things are working at checkpoint G.</h1>');
//__CLOSING SERVER STUFF___________________________________________________________ */
// close the response
res.end();
}).listen(process.env.PORT || 8888); // the server will listen on "process.env.PORT" if it exists (Heroku!), or port 8888 as a default fallback
console.log("END - Listening on http://127.0.0.1:8888");