-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmyfbot.js
50 lines (42 loc) · 1.44 KB
/
myfbot.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
irc = require('irc');
var exec = require('child_process').exec,
sleep = require('sleep'),
channel = '#cowbot';
function addslashes( str,callback ) {
catmes = (str+'').split(/^moo/)[1].replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
callback(catmes);
}
function cowsay(string, callback) {
var command = "echo $INPUT | cowsay -f cows/hacker.cow";
exec(command, {env: {INPUT: string}}, function(error, stdout,stderr){
var child = stdout;
var raw = child.match(/^.*([]+|$)/gm);
console.log(raw);
callback(raw);
});
}
var bot = new irc.Client('irc.freenode.net', 'cowbot', {
debug: false,
channels: [channel],
realName: "James Joyce",
});
bot.addListener('error', function(message) {
console.error('ERROR: %s: %s', message.command, message.args.join(' '));
});
bot.addListener('message', function (from, to ,message) {
if (message.match(/^moo/)) {
addslashes(message, function (catmes) {
cowsay(catmes, function(raw){
var counter = 0;
var interval = setInterval(function () {
console.log(raw[counter]);
bot.say(channel,raw[counter]);
counter++;
if (counter>=raw.length) {
clearInterval(interval);
}
}, 1000);
});
});
}
});