-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (44 loc) · 1.62 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
55
56
var http = require('http');
var isup = function() {
this.name = 'isup';
this.displayname = 'Is It Up?';
this.description = 'Ask woodhouse to check if a website is up';
return this;
}
isup.prototype.init = function(){
var self = this;
this.listen('is (:<url>.+?) (up|down)(\\?|)', 'standard', function(from, interface, params){
self.sendMessage('Let me just check...', interface, from);
var options = {
hostname: 'isup.me',
path: '/' + params[0],
headers: {
'user-agent': 'Woodhouse Bot - https://github.com/lukeb-uk/woodhouse'
}
},
data = '';
var req = http.request(options, function(res) {
res.on('data', function (response) {
data += String(response);
});
res.on('end', function() {
var reply;
if (data.match('It\'s just you')) {
reply = params[0] + ' looks UP to me!'
} else if (data.match('It\'s not just you!')) {
reply = params[0] + ' looks DOWN to me!'
} else if (data.match('doesn\'t look like a site on the interwho')) {
reply = params[0] + ' doesn\'t seem to be a valid domain'
} else {
reply = params[0] + ' returned an error'
}
self.sendMessage(reply, interface, from);
})
})
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.end();
})
}
module.exports = isup;