-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
78 lines (76 loc) · 2.43 KB
/
app.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Initializes ircbot
const ircbot = require('./ircbot.js');
const readline = require('readline');
const event = require('events');
const fs = require('fs');
const cluster = require('cluster');
if (cluster.isMaster) {
console.log('[NOTICE] Starting cluster...');
cluster.fork();
cluster.on('exit',_=>{cluster.fork();});
} else if (cluster.isWorker) {
console.log('[INFO] Started as worker');
var consoleinterface = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: 'repl> '
}).on('line',function(line) {
try {
var result = eval(line);
} catch(e) {
var result = e;
}
console.log(result);
consoleinterface.prompt();
}).on('SIGINT',function() {
process.emit('SIGINT');
console.log('Closing connection. Use Ctrl-D to exit');
});
var config = require('./config.js');
var stuxconfig = Object.assign({},config);
stuxconfig.host = 'irc.stuxnet.xyz';
stuxconfig.nick = 'relay';
stuxconfig.channels = '#j,#'; // FIXME(jeffl35): this is just bad
var bot = new ircbot(config);
var stuxrelay = new ircbot(stuxconfig);
stuxconfig.modules = {};
config.modules = {};
function loadModules(xbot,reload,config,noload) {
console.log('[INFO] Loading modules...');
if (!noload) {noload = {};}
if (reload) {
xbot.privmsg.removeAllListeners();
xbot.servmsg.removeAllListeners();
xbot.events.removeAllListeners();
xbot.setlis();
}
xbot.events.on('reload',_=>{loadModules(xbot,true,config,noload);});
fs.readdirSync('modules').forEach(function(file) {
if(fs.lstatSync('./modules/'+file).isFile() && file.endsWith('.js') && !(file in noload)) {
if (reload) {
try{
console.log('[DEBUG] Deleting cache for file '+file);
delete require.cache[require.resolve('./modules/'+file)];
}catch(e){}
}
config.modules[file] = require('./modules/'+file)(xbot,config);
console.log('[INFO] Loaded module '+file);
}
});
}
loadModules(bot,false,config);
loadModules(stuxrelay,false,stuxconfig,{"track.js":1});
// FIXME(jeffl35): this is a horrible hack
bot.privmsg.on('##jeffl35',(args,host)=>{stuxrelay.sendMsg('#j',formatRelay(host[0],args))});
stuxrelay.privmsg.on('#j',(args,host)=>{bot.sendMsg('##jeffl35',formatRelay(host[0],args))});
function formatRelay(nick,msg){
if (msg[0] == '\x01ACTION') {
msg.splice(0,1);
return `* ${nick} ${msg.join(' ').replace('\x01','')}`;
} else {
return `<${nick}> ${msg.join(' ')}`;
}
}
bot.start();
stuxrelay.start();
}