/
bot.js
52 lines (40 loc) · 1.19 KB
/
bot.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
var config = {
channels: ["##uncla"],
server: "irc.freenode.net",
botName: "DogTipBot"
};
var options = {
host: 'hatch02.cs.unc.edu',
path: '/hatch/run.php?v='
}
var irc = require('irc');
var http = require('http');
var bot = new irc.Client(config.server, config.botName, {channels: config.channels });
callback = function(response) {
var str = '';
//another chunk of data has been recieved, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});
//the whole response has been recieved, so we just print it out here
response.on('end', function () {
bot.say(str);
});
}
bot.addListener("message", function(from,to,text,msg) {
if (text.indexOf("pls") > -1) {
bot.say(config.channels[0], "Congrats you get +1 dog. Calling the ASPCA now!");
}
if (text.indexOf("topic") > -1) {
bot.say(config.channels[0], "The _real_ topic is Dogecoin");
}
if (text.indexOf("playaudio: ") > -1) {
bot.say(config.channels[0], "Playing Audio");
options.path = '/hatch/run.php?v=' + text.substring(11);
http.request(options, callback).end();
}
if (text.indexOf("killaudio" > -1)) {
options.path = '/hatch/kill.php';
http.request(options, callback).end();
}
});