-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (33 loc) · 952 Bytes
/
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
var behest = require('behest');
function plugin() {
return function(irc) {
irc.on('message', function(evt) {
var from = evt.from;
var to = evt.to;
var message = evt.message;
if (!behest.isValid(message)) {
return;
}
var command = behest(message);
if (command.command === 'base64') {
var destination = to.charAt(0) === '#' ? to : from;
var str = command.params.slice(1).join(' ');
var b;
switch (command.params[0]) {
case 'encode':
b = new Buffer(str).toString('base64');
break;
case 'decode':
b = new Buffer(str, 'base64').toString('utf8');
break;
default:
irc.send(destination, from + ': Huh? Try `!base64 encode|decode <query>`');
}
if (b) {
irc.send(destination, from + ': ' + b);
}
}
});
};
}
module.exports = plugin;