forked from martindale/snarl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.js
858 lines (749 loc) · 28.5 KB
/
messages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
var rest = require('restler')
, google = require('google')
, ddg = require('ddg-api')
, urban = require('urban')
, github = require('github')
, _ = require('underscore')
, async = require('async')
, timeago = require('timeago')
, mongoose = require('mongoose')
, ObjectId = mongoose.Schema.Types.ObjectId
, Schema = mongoose.Schema
, db = mongoose.createConnection('localhost', 'snarl');
var facts = require('./facts');
var personSchema = mongoose.Schema({
name: { type: String, index: true }
, plugID: { type: String, unique: true, sparse: true }
, role: { type: Number }
, karma: { type: Number, default: 0 }
, points: {
listener: { type: Number, default: 0 }
, curator: { type: Number, default: 0 }
, dj: { type: Number, default: 0 }
, man: { type: Number, default: 0 }
}
, lastChat: { type: Date }
, bio: { type: String, max: 1024 }
, avatar: {
'set': String
, 'key': String
, 'uri': String
, 'thumb': String
}
});
var songSchema = mongoose.Schema({
author: String
, id: { type: String, index: true }
, cid: String
, plugID: String
, format: String
, title: String
, duration: Number
, lastPlay: Date
, nsfw: Boolean
});
var historySchema = mongoose.Schema({
_song: { type: ObjectId, ref: 'Song', required: true }
, _dj: { type: ObjectId, ref: 'Person', required: true }
, timestamp: { type: Date }
, curates: [ new Schema({
_person: { type: ObjectId, ref: 'Person', required: true }
}) ]
, downvotes: { type: Number, default: 0 }
, upvotes: { type: Number, default: 0 }
, votes: [ new Schema({
_person: { type: ObjectId, ref: 'Person', required: true }
, vote: { type: String, enum: ['up', 'down'] }
}) ]
});
var chatSchema = mongoose.Schema({
timestamp: { type: Date, default: Date.now }
, _person: { type: ObjectId, ref: 'Person', required: true }
, message: { type: String, required: true }
});
personSchema.virtual('points.total').get(function () {
return this.points.dj + this.points.curator + this.points.listener;
});
historySchema.virtual('isoDate').get(function() {
return this.timestamp.toISOString();
});
chatSchema.virtual('isoDate').get(function() {
return this.timestamp.toISOString();
});
var Person = db.model('Person', personSchema);
var Song = db.model('Song', songSchema);
var History = db.model('History', historySchema);
var Chat = db.model('Chat', chatSchema);
module.exports = {
snarl: "Ohaithar. I'm a bot created by @remæus. Blame him for any of my supposed mistakes."
, source: "You can see all my insides (and submit modifications) here: http://github.com/martindale/snarl"
, about: 'About Coding Soundtrack: http://codingsoundtrack.org/about'
, afk: 'If you\'re AFK at the end of your song for longer than 30 minutes you get warning 1. One minute later you get warning 2, another minute last warning, 30 seconds [boot].'
, askforseat: 'Please don\'t ask for seats here. It\'s first come, first serve, and free for all.'
, bitch: 'Not a lot of things are against the rules, but bitching about the music is. Stop being a bitch.'
, stfu: 'Please, shut your mouth and just enjoy the music.'
, overlord: 'ALL HAIL THE OVERLORD! http://codingsoundtrack.org/boycey'
, commandments: 'Coding Soundtrack\'s 10 Commandments: http://codingsoundtrack.org/ten-commandments'
, rules: 'No song limits, no queues, no auto-DJ. Pure FFA. DJ\'s over 10 minutes idle (measured by chat) face the [boot]. See !music for music suggestions, though there are no defined or enforced rules on music. More: http://codingsoundtrack.org/rules' // formerly: http://goo.gl/b7UGO
, selection: 'Song Selection Guide: http://codingsoundtrack.org/song-selection'
, suitup: 'Suit up, motherfucker!'
, netsplit: 'plug.dj has been having a lot of issues lately, especially with chat becoming fragmented. Some people can chat with each other, and others can\'t see those messages. Relax, @Boycey will have it fixed soon.'
, plugin: 'Coding Soundtrack is best enjoyed with jarPlug: https://chrome.google.com/webstore/detail/jarplug/anhldmgeompmlcmdcpbgdecdokhedlaa'
, tags: 'Please edit the tags of the songs on your playlists to exclude things like [VIDEO] and [OFFICIAL]. It\'s a data thing, man!'
, video: 'dat video.'
, smellslike: 'PISSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS'
, force: '/me senses a disturbance in the force.'
, smiffhour: 'Lock & Load your smiff tracks !djs for the next hour we spin strictly smiff.'
, ping: 'pong!'
, awesome: function(data) {
var self = this;
this.woot(function() {
console.log('Voted.');
self.chat('Agreed, this track is svelte! Wooted.');
});
}
, lame: function(data) {
var self = this;
this.meh(function() {
console.log('Voted.');
self.chat('Mmm, not so hot. Meh\'d.');
});
}
, notsmiff: function(data) {
var self = this;
this.meh(function() {
console.log('Voted.');
self.chat('Hey, wait a second. This isn\'t smiff. D:');
});
}
, bio: function(data) {
var self = this;
if (typeof(data.params) != 'undefined' && data.params.trim().length > 0) {
data.person.bio = data.params.trim();
data.person.save(function(err) {
self.chat('Bio saved! Profile link: http://codingsoundtrack.org/djs/' + data.fromID );
});
} else {
if (typeof(data.person.bio) != 'undefined' && data.person.bio.length > 0) {
self.chat('You must provide a string for your bio. Markdown is accepted. Your current bio is: “'+data.person.bio+'”');
} else {
self.chat('You must provide a string for your bio. Markdown is accepted.');
}
}
}
, catfacts: function(data) {
var self = this;
rest.get('http://catfacts-api.appspot.com/api/facts').on('complete', function(response) {
response = JSON.parse(response);
if (response.facts && response.facts.length > 0) {
self.chat(response.facts[0]);
}
});
}
, topologyfacts: function(data) {
var self = this;
self.chat(randomFact('topology'));
}
, interstellafacts: function(data) {
var self = this;
self.chat(randomFact('interstella'));
}
, get smifffax () { return this.smifffacts }
, smifffacts: function(data) {
var self = this;
self.chat(randomFact('smiff'));
}
, remæusfacts: function(data) {
var self = this;
self.chat('remæus\' third word was "combine". His first was "truck," and his second "bobtail".');
}
, boss: function(data) {
var self = this;
self.chat('The best play of all time was... @' + self.records.boss._dj.name + ' with ' + self.records.boss.curates.length + ' snags of their play of ' + self.records.boss._song.title + ' on ' + self.records.boss.timestamp + '! More: http://codingsoundtrack.org/history/' + self.records.boss._id );
}
, cb: function(data) {
var self = this;
self.chat('GTFO, @' + self.from +'!');
}
, count: function(data) {
var self = this;
self.chat('I am currently aware of ' + _.toArray(self.room.audience).length + ' audience members.');
}
, djs: function(data) {
var self = this;
var now = new Date();
var idleDJs = [];
_.toArray(self.room.djs).forEach(function(dj) {
if (typeof(dj.lastChat) != 'undefined') {
if (dj.lastChat.getTime() <= (now.getTime() - 300000)) {
dj.idleTime = (now.getTime() - dj.lastChat.getTime()) / 1000;
idleDJs.push(dj);
}
}
});
idleDJs = idleDJs.map(function(item) {
var idleTime = secondsToTime(item.idleTime);
var idleTimeString = '';
var idleTimeString = (idleTime.h > 0) ? '('+ idleTime.h +'h'+ idleTime.m +'m'+idleTime.s+'s)' : '('+ idleTime.m +'m'+idleTime.s+'s)';
if(item.idleTime < 600)
return item.name + ' '+idleTimeString;
return '@' + item.name + ' '+idleTimeString;
});
if (idleDJs.length > 0) {
self.chat('Idle: ' + oxfordJoin(idleDJs));
} else {
self.chat('No idle DJs!');
}
}
, donkeypunch: function(data) {
var self = this;
var randomSeed = getRandomInt(1, 100);
Person.findOne({ $or: [ { plugID: data.fromID }, { name: data.from } ] }).exec(function(err, person) {
if (!person) {
var person = new Person({
name: data.from
, plugID: data.fromID
});
}
person.points.man += randomSeed;
person.save(function(err) {
Person.count({}, function(err, totalPeople) {
var fivePercent = Math.floor(totalPeople * 0.0006);
var chanceToLose = 50;
Person.find({}).sort('-points.man').limit(fivePercent).exec(function(err, manlyMen) {
var manlyMenMap = manlyMen.map(function(man) {
return man.plugID;
});
if (randomSeed <= chanceToLose) {
self.chat('DONKEY PUNNNNNCH! ' + randomFact('donkey'));
self.chat('/me donkeypunches ' + data.from +'.');
person.points.man = 0;
person.save(function(err) {
if (err) { console.log(err); }
});
} else {
if (manlyMenMap.indexOf(data.fromID) >= 0) {
self.chat('@' + data.from + ' is ' + randomFact('compliment') + '.');
} else if ( randomSeed > chanceToLose ) {
self.chat('@' + data.from + ' is alright.');
}
}
});
});
});
});
}
, manly: function(data) {
var self = this;
Person.count({}, function(err, totalPeople) {
var fivePercent = Math.floor(totalPeople * 0.0006);
Person.find({}).sort('-points.man').limit(fivePercent).exec(function(err, manlyMen) {
var manlyManMap = manlyMen.map(function(man) {
return '@' + man.name;
});
//console.log( 'Manly: ' + manlyManMap.join(', ') )
self.chat('Manly: ' + manlyManMap.join(', '));
});
});
}
, erm: function(data) {
var self = this;
if (typeof(data.params) != 'undefined') {
self.chat(ermgerd(data.params));
}
}
, mods: function(data) {
var self = this;
var onlineStaff = [];
var realModerators = [];
_.toArray(self.room.staff).forEach(function(staffMember) {
if ( self.room.staff[staffMember.plugID].role > 1 ) {
realModerators.push(staffMember);
}
});
_.intersection(
_.toArray(realModerators).map(function(staffMember) {
return staffMember._id.toString();
}),
_.toArray(self.room.audience).map(function(audienceMember) {
return audienceMember._id.toString();
})
).forEach(function(staffMember) {
onlineStaff.push(staffMember);
});
Person.find({ _id: { $in: onlineStaff } }).exec(function(err, staff) {
self.chat(staff.length + ' online staff members: ' + staff.map(function(staffMember) {
console.log(staffMember);
console.log(self.room.staff);
//return staffMember.name + self.room.staff[staffMember.plugID].role;
return '@' + staffMember.name;
}).join(', ') );
});
}
, nsfw: function(data) {
var self = this;
var staffMap = [];
_.toArray(self.room.staff).forEach(function(staffMember) {
if ( self.room.staff[staffMember.plugID].role >= 1 ) {
staffMap.push(staffMember.plugID);
}
});
if (staffMap.indexOf( data.fromID ) > -1) {
Song.findOne({ id: self.currentSong.id }).exec(function(err, song) {
if (err) {
console.log(err);
}
else {
song.nsfw = true;
song.save(function(err) {
if (err) {
console.log(err);
}
else {
self.chat('Song updated. NSFW tag added.')
}
});
}
});
}
self.chat('Please give people who are listening at work fair warning about NSFW videos. It\'s common courtesy for people who don\'t code from home or at an awesome startup like LocalSense!');
}
, sfw: function(data) {
var self = this;
var staffMap = [];
_.toArray(self.room.staff).forEach(function(staffMember) {
if ( self.room.staff[staffMember.plugID].role >= 1 ) {
staffMap.push(staffMember.plugID);
}
});
if (staffMap.indexOf( data.fromID ) > -1) {
Song.findOne({ id: self.currentSong.id }).exec(function(err, song) {
if (err) {
console.log(err);
}
else {
song.nsfw = false;
song.save(function(err) {
if (err) {
console.log(err);
}
else {
self.chat('Song updated to SFW.')
}
});
}
});
}
else {
self.chat('I\'ll take that into consideration. Maybe.');
}
}
, permalink: function(data) {
var self = this;
self.chat('Song: http://codingsoundtrack.org/songs/' + self.room.track.id );
}
, plugid: function(data) {
var self = this;
self.chat('plug.dj calls you "'+ data.fromID +'". Are you gonna take that?');
}
, profile: function(data) {
var self = this;
if (typeof(data.params) != 'undefined' && data.params.trim().length > 0) {
Person.findOne({ name: data.params }).exec(function(err, person) {
if (!person) {
self.chat('/me could not find a profile by that name.');
} else {
self.chat('@' + data.params + ': “'+person.bio+'” More: http://codingsoundtrack.org/djs/'+ person.plugID)
}
});
} else {
self.chat('Whose profile did you want?');
}
}
, songtitle: function(data) {
var self = this;
var staffMap = [];
_.toArray(self.room.staff).forEach(function(staffMember) {
if ( self.room.staff[staffMember.plugID].role >= 1 ) {
staffMap.push(staffMember.plugID);
}
});
if (staffMap.indexOf( data.fromID ) == -1) {
self.chat('I\'ll take that into consideration. Maybe.');
} else {
Song.findOne({ id: self.currentSong.id }).exec(function(err, song) {
if (err) { console.log(err); } else {
if (data.params.length > 0) {
var previousTitle = song.title;
song.title = data.params;
song.save(function(err) {
self.chat('Song title updated, from "'+previousTitle+ '" to "'+song.title+'". Link: http://codingsoundtrack.org/songs/' + self.room.track.id );
});
} else {
self.chat('What do you want to set the title of this song to? I need a parameter.');
}
}
});
}
}
, songartist: function(data) {
var self = this;
var staffMap = [];
_.toArray(self.room.staff).forEach(function(staffMember) {
if ( self.room.staff[staffMember.plugID].role >= 1 ) {
staffMap.push(staffMember.plugID);
}
});
if (staffMap.indexOf( data.fromID ) == -1) {
self.chat('I\'ll take that into consideration. Maybe.');
} else {
Song.findOne({ id: self.currentSong.id }).exec(function(err, song) {
if (err) { console.log(err); } else {
if (data.params.length > 0) {
var previousAuthor = song.author;
song.author = data.params;
song.save(function(err) {
self.chat('Song artist updated, from "'+previousAuthor+ '" to "'+song.author+'". Link: http://codingsoundtrack.org/songs/' + self.room.track.id );
});
} else {
self.chat('What do you want to set the author of this song to? I need a parameter.');
}
}
});
}
}
, songplays: function(data) {
var self = this;
console.log('looking up: ' + JSON.stringify(self.currentSong));
Song.findOne({ id: self.currentSong.id }).exec(function(err, song) {
if (err) { console.log(err); } else {
History.count({ _song: song._id }, function(err, count) {
self.chat('This song has been played ' + count + ' times in recorded history.');
});
}
});
}
, distracting: 'Try not to play songs that would be distracting to someone trying to write code. Stay on theme as much as possible!'
, lastplayed: function(data) {
var self = this;
History.find({ _song: self.room.track._id }).sort('-timestamp').limit(2).populate('_dj').exec(function(err, history) {
var lastPlay = history[1];
if (lastPlay) {
History.count({ _song: self.room.track._id }).exec(function(err, count) {
self.chat('This song was last played ' + timeago(lastPlay.timestamp) + ' by @' + lastPlay._dj.name + '. It\'s been played ' + count + ' times in total. More: http://codingsoundtrack.org/songs/' + self.room.track.id );
});
} else {
self.chat('I haven\'t heard this song before now.');
}
});
}
, firstplayed: function(data) {
var self = this;
if (typeof(self.room.track._id) != 'undefined') {
History.findOne({ _song: self.room.track._id }).sort('+timestamp').populate('_dj').exec(function(err, firstPlay) {
History.count({ _song: self.room.track._id }).exec(function(err, count) {
self.chat('@' + firstPlay._dj.name + ' was the first person to play this song! Since then, it\'s been played ' + count + ' times. More: http://codingsoundtrack.org/songs/' + self.room.track.id );
});
});
} else {
self.chat('Hold on, I\'m still booting up. Gimme a minute.');
}
}
, lastsong: function(data) {
var self = this;
History.find({}).sort('-timestamp').limit(2).populate('_song').exec(function(err, history) {
if (history.length <= 1) {
self.chat("I've not been alive long enough to know that, Dave.");
} else {
var lastSong = history[1]._song;
self.chat('The last song was “'+ lastSong.title +'” by '+ lastSong.author + '.');
}
});
}
, music: function(data) {
var self = this;
var time = new Date().getUTCHours() - 5;
if ( 0 <= time && time < 5) {
self.chat("Evening! Keep the tempo up, it's the only thing keeping the all nighters going.");
} else if ( 5 <= time && time < 12 ) {
self.chat("AM! Chill tracks with good beats, most programmers are slow to wake so don't hit them with hard hitting tunes. Wubs are widely discouraged this early.");
} else if (12 <= time && time < 17 ){
self.chat('Afternoon! Fresh tracks for fresh people.');
} else {
self.chat("Evening! Most people are out of work so things are a lot more fluid and much less harsh. Seats are easy to get, spin a few if you want but don't hog the decks!");
}
}
, history: function(data) {
var self = this;
History.count({}, function(err, count) {
self.chat('There are ' + count + ' songs in recorded history: http://codingsoundtrack.org/history');
});
}
, popular: function(data) {
var self = this;
Person.find().sort('-karma').limit(3).exec(function(err, people) {
var names = people.map(function(person) {
return '@' + person.name;
});
self.chat(oxfordJoin(names) + ' are all the rage these days. See more: http://codingsoundtrack.org/djs');
});
}
, karma: function(data) {
var self = this;
Person.findOne({ $or: [ { plugID: data.fromID }, { name: data.from } ] }).exec(function(err, person) {
if (!person) {
var person = new Person({
name: data.from
, plugID: data.fromID
});
person.save(function(err) {
self.chat('Karma is an arbitrary count of times that people have said your name followed by ++. You can find yours at http://codingsoundtrack.org/djs/' + data.fromID );
});
} else {
self.chat('Karma is an arbitrary count of times that people have said your name followed by ++. You can find yours at http://codingsoundtrack.org/djs/' + data.fromID );
}
});
}
, trout: function(data) {
var target = data.from;
if (typeof(data.params) != 'undefined' && data.params.trim().length > 0) {
target = data.params.trim();
}
this.chat('/me slaps ' + target + ' around a bit with a large trout.');
}
, falconpunch: function(data) {
this.chat('/me falcon punches ' + data.from + ' out of a 13-story window.')
}
, brew: function(data) {
var self = this;
if (typeof(data.params) != 'undefined') {
rest.get('http://api.brewerydb.com/v2/search?q=' + data.params + '&key=7c05e35f30f5fbb823ec4731735eb2eb').on('complete', function(api) {
if (typeof(api.data) != 'undefined' && api.data.length > 0) {
if (typeof(api.data[0].description) != 'undefined') {
self.chat(api.data[0].name + ': ' + api.data[0].description);
} else {
self.chat(api.data[0].name + ' is a good beer, but I don\'t have a good way to describe it.');
}
} else {
self.chat('Damn, I\'ve never heard of that. Where do I need to go to find it?');
}
});
} else {
self.chat('No query provided.');
}
}
, urban: function(data) {
var self = this;
if (typeof(data.params) != 'undefined') {
rest.get('http://api.urbandictionary.com/v0/define?term='+data.params).on('complete', function(data) {
self.chat(data.list[0].definition);
});
} else {
self.chat('No query provided.');
}
}
, duckduckgo: function(data) {
var self = this;
var client = new ddg.SearchClient();
if (typeof(data.params) != 'undefined') {
client.search(data.params, function(error, response, ddgData) {
if (!error && response.statusCode == 200) {
console.log(ddgData);
if (ddgData.Abstract.length > 0) {
self.chat(ddgData.Abstract);
} else if (ddgData.Definition.length > 0) {
self.chat(ddgData.Definition);
} else {
self.chat('No results found.');
}
} else {
console.log("ERROR! " + error + "/" + response.statusCode);
}
});
} else {
self.chat('No query provided.');
}
}
,define: function (data) {
var self = this, finalMsg;
if (!data.params) {
finalMsg = "You have to provide the word...";
self.chat(finalMsg);
} else {
var word = data.params.split(" ").join("").split(',');
var url = "http://api.wordnik.com//v4/word.json/" + word[0] + "/definitions?includeRelated=false&includeTags=false&limit=1&useCanonical=false&api_key=4b9d570699e20d6a5d00104d9e50a041c7e8547b7f448c627";
if (word[1]) {
url = url + "&partOfSpeech=" + word[1];
};
rest.get(url).on('complete', function (msg) {
if (msg[0]) {
finalMsg = msg[0].text;
} else {
finalMsg = "No definitions found :*(";
}
self.chat(finalMsg);
});
}
}
, google: function(data) {
var self = this;
if (typeof(data.params) != 'undefined') {
google(data.params, function(err, next, links) {
if (err) { console.log(err); }
if (typeof(links[0]) != 'undefined') {
self.chat(links[0].title + ': ' + links[0].link);
}
});
} else {
self.chat('No query provided.');
}
}
, get snarlsource () { return this.source; }
, debug: function(data) { this.chat(JSON.stringify(data)) }
, get afpdj () { return this.afk; }
, get aftt () { return this.afk; }
, get boycey () { return this.overlord; }
, get ddg () { return this.duckduckgo; }
, get dp () { return this.donkeypunch; }
, get jarplug () { return this.plugin; }
, get woot () { return this.awesome; }
, get meh () { return this.lame; }
}
function oxfordJoin(array) {
if (array instanceof Array) {
} else {
array = _.toArray(array).map(function(item) {
return item.name;
});
}
var string = '';
if (array.length <= 1) {
string = array.join();
} else {
string = array.slice(0, -1).join(", ") + ", and " + array[array.length-1];
}
return string;
}
function secondsToTime(secs) {
var hours = Math.floor(secs / (60 * 60));
var divisor_for_minutes = secs % (60 * 60);
var minutes = Math.floor(divisor_for_minutes / 60);
var divisor_for_seconds = divisor_for_minutes % 60;
var seconds = Math.ceil(divisor_for_seconds);
var obj = {
"h": hours,
"m": minutes,
"s": seconds
};
return obj;
}
function randomFact(type) {
var ar = facts[type];
return ar[Math.round(Math.random()*(ar.length-1))];
}
function getRandomInt (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function ermgerd(text) {
text = text.toUpperCase();
var words = text.split(' '),
translatedWords = [];
for (var j in words) {
var prefix = words[j].match(/^\W+/) || '',
suffix = words[j].match(/\W+$/) || '',
word = words[j].replace(prefix, '').replace(suffix, '');
if (word) {
// Is translatable
translatedWords.push(prefix + translate(word) + suffix);
} else {
// Is punctuation
translatedWords.push(words[j]);
}
}
return translatedWords.join(' ');
}
function str_split(string, split_length) {
// http://kevin.vanzonneveld.net
// + original by: Martijn Wieringa
// + improved by: Brett Zamir (http://brett-zamir.me)
// + bugfixed by: Onno Marsman
// + revised by: Theriault
// + input by: Bjorn Roesbeke (http://www.bjornroesbeke.be/)
// + revised by: Rafał Kukawski (http://blog.kukawski.pl/)
// * example 1: str_split('Hello Friend', 3);
// * returns 1: ['Hel', 'lo ', 'Fri', 'end']
if (split_length === null) {
split_length = 1;
}
if (string === null || split_length < 1) {
return false;
}
string += '';
var chunks = [],
pos = 0,
len = string.length;
while (pos < len) {
chunks.push(string.slice(pos, pos += split_length));
}
return chunks;
};
function translate(word) {
// Don't translate short words
if (word.length == 1) {
return word;
}
// Handle specific words
switch (word) {
case 'AWESOME': return 'ERSUM';
case 'BANANA': return 'BERNERNER';
case 'BAYOU': return 'BERU';
case 'FAVORITE':
case 'FAVOURITE': return 'FRAVRIT';
case 'GOOSEBUMPS': return 'GERSBERMS';
case 'LONG': return 'LERNG';
case 'MY': return 'MAH';
case 'THE': return 'DA';
case 'THEY': return 'DEY';
case 'WE\'RE': return 'WER';
case 'YOU': return 'U';
case 'YOU\'RE': return 'YER';
}
// Before translating, keep a reference of the original word
var originalWord = word;
// Drop vowel from end of words
if (originalWord.length > 2) { // Keep it for short words, like "WE"
word = word.replace(/[AEIOU]$/, '');
}
// Reduce duplicate letters
word = word.replace(/[^\w\s]|(.)(?=\1)/gi, '');
// Reduce adjacent vowels to one
word = word.replace(/[AEIOUY]{2,}/g, 'E'); // TODO: Keep Y as first letter
// DOWN -> DERN
word = word.replace(/OW/g, 'ER');
// PANCAKES -> PERNKERKS
word = word.replace(/AKES/g, 'ERKS');
// The meat and potatoes: replace vowels with ER
word = word.replace(/[AEIOUY]/g, 'ER'); // TODO: Keep Y as first letter
// OH -> ER
word = word.replace(/ERH/g, 'ER');
// MY -> MAH
word = word.replace(/MER/g, 'MAH');
// FALLING -> FALERNG -> FERLIN
word = word.replace('ERNG', 'IN');
// POOPED -> PERPERD -> PERPED
word = word.replace('ERPERD', 'ERPED');
// MEME -> MAHM -> MERM
word = word.replace('MAHM', 'MERM');
// Keep Y as first character
// YES -> ERS -> YERS
if (originalWord.charAt(0) == 'Y') {
word = 'Y' + word;
}
// Reduce duplicate letters
word = word.replace(/[^\w\s]|(.)(?=\1)/gi, '');
// YELLOW -> YERLER -> YERLO
if ((originalWord.substr(-3) == 'LOW') && (word.substr(-3) == 'LER')) {
word = word.substr(0, word.length - 3) + 'LO';
}
return word;
};