-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbot.js
More file actions
1148 lines (1125 loc) · 56.6 KB
/
bot.js
File metadata and controls
1148 lines (1125 loc) · 56.6 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
var PlugAPI = require('plugbotapi'); //Use 'git clone git@github.com:plugCubed/plugAPI.git' in your node_modules
var bot = new PlugAPI({
"email": "jbader@conncoll.edu",
"password": "xxx"
});
var ROOM = 'terminally-chillin';
bot.connect(ROOM); // The part after https://plug.dj
var Lastfm = require('simple-lastfm'); //Use 'npm install simple-lastfm'
var lastfm = new Lastfm({ //Get own last.fm account with api_key, api_secret, username, and password
api_key: 'd657909b19fde5ac1491b756b6869d38',
api_secret: '571e2972ae56bd9c1c6408f13696f1f3',
username: 'BaderBombs',
password: 'xxx'
});
var LastfmAPI = require('lastfmapi');
var lfm = new LastfmAPI({
'api_key' : 'd657909b19fde5ac1491b756b6869d38',
'secret' : '571e2972ae56bd9c1c6408f13696f1f3'
});
var api = require('dictionaryapi'); //Use 'npm install dictionaryapi'
var Wiki = require("wikijs"); //Use 'npm install wikijs'
var google_geocoding = require('google-geocoding'); //Use 'npm install google-geocoding'
var weather = require('weathers'); //Use 'npm install weathers'
var mlexer = require('math-lexer'); //Use 'npm install math-lexer'
var MsTranslator = require('mstranslator'); //Use 'npm install mstranslator'
var client = new MsTranslator({client_id:"PlugBot", client_secret: "uScbNIl2RHW15tIQJC7EsocKJsnACzxFbh2GqdpHfog="}); //Get own Microsoft Translator account with client_id and client_secret
var translateList = [];
var request = require('request'); //Use 'npm install request'
var time = require('time'); //Use 'npm install time'
var reconnect = function() {
bot.connect(ROOM);
};
bot.on('close', reconnect);
bot.on('error', reconnect);
var media = null;
var waitlist = null;
var dj = null;
var staff = null;
var users = null;
var roomScore = null;
//Event which triggers when the bot joins the room
bot.on('roomJoin', function(data) {
bot.getMedia(function(plugMedia){
media = plugMedia;
});
bot.getWaitList(function(plugWaitlist){
waitlist = plugWaitlist;
});
bot.getDJ(function(plugDJ){
dj = plugDJ;
});
bot.getStaff(function(plugStaff){
staff = plugStaff;
});
bot.getUsers(function(plugUsers){
users = plugUsers;
});
console.log("I'm live!");
});
//Event which triggers when new DJ starts playing a song
bot.on('advance', function(data) {
bot.getMedia(function(plugMedia){
media = plugMedia;
});
bot.getDJ(function(plugDJ){
dj = plugDJ;
});
bot.getWaitList(function(plugWaitlist){
waitlist = plugWaitlist;
});
var noSpaceName = media.author.toLowerCase().replace(/ +/g, "");
var wordCheck = false;
var authorWords = media.author.toLowerCase().split(' ');
for (var i=0; i < authorWords.length; i++){
//console.log(authorWords[i]);
if (dj.username.toLowerCase().indexOf(authorWords[i]) > -1 && authorWords[i].match(/[a-zA-Z]/g)){
wordCheck = true;
}
}
//console.log("No Space Name: " + noSpaceName + ", Word Check: " + wordCheck + ", Author: " + dj.username.toLowerCase());
if (dj.username.toLowerCase() == media.author.toLowerCase() || dj.username.toLowerCase() == noSpaceName || wordCheck){
var link = 'http://api.soundcloud.com/users.json?q=' + media.author + '&consumer_key=apigee';
request(link, function (error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
if (info[0] != undefined){
bot.chat(info[0].username + ": " + info[0].permalink_url);
}
}
});
}
// if (data.lastPlay.score != null) {
// bot.chat("Last song: :thumbsup: " + data.lastPlay.score.positive + " :star: " + data.lastPlay.score.grabs + " :thumbsdown: " + data.lastPlay.score.negative);
// bot.chat(":musical_note: " + data.dj.username + " started playing \"" + data.media.title + "\" by " + data.media.author + " :musical_note:");
// }
});
//Event which triggers when the waitlist changes
bot.on('waitListUpdate', function(data) {
bot.getWaitList(function(plugWaitlist){
waitlist = plugWaitlist;
});
bot.getStaff(function(plugStaff){
staff = plugStaff;
});
bot.getUsers(function(plugUsers){
users = plugUsers;
});
});
//Event which triggers when user skips his song
bot.on('skip', function(data) {
bot.getMedia(function(plugMedia){
media = plugMedia;
});
bot.getWaitList(function(plugWaitlist){
waitlist = plugWaitlist;
});
bot.getDJ(function(plugDJ){
dj = plugDJ;
});
bot.getStaff(function(plugStaff){
staff = plugStaff;
});
bot.getUsers(function(plugUsers){
users = plugUsers;
});
});
//Event which triggers when a mod skips the song
bot.on('modSkip', function(data) {
bot.getMedia(function(plugMedia){
media = plugMedia;
});
bot.getWaitList(function(plugWaitlist){
waitlist = plugWaitlist;
});
bot.getDJ(function(plugDJ){
dj = plugDJ;
});
bot.getStaff(function(plugStaff){
staff = plugStaff;
});
bot.getUsers(function(plugUsers){
users = plugUsers;
});
});
//Still figuring out how this works
bot.on('floodChat', function(data) {
bot.chat("flood!");
});
//Event which triggers with a user joins the room
bot.on('userJoin', function(data) {
//console.log(data);
bot.getStaff(function(plugStaff){
staff = plugStaff;
});
bot.getUsers(function(plugUsers){
users = plugUsers;
});
});
//Event which triggers when the current song receives 5 mehs, skips the song
var setmehs = false;
var mehs = 4;
bot.on('vote', function(data) {
roomScore = bot.getRoomScore();
if (roomScore.negative > mehs && setmehs){
bot.chat("@" + dj.username + " Your tune does not fall within the established genre of the Chillout Mixer. Please type .noplay or .yesplay for more info.");
bot.moderateForceSkip(dj.id);
}
});
//Event which triggers when anyone chats
bot.on('chat', function(data) {
var command=data.message.split(' ')[0];
var firstIndex=data.message.indexOf(' ');
var qualifier="";
if (firstIndex!=-1){
qualifier = data.message.substring(firstIndex+1, data.message.length);
}
qualifier=qualifier.replace(/'/g, '\'');
qualifier=qualifier.replace(/"/g, '\"');
qualifier=qualifier.replace(/&/g, '\&');
qualifier=qualifier.replace(/</gi, '\<');
qualifier=qualifier.replace(/>/gi, '\>');
switch (command)
{
case ".commands": //Returns a list of the most important commands
bot.chat("List of Commands: .about, .album, .artist, .calc, .define, .events, .facebook, .forecast, .genre, .google, .github, .props, .similar, .soundcloud, .temp, .time, .track, .translate, .twitter, and .wiki");
break;
case ".modcommands": //Returns a list of the most important commands
bot.chat("List of Mod Commands: .autoskip, .autotranslate, .banuser, .front, .join, .leave, .meh, .move, .setmehs, .skip, .unskip, .untranslate, .warn, and .woot");
break;
case ".hey": //Makes the bot greet the user
case ".yo":
case ".hi":
case ".bot":
bot.chat("Well hey there! @"+data.un);
break;
case ".yesplay": //Gives the room criteria for acceptable genres
bot.chat("Types of music we encourage in the Chillout Mixer: Trip Hop, Ambient, Psybient, Dub, Liquid DnB, Acid Jazz, as well as some occasional instrumental chillwave/hip hop/trap when it fits. Think downtempo... soothing, relaxing electronica.");
break;
case ".noplay": //Gives the room criteria for unacceptable genres
bot.chat("DO NOT PLAY: Rock genres (Indie/Post/Alt/etc), Wubs (Chillstep/Dubstep/Brostep), EDM - Dance Music (Trance/House/etc), or vocal Hip Hop/Rap/Trap. Music MUST be chill and fit the Rooms flow. Repeated failure to obey these rules may = ban.")
break;
case ".warn": //Skips a user playing an off-genre song
for (var i=0; i<staff.length; i++){
if (staff[i].username == data.un && staff[i].role > 1){
bot.chat("@" + dj.username + " Your tune does not fall within the established genre of the Chillout Mixer. Please type .noplay or .yesplay for more info.");
bot.moderateForceSkip(dj.id);
}
}
break;
case ".banuser": //Bans a user from the room permanently with .banuser [givenUser]
for (var i=0; i<staff.length; i++){
if (staff[i].username == data.un && staff[i].role > 1){
for (var j=0; j<users.length; j++){
if (users[j].username == qualifier){
bot.moderateBanUser(users[j].id);
}
}
}
}
break;
case ".move": //Moves a user in the waitlist with .move [givenUser], [givenSpot]
for (var i=0; i<staff.length; i++){
if (staff[i].username == data.un && staff[i].role > 1 && staff[i].role > 1){
for (var j=0; j<users.length; j++){
if (users[j].username == qualifier.split(' ')[0]){
if (Number(qualifier.split(' ')[1]) > waitlist.length){
bot.chat("Sorry, there are only " + waitlist.length + " people in the waitlist, please try again.");
}
else{
bot.moderateMoveDJ(users[j].id, Number(qualifier.split(' ')[1]));
}
}
}
}
}
break;
case ".front": //Moves a user to the front of the waitlist with .front [givenUser]
for (var i=0; i<staff.length; i++){
if (staff[i].username == data.un && staff[i].role > 1 && staff[i].role > 1){
for (var j=0; j<users.length; j++){
if (users[j].username == qualifier.split(' ')[0]){
bot.moderateMoveDJ(users[j].id, 1);
}
}
}
}
break;
case ".woot": //Makes the bot cast an upvote
for (var i=0; i<staff.length; i++){
if (staff[i].username == data.un && staff[i].role > 1){
bot.chat("I can dig it!");
bot.woot();
}
}
break;
case ".meh": //Makes the bot cast a downvote
for (var i=0; i<staff.length; i++){
if (staff[i].username == data.un && staff[i].role > 1){
bot.chat("Please... make it stop :unamused:");
bot.meh();
}
}
break;
case ".props": //Makes the bot give props to the user
case ".propsicle":
bot.chat("Nice play! @"+dj.username);
break;
case ".join": //Makes the bot join the waitlist
for (var i=0; i<staff.length; i++){
if (staff[i].username == data.un && staff[i].role > 1){
bot.djJoin();
bot.chat("Joining waitlist!");
}
}
break;
case ".leave": //Makes the bot leave the waitlist
for (var i=0; i<staff.length; i++){
if (staff[i].username == data.un && staff[i].role > 1){
bot.djLeave();
bot.chat("Leaving waitlist.");
}
}
break;
case ".skip": //Makes the bot skip the current song
for (var i=0; i<staff.length; i++){
if (staff[i].username == data.un && staff[i].role > 1){
bot.chat("Skipping!");
bot.moderateForceSkip(dj.id);
}
}
break;
case ".github": //Returns a link to the bot's GitHub repository
bot.chat("Check me out on GitHub! https://github.com/JBader89/PlugBot");
break;
case ".about": //Returns a description of the bot's purpose, creator, and usability
bot.chat("Hey, I'm GeniusBot, your personal encyclopedic web scraper. My father, TerminallyChill, created me. For a list of my commands, type .commands");
break;
case ".fb":
case ".facebook": //Returns a link to the Chillout Mixer Facebook page
bot.chat("Like us on Facebook: https://www.facebook.com/ChilloutMixer");
break;
case ".twitter": //Returns a link to the Chillout Mixer Twitter page
bot.chat("Follow us on Twitter: https://www.twitter.com/ChilloutMixer");
break;
case ".damnright": //Commands just for fun
bot.chat("http://i.imgur.com/5Liksxa.gif");
break;
case ".highfive":
bot.chat("http://i.imgur.com/KevhNWt.gif");
break;
case ".justdoit":
bot.chat("http://i.imgur.com/W8GgWzh.gif");
break;
case ".timeforwork":
bot.chat("http://i.imgur.com/LqU7LPl.gif");
break;
case ".saul":
bot.chat("http://i.imgur.com/URNSlqT.gif");
break;
case ".smh":
case ".no":
bot.chat("http://i.imgur.com/93j8cA1.gif");
break;
case ".touche":
bot.chat("http://replygif.net/i/1108.gif");
break;
case ".holyshit":
case ".ohsnap":
bot.chat("http://i.imgur.com/Qtcjvi4.gif");
break;
case ".feels":
bot.chat("http://i.imgur.com/axsIhkT.gif");
break;
case ".pleasestop":
bot.chat("http://i.imgur.com/QHfqz3L.gif");
break;
case ".yeah":
case ".yeah!":
bot.chat("http://i.imgur.com/jmw4OLz.gif");
break;
case ".jesse":
bot.chat("http://i.imgur.com/34qU4qC.gif");
break;
case ".dontmove":
bot.chat("http://i.imgur.com/bzGFChQ.gif");
break;
case ".hello":
bot.chat("http://cdn.makeagif.com/media/8-12-2013/R7sSHU.gif");
break;
case ".boom":
bot.chat("http://i.imgur.com/tKd5J2x.gif");
break;
case ".what":
bot.chat("http://i.imgur.com/RcNHW.gif");
break;
case ".argh":
case ".pizza":
case ".gahhh":
bot.chat("http://i53.tinypic.com/24ep2xc.gif");
break;
case ".eggsfortheprettylady":
bot.chat("Wakey wakey :egg: and bakey, fo' the pretty lady @Rightclik");
break;
case ".pita":
bot.chat("http://chillouttent.org/p-i-t-a/");
break;
case ".artist": //Returns Last.fm info about the current artist, .artist [givenArtist] returns Last.fm info about a given artist
var artistChoice="";
if (qualifier==""){
artistChoice=media.author;
}
else{
artistChoice=qualifier;
}
lastfm.getArtistInfo({
artist: artistChoice,
callback: function(result) {
if (result.success==true){
if (result.artistInfo.bio.summary!=""){
var summary=result.artistInfo.bio.summary;
summary=summary.replace(/(")/g, '"');
summary=summary.replace(/(&)/g, '&');
summary=summary.replace(/(é)/g, 'é');
summary=summary.replace(/(á)/g, 'á');
summary=summary.replace(/(ä)/g, 'ä');
summary=summary.replace(/(í)/g, 'í');
summary=summary.replace(/(ó)/g, 'ó');
summary=summary.replace(/(Š)/g, 'Š');
summary=summary.replace(/<[^>]+>/g, '');
if (summary.indexOf(" 1) ") != -1){
summary=summary.substring(summary.lastIndexOf(" 1) ")+4);
if (summary.indexOf(" 2) ") != -1){
summary=summary.substring(0, summary.lastIndexOf(" 2)"));
}
}
else if (summary.indexOf(" 1. ") != -1){
summary=summary.substring(summary.lastIndexOf(" 1. ")+4);
if (summary.indexOf(" 2. ") != -1){
summary=summary.substring(0, summary.lastIndexOf(" 2."));
}
}
else if (summary.indexOf(" (1) ") != -1){
summary=summary.substring(summary.lastIndexOf(" (1) ")+4);
if (summary.indexOf(" (2) ") != -1){
summary=summary.substring(0, summary.lastIndexOf(" (2)"));
}
}
if (summary.length>250){
summary=summary.substring(0, 247)+"...";
}
bot.chat(summary);
var lastfmArtist=artistChoice;
lastfmArtist=lastfmArtist.replace(/ /g, '+');
bot.chat("For more info: http://www.last.fm/music/" + lastfmArtist);
}
else {
bot.chat("No artist info found.");
}
}
else {
bot.chat("No artist info found.");
}
}
});
break;
case ".track": //Returns Last.fm info about the current song
lastfm.getTrackInfo({
artist: media.author,
track: media.title,
callback: function(result) {
if (result.success==true){
if (result.trackInfo.wiki!=undefined){
var summary=result.trackInfo.wiki.summary;
summary=summary.replace(/(")/g, '"');
summary=summary.replace(/(&)/g, '&');
summary=summary.replace(/(é)/g, 'é');
summary=summary.replace(/(á)/g, 'á');
summary=summary.replace(/(ä)/g, 'ä');
summary=summary.replace(/(í)/g, 'í');
summary=summary.replace(/(ó)/g, 'ó');
summary=summary.replace(/(Š)/g, 'Š');
summary=summary.replace(/<[^>]+>/g, '');
if (summary.length>250){
summary=summary.substring(0, 247)+"...";
}
bot.chat(summary);
}
else {
bot.chat("No track info found.");
}
}
else {
bot.chat("No track info found.");
}
}
});
break;
case ".genre": //Returns the genres of the current artist, .genre [givenArtist] returns the genres of a given artist
var artistChoice="";
if (qualifier==""){
artistChoice=media.author;
trackChoice=media.title;
}
else{
artistChoice=qualifier;
trackChoice=null;
}
lastfm.getTags({
artist: artistChoice,
track: trackChoice,
callback: function(result) {
var tags = "";
if (result.tags!=undefined){
for (var i=0; i<result.tags.length; i++){
tags+=result.tags[i].name;
tags+=", ";
}
tags=tags.substring(0, tags.length-2);
}
if (qualifier==""){
if (tags!=""){
bot.chat("Genre of "+trackChoice+" by "+artistChoice+": "+tags);
}
else{
bot.chat("No genre found.");
}
}
else{
if (tags!=""){
bot.chat("Genre of "+artistChoice+": "+tags);
}
else{
bot.chat("No genre found.");
}
}
}
});
break;
case ".album": //Returns the album of the current song
lfm.track.getInfo({
'artist' : media.author,
'track' : media.title
}, function (err, track) {
if (track!=undefined){
lfm.album.getInfo({
'artist' : media.author,
'album' : track.album.title
}, function (err, album) {
var albumMessage = track.name + " is from the album " + track.album.title;
if (album.wiki!=undefined){
if (album.wiki.summary.indexOf('released on') != -1){
var year = album.wiki.summary.substring(album.wiki.summary.indexOf('released on')).split(' ')[4].substring(0,4);
albumMessage = albumMessage + " (" + year + ")";
}
}
bot.chat(albumMessage);
bot.chat("Check out the full album: " + track.album.url);
});
}
else{
bot.chat("No album found.");
}
});
break;
case ".similar": //Returns similar artists of the current artist, .similar [givenArtist] returns similar artists of a given artist
var artistChoice="";
if (qualifier==""){
artistChoice=media.author;
}
else{
artistChoice=qualifier;
}
lfm.artist.getSimilar({
'limit' : 7,
'artist' : artistChoice,
'autocorrect' : 1
}, function (err, similarArtists) {
if (similarArtists!=undefined){
var artists = '';
for (var i=0; i<similarArtists.artist.length; i++){
artists = artists + similarArtists.artist[i].name + ", ";
}
artists = artists.substring(0, artists.length-2);
bot.chat("Similar artists to " + artistChoice + ": " + artists);
}
else{
bot.chat("No similar artists found.");
}
});
break;
case ".events": //Returns the artist's upcoming events, .events [givenArtist] returns a given artist's upcoming events
var artistChoice="";
if (qualifier==""){
artistChoice=media.author;
}
else{
artistChoice=qualifier;
}
lfm.artist.getEvents({
'limit' : 3,
'artist' : artistChoice
}, function (err, events) {
if (events!=undefined){
var upcomingEvents = '';
if (!(events.event instanceof Array)){
events.event = [events.event];
}
for (var i=0; i<events.event.length; i++){
var day = '';
if (events.event[i].startDate.split(/\s+/).slice(1,2).join(" ").slice(0,1) == '0'){
day = events.event[i].startDate.split(/\s+/).slice(1,2).join(" ").slice(1,2);
}
else{
day = events.event[i].startDate.split(/\s+/).slice(1,2).join(" ");
}
upcomingEvents = upcomingEvents + events.event[i].startDate.split(/\s+/).slice(2,3).join(" ") + "/" + day + "/" + events.event[i].startDate.split(/\s+/).slice(3,4).join(" ").slice(-2) + " at " + events.event[i].venue.name + " in " + events.event[i].venue.location.city + ", " + events.event[i].venue.location.country + "; ";
}
upcomingEvents = upcomingEvents.substring(0, upcomingEvents.length-2);
upcomingEvents=upcomingEvents.replace(/Jan/g, '1');
upcomingEvents=upcomingEvents.replace(/Feb/g, '2');
upcomingEvents=upcomingEvents.replace(/Mar/g, '3');
upcomingEvents=upcomingEvents.replace(/Apr/g, '4');
upcomingEvents=upcomingEvents.replace(/May/g, '5');
upcomingEvents=upcomingEvents.replace(/Jun/g, '6');
upcomingEvents=upcomingEvents.replace(/Jul/g, '7');
upcomingEvents=upcomingEvents.replace(/Aug/g, '8');
upcomingEvents=upcomingEvents.replace(/Sep/g, '9');
upcomingEvents=upcomingEvents.replace(/Oct/g, '10');
upcomingEvents=upcomingEvents.replace(/Nov/g, '11');
upcomingEvents=upcomingEvents.replace(/Dec/g, '12');
bot.chat("Upcoming events for " + artistChoice + ": " + upcomingEvents);
}
else{
bot.chat("No upcoming events found.");
}
});
break;
case ".sc":
case ".soundcloud": //Returns the current artist's SC page, .soundcloud [givenArtist] returns a given artist's SC page
var artistChoice="";
if (qualifier==""){
artistChoice = media.author;
}
else{
artistChoice=qualifier;
}
var link = 'http://api.soundcloud.com/users.json?q=' + artistChoice + '&consumer_key=apigee';
request(link, function (error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
if (info[0] != undefined){
bot.chat(info[0].username + ": " + info[0].permalink_url);
}
else{
bot.chat("No soundcloud found.");
}
}
});
break;
// case ".grab": //Makes the bot grab the current song
// for (var i=0; i<staff.length; i++){
// if (staff[i].username == data.un && staff[i].role > 1){
// bot.getPlaylists(function(playlists) {
// console.log(playlists);
// for (var i=0; i<playlists.length; i++){
// if (playlists[i].active){
// if (playlists[i].count!=200){
// var selectedID=playlists[i].id;
// bot.chat("Added to my "+playlists[i].name+" playlist.");
// }
// else{
// bot.createPlaylist("Library "+playlists.length+1);
// bot.activatePlaylist(playlists[playlists.length-1].id);
// var selectedID=playlists[playlists.length-1].id;
// bot.chat("Added to "+playlists[playlists.length-1].name+" playlist.");
// }
// }
// }
// bot.addSongToPlaylist(selectedID, media.id);
// });
// }
// }
// break;
case ".define": //Returns the Merriam-Webster dictionary definition of a given word with .define [givenWord]
if (qualifier!=""){
var dict = new api.DictionaryAPI(api.COLLEGIATE, 'cf2109fd-f2d0-4451-a081-17b11c48069b');
var linkQualifier=qualifier;
linkQualifier=linkQualifier.replace(/ /g, '%20');
dict.query(linkQualifier.toLowerCase(), function(err, result) {
result=result.replace(/<vi>(.*?)<\/vi>|<dx>(.*?)<\/dx>|<dro>(.*?)<\/dro>|<uro>(.*?)<\/uro>|<svr>(.*?)<\/svr>|<sin>(.*?)<\/sin>|<set>(.*?)<\/set>|<pl>(.*?)<\/pl>|<pt>(.*?)<\/pt>|<ss>(.*?)<\/ss>|<ca>(.*?)<\/ca>|<art>(.*?)<\/art>|<ew>(.*?)<\/ew>|<hw>(.*?)<\/hw>|<sound>(.*?)<\/sound>|<pr>(.*?)<\/pr>|<fl>(.*?)<\/fl>|<date>(.*?)<\/date>|<sxn>(.*?)<\/sxn>|<ssl>(.*?)<\/ssl>/g, '');
result=result.replace(/<vt>(.*?)<\/vt>/g,' ');
result=result.replace(/<\/sx> <sx>|<sd>/g,', ');
result=result.replace(/\s{1,}<sn>/g, '; ');
result=result.replace(/\s{1,}<un>/g, ': ');
result=result.replace(/<(?!\/entry\s*\/?)[^>]+>/g, '');
result=result.replace(/\s{1,}:/g,': ');
if (result.indexOf(":") != -1 && (result.indexOf(":")<result.indexOf("1:") || result.indexOf("1:") == -1) && (result.indexOf(":")<result.indexOf("1 a") || result.indexOf("1 a") == -1)) {
result=result.substring(result.indexOf(":")+1);
}
else if (result.indexOf("1:") != -1 || result.indexOf("1 a") != -1){
if ((result.indexOf("1:")<result.indexOf("1 a") && result.indexOf("1:")!=-1) || result.indexOf("1 a")==-1){
result=result.substring(result.indexOf("1:"));
}
else{
result=result.substring(result.indexOf("1 a"));
}
}
result=result.substring(0, result.indexOf("</entry>"));
result=result.replace(/\s{1,};/g, ';');
result=result.replace(/\s{1,},/g, ',');
if (result != ''){
if (result.length>250){
result=result.substring(0, 247)+"...";
}
bot.chat(result);
//bot.chat("For more info: http://www.merriam-webster.com/dictionary/" + linkQualifier);
}
else{
bot.chat("No definition found.");
}
});
}
else{
bot.chat("Try .define followed by something to look up.");
}
break;
case ".wiki": //Returns Wikipedia article summary of a given query with .define [givenWord]
if (qualifier!=""){
Wiki.page(qualifier, false, function(err, page){
page.summary(function(err, summary){
if (summary!=undefined){
Wiki.page(qualifier, false, function(err, page){
page.html(function(err, html){
if (html.indexOf('<ul>')!=-1){
html=html.substring(0, html.indexOf('<ul>'));
}
html=html.replace(/<[^>]+>/g, '');
Wiki.page(qualifier, false, function(err, page){
page.summary(function(err, summary){
if (summary!=undefined){
if (summary=="" || summary.indexOf("This is a redirect")!=-1){
summary="redirect "+html;
}
if (summary.indexOf('may refer to:')!=-1 || summary.indexOf('can refer to:')!=-1 || summary.indexOf('may also refer to:')!=-1 || summary.indexOf('may refer to the following:')!=-1 || summary.indexOf('may stand for:')!=-1){
bot.chat("This may refer to several things - please be more specific.");
var queryChoice=qualifier;
queryChoice=queryChoice.replace(/ /g, '_');
bot.chat("For more info: http://en.wikipedia.org/wiki/" + queryChoice);
}
else if (summary.substring(0,8).toLowerCase()=="redirect"){
subQuery='';
if (summary.indexOf('#')==-1){
if (summary.substring(8,9)==' '){
var query=summary.substring(9);
}
else{
var query=summary.substring(8);
}
}
else{
var query=summary.substring(9, summary.indexOf('#'));
subQuery=summary.substring(summary.indexOf('#')+1);
}
Wiki.page(query, false, function(err, page2){
page2.content(function(err, content){
if (content!=undefined){
if (content.indexOf('may refer to:')!=-1 || content.indexOf('can refer to:')!=-1 || content.indexOf('may also refer to:')!=-1 || content.indexOf('may refer to the following:')!=-1 || content.indexOf('may stand for:')!=-1){
bot.chat("This may refer to several things - please be more specific.");
}
else if (subQuery!=''){
content=content.substring(content.indexOf("=== "+subQuery+" ===")+8+subQuery.length);
if (content.length>250){
content=content.substring(0, 247)+"...";
}
bot.chat(content);
}
else{
if (content.length>250){
content=content.substring(0, 247)+"...";
}
bot.chat(content);
}
var queryChoice=qualifier;
queryChoice=queryChoice.replace(/ /g, '_');
bot.chat("For more info: http://en.wikipedia.org/wiki/" + queryChoice);
}
else{
bot.chat("No wiki found.");
}
});
});
}
else{
if (summary.length>250){
summary=summary.substring(0, 247)+"...";
}
bot.chat(summary);
var queryChoice=qualifier;
queryChoice=queryChoice.replace(/ /g, '_');
bot.chat("For more info: http://en.wikipedia.org/wiki/" + queryChoice);
}
}
else{
bot.chat("No wiki found.");
}
});
});
});
});
}
else{
bot.chat("No wiki found.");
}
});
});
}
else{
bot.chat("Try .wiki followed by something to look up.");
}
break;
case ".forecast": //Returns a four day forecast of the weather in given city with .forecast [givenCity], [givenState]
case ".weather":
if (qualifier==""){
bot.chat("Try .forecast followed by a US state, city, or zip to look up.");
}
else{
google_geocoding.geocode(qualifier, function(err, location) {
if (location!=null){
weather.getWeather(location.lat, location.lng, function(err, data){
if (data!=null){
var weekForecast="Forecast for "+data.location.areaDescription+": Current: "+data.currentobservation.Temp+"°F "+data.currentobservation.Weather;
for (var i=0; i<7; i++){
var day = data.time.startPeriodName[i].split(' ');
if (day[1]!='Night'){
weekForecast=weekForecast+"; "+data.time.startPeriodName[i]+": ";
}
else{
weekForecast=weekForecast+", ";
}
weekForecast=weekForecast+data.time.tempLabel[i]+": "+data.data.temperature[i]+"°F";
}
weekForecast=weekForecast.replace(/Sunday/g, 'Sun');
weekForecast=weekForecast.replace(/Monday/g, 'Mon');
weekForecast=weekForecast.replace(/Tuesday/g, 'Tues');
weekForecast=weekForecast.replace(/Wednesday/g, 'Wed');
weekForecast=weekForecast.replace(/Thursday/g, 'Thurs');
weekForecast=weekForecast.replace(/Friday/g, 'Fri');
weekForecast=weekForecast.replace(/Saturday/g, 'Sat');
bot.chat(weekForecast);
}
else{
bot.chat("No weather found.");
}
});
}
else{
bot.chat("No weather found.");
}
});
}
break;
case ".temp": //Returns the current temperature in given city with .temp [givenCity], [givenState]
case ".temperature":
if (qualifier==""){
bot.chat("Try .temp followed by a US state, city, or zip to look up.");
}
else{
google_geocoding.geocode(qualifier, function(err, location) {
if (location!=null){
weather.getWeather(location.lat, location.lng, function(err, data){
if (data!=null){
var temp="Current temperature in "+data.location.areaDescription+": "+data.currentobservation.Temp+"°F "+data.currentobservation.Weather;
bot.chat(temp);
}
else{
bot.chat("No temperature found.");
}
});
}
else{
bot.chat("No temperature found.");
}
});
}
break;
case ".time": //Returns the current time in a given city with .time [givenCity], givenState]
if (qualifier==""){
bot.chat("Try .time followed by a place to look up.");
}
else{
google_geocoding.geocode(qualifier, function(err, location) {
if (location!=null){
var link = 'http://api.geonames.org/findNearbyPlaceNameJSON?lat=' + location.lat + '&lng=' + location.lng + '&username=jbader89&style=full'
request(link, function (error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
if (info != undefined){
var timezone = info.geonames[0].timezone.timeZoneId;
var currentTime = new time.Date();
currentTime.setTimezone(timezone);
var ampm = "";
var hours = "";
var mins = currentTime.toString().split(' ')[4].substring(2,5);
if (currentTime.toString().split(' ')[4].substring(0,2) == "00"){
hours = "12";
ampm = "AM";
}
else if (Number(currentTime.toString().split(' ')[4].substring(0,2)) < 13){
hours = currentTime.toString().split(' ')[4].substring(0,2);
ampm = "AM";
if (hours[0]=="0"){
hours = hours[1];
}
else if (hours=="12"){
ampm = "PM";
}
}
else{
hours = String(Number(currentTime.toString().split(' ')[4].substring(0,2)) - 12);
ampm = "PM";
}
var stateOrCity = '';
if (info.geonames[0].adminName1 != ''){
stateOrCity = info.geonames[0].adminName1 + ", ";
}
bot.chat("Current time in " + stateOrCity + info.geonames[0].countryName + ": " + hours + mins + " " + ampm);
}
}
});
}
else{
bot.chat("No time found.");
}
});
}
break;
case ".calc": //Calculates the solution to a given mathematical problem with .calc [equation]
var counter = 0;
var counter2 = 0;
for (var i=0; i<qualifier.length; i++) {
if (qualifier.charAt(i)=='(') {
counter++;
}
else if(qualifier.charAt(i)==')') {
counter2++;
}
}
qualifier=qualifier.replace(/x/g, '*');
if (qualifier!="" && !(/\d\(/g.test(qualifier)) && !(/[\!\,\@\'\"\?\#\$\%\&\_\=\<\>\:\;\[\]\{\}\`\~\||log]/g.test(qualifier)) && !(/\^\s{0,}\d{0,}\s{0,}\^/g.test(qualifier)) && !(/\)\d/g.test(qualifier)) && !(/^[\+\*\/\^]/g.test(qualifier)) && !(/[\+\-\*\/\^]$/g.test(qualifier)) && !(/[\+\-\*\/\^]\s{0,}[\+\*\/\^]/g.test(qualifier)) && !(/\d\s{1,}\d/g.test(qualifier)) && !(/\s\.\s/g.test(qualifier)) && !(/\.\d\./g.test(qualifier)) && !(/\d\.\s{1,}\d/g.test(qualifier)) && !(/\d\s{1,}\.\d/g.test(qualifier)) && !(/\.\./g.test(qualifier)) && (!(/([a-zA-Z])/g.test(qualifier))) && counter==counter2){
func=qualifier;
func+=" + (0*x) + (0*y)";
var realfunc=mlexer.parseString(func);
var answer=(realfunc({x:0,y:0}));
if (answer.toString()!="NaN"){
if (answer.toString()!="Infinity"){
bot.chat(answer.toString());
}
else{
bot.chat('http://i.imgur.com/KpAzEs8.jpg');
}
}
else{
bot.chat("/me does not compute.");
}
}
else if (qualifier==""){
bot.chat("Try .calc followed by something to calculate.");
}
else{
bot.chat("/me does not compute.");
}
break;
case ".tl":
case ".translate": //Returns a translation of given words with .translate [givenWords] '([language])', English by default
var languageCodes = ["ar","bg","ca","zh-CHS","zh-CHT","cs","da","nl","en","et","fa","fi","fr","de","el","ht","he","hi","hu","id","it","ja","ko","lv","lt","ms","mww","no","pl","pt","ro","ru","sk","sl","es","sv","th","tr","uk","ur","vi"];
var languages = ['Arabic', 'Bulgarian', 'Catalan', 'Chinese', 'Chinese', 'Czech', 'Danish', 'Dutch', 'English', 'Estonian', 'Persian (Farsi)', 'Finnish', 'French', 'German', 'Greek', 'Haitian Creole', 'Hebrew', 'Hindi', 'Hungarian', 'Indonesian', 'Italian', 'Japanese', 'Korean', 'Latvian', 'Lithuanian', 'Malay', 'Hmong Daw', 'Norwegian', 'Polish', 'Portuguese', 'Romanian', 'Russian', 'Slovak', 'Slovenian', 'Spanish', 'Swedish', 'Thai', 'Turkish', 'Ukrainian', 'Urdu', 'Vietnamese'];
if (qualifier!=""){
var params = {
text: qualifier
};
var language="";
client.initialize_token(function(keys){
client.detect(params, function(err, data) {
var language = data;
if (languageCodes.indexOf(language) > -1){
if (qualifier.indexOf('(')==-1){
var params2 = {
text: qualifier,
from: language,
to: 'en'
};
client.initialize_token(function(keys){
client.translate(params2, function(err, data) {
bot.chat(data + " (" + languages[languageCodes.indexOf(language)] + ")");
});
});
}
else{
var givenLanguage='';
var language2 = qualifier.substring(qualifier.indexOf('(')+1, qualifier.lastIndexOf(')')).toLowerCase();
if (languageCodes.indexOf(language2) > -1){
givenLanguage = language2;
}
else{
language2 = language2.charAt(0).toUpperCase() + language2.slice(1);
givenLanguage = languageCodes[languages.indexOf(language2)];
}
if (languages.indexOf(language2) > -1 || languageCodes.indexOf(language2) > -1){
var params2 = {
text: qualifier,
from: language,
to: givenLanguage
};
client.initialize_token(function(keys){
client.translate(params2, function(err, data) {
data = data.substring(0, data.indexOf('('));
bot.chat(data);