-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathcommands.js
58 lines (53 loc) · 1.33 KB
/
commands.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
/**
* This is the file where the bot commands are located
*
* @license MIT license
*/
var http = require('http');
var sys = require('sys');
exports.commands = {
/**
* It is recommended that you keep the following functions
*/
about: function(arg, by, room, con) {
var text = '**Pokémon Showdown Bot** by: Quinella';
this.say(con, room, text);
},
reload: function(arg, by) {
if (!this.hasRank(by, '#~')) return false;
try {
this.uncacheTree('./commands.js');
Commands = require('./commands.js').commands;
} catch (e) {
error('failed to reload: ' + sys.inspect(e));
}
},
/**
* Example commands below.
* Feel free to remove them and add your own.
*/
tell: 'say',
say: function(arg, by, room, con) {
if (!this.hasRank(by, '+%@&#~')) return false;
this.say(con, room, arg + ' (' + by + ' said this)');
},
joke: function(arg, by, room, con) {
var self = this;
var reqOpt = {
hostname: 'api.icndb.com',
path: '/jokes/random',
method: 'GET'
};
var req = http.request(reqOpt, function(res) {
res.on('data', function(chunk) {
try {
var data = JSON.parse(chunk);
self.say(con, room, data.value.joke);
} catch (e) {
self.say(con, room, 'Sorry, couldn\'t fetch a random joke... :(');
}
});
});
req.end();
}
};