-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (47 loc) · 1.86 KB
/
index.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
var request = require('request');
var cheerio = require('cheerio');
var drWho = function() {
this.name = 'dr-who';
this.displayname = 'Dr Who';
this.description = 'Gives you a random Dr Who quote';
}
drWho.prototype.init = function(){
var self = this;
this.listen('dr who me', 'standard', function(from, interface, params){
self.getQuote(from, interface, params);
})
}
drWho.prototype.getQuote = function(from, interface, params){
var doctors = [
"http://en.wikiquote.org/wiki/First_Doctor",
"http://en.wikiquote.org/wiki/Second_Doctor",
"http://en.wikiquote.org/wiki/Third_Doctor",
"http://en.wikiquote.org/wiki/Fourth_Doctor",
"http://en.wikiquote.org/wiki/Fifth_Doctor",
"http://en.wikiquote.org/wiki/Sixth_Doctor",
"http://en.wikiquote.org/wiki/Seventh_Doctor",
"http://en.wikiquote.org/wiki/Eighth_Doctor",
"http://en.wikiquote.org/wiki/War_Doctor",
"http://en.wikiquote.org/wiki/Ninth_Doctor",
"http://en.wikiquote.org/wiki/Tenth_Doctor",
"http://en.wikiquote.org/wiki/Eleventh_Doctor",
"http://en.wikiquote.org/wiki/Twelfth_Doctor"
];
var doctor = doctors[Math.floor(Math.random() * doctors.length)];
var self = this,
options = {
uri: doctor,
headers: {
'user-agent': 'Woodhouse Bot - https://github.com/lukeb-uk/woodhouse'
}
};
request(options, function(err, response, html){
if (err) {throw err}
var $ = cheerio.load(html);
var quotes = $('div > dl:not(:has(small, dl))').toArray();
var quote = quotes[Math.floor(Math.random() * quotes.length)];
var message = $(quote).text().trim();
self.sendMessage(message, interface, from);
})
}
module.exports = drWho;