/
bot.js
63 lines (54 loc) · 1.18 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
51
52
53
54
55
56
57
58
59
60
61
62
63
var fs = require("fs");
var domain = require("domain");
var Irc = require("./bin/irc");
var conf = JSON.parse(fs.readFileSync("conf.json"));
var pluginManager = require("./bin/pluginManager");
var plugins = [];
//initiate IRC
var irc = new Irc(conf, function(sender, to, msg)
{
plugins.forEach(function(plugin)
{
try
{
plugin.exec(msg, sender, to);
}
catch (err)
{
console.log("Error from plugin '"+plugin.name+"': "+err);
}
});
});
pluginManager.loadPlugins(plugins, conf, irc);
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", function(line)
{
var tokens = line.split(/\s+/);
var command = tokens[0];
switch (command)
{
case "reload":
var conf = JSON.parse(fs.readFileSync("conf.json"));
plugins = [];
pluginManager.loadPlugins(plugins, conf, irc);
console.log("Reload complete.");
break;
default:
console.log("Unknown command: "+command+".");
}
});
//don't crash on unhandled exception
var d = domain.create();
d.on("error", function(err)
{
console.log(err);
});
//again, don't crash!
process.on("uncaughtException", function(err)
{
console.log(err);
});
process.on("SIGUSR2", function() {
console.log("pong");
});