index.js
2.15 KB
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
var fs = require('fs');
var ini = require('ini');
var config = ini.parse(fs.readFileSync(__dirname + '/config.ini', 'utf-8'));
var irc = require('irc');
var client = new irc.Client(config.globals.irc_server, config.globals.irc_nick);
var redis = require('redis');
var redisClient = redis.createClient(config.globals.redis_port, config.globals.redis_host);
client.addListener('message', function (from, to, message) {
console.log('MESSAGE ' + from + ' => ' + to + ': ' + message);
});
client.addListener('registered', function () {
console.log('onRegistered');
client.say('NickServ', 'identify ' + config.globals.nickserv_password);
});
client.addListener('join', function (channel, nick, message) {
console.log('JOIN ' + channel);
if (channel == '#' + config.globals.aaa_pull_channel) {
redisClient.psubscribe('kimochi.*.text');
}
else if (channel == '#' + config.globals.topup_message_channel) {
redisClient.psubscribe('echi.topup_report.*.message');
}
});
client.addListener('notice', function (from, to, message) {
console.log('NOTICE ' + from + ' => ' + to + ': ' + message);
if (from == 'NickServ' && message.match('You are now identified for')) {
console.log('Joining #' + config.globals.aaa_pull_channel);
client.join('#' + config.globals.aaa_pull_channel);
console.log('Joining #' + config.globals.topup_message_channel);
client.join('#' + config.globals.topup_message_channel);
}
});
client.addListener('pm', function (from, message) {
console.log('PM ' + from + ' => ME: ' + message);
});
redisClient.on("pmessage", function (pattern, channel, message) {
if (channel.match(/^kimochi/)) {
var gateway = channel.match(/gw:(.*)\.text/)[1];
//console.log(message + ' (' + gateway + ')');
client.say('#' + config.globals.aaa_pull_channel, message + ' (' + gateway + ')');
}
else if (channel.match(/^echi/)) {
var gateway = channel.match(/gw:(.*)\.message$/)[1];
//console.log(message + ' (' + gateway + ')');
client.say('#' + config.globals.topup_message_channel, message + ' (' + gateway + ')');
}
});