Commit 142a9ba6de89b830445dc6dfcdac4dfb9b770e9d
1 parent
e0affa02fa
Exists in
master
ready to run
Showing 2 changed files with 58 additions and 1 deletions Side-by-side Diff
index.js
1 | 1 | var fs = require('fs'); |
2 | 2 | var ini = require('ini'); |
3 | 3 | var config = ini.parse(fs.readFileSync(__dirname + '/config.ini', 'utf-8')); |
4 | + | |
5 | +var irc = require('irc'); | |
6 | +var client = new irc.Client(config.globals.irc_server, config.globals.irc_nick); | |
7 | +var redis = require('redis'); | |
8 | + | |
9 | +var redisClient = redis.createClient(config.globals.redis_port, config.globals.redis_host); | |
10 | + | |
11 | +client.addListener('message', function (from, to, message) { | |
12 | + console.log('MESSAGE ' + from + ' => ' + to + ': ' + message); | |
13 | +}); | |
14 | + | |
15 | +client.addListener('registered', function () { | |
16 | + console.log('onRegistered'); | |
17 | + client.say('NickServ', 'identify ' + config.globals.nickserv_password); | |
18 | +}); | |
19 | + | |
20 | +client.addListener('join', function (channel, nick, message) { | |
21 | + console.log('JOIN ' + channel); | |
22 | + | |
23 | + if (channel == '#' + config.globals.aaa_pull_channel) { | |
24 | + redisClient.psubscribe('kimochi.*.text'); | |
25 | + } | |
26 | + else if (channel == '#' + config.globals.topup_message_channel) { | |
27 | + redisClient.psubscribe('echi.topup_report.*.message'); | |
28 | + } | |
29 | +}); | |
30 | + | |
31 | +client.addListener('notice', function (from, to, message) { | |
32 | + console.log('NOTICE ' + from + ' => ' + to + ': ' + message); | |
33 | + | |
34 | + if (from == 'NickServ' && message.match('You are now identified for')) { | |
35 | + console.log('Joining #' + config.globals.aaa_pull_channel); | |
36 | + client.join('#' + config.globals.aaa_pull_channel); | |
37 | + | |
38 | + console.log('Joining #' + config.globals.topup_message_channel); | |
39 | + client.join('#' + config.globals.topup_message_channel); | |
40 | + } | |
41 | +}); | |
42 | + | |
43 | +client.addListener('pm', function (from, message) { | |
44 | + console.log('PM ' + from + ' => ME: ' + message); | |
45 | +}); | |
46 | + | |
47 | +redisClient.on("pmessage", function (pattern, channel, message) { | |
48 | + if (channel.match(/^kimochi/)) { | |
49 | + var gateway = channel.match(/gw:(.*)\.text/)[1]; | |
50 | + //console.log(message + ' (' + gateway + ')'); | |
51 | + client.say('#' + config.globals.aaa_pull_channel, message + ' (' + gateway + ')'); | |
52 | + } | |
53 | + else if (channel.match(/^echi/)) { | |
54 | + var gateway = channel.match(/gw:(.*)\.message$/)[1]; | |
55 | + //console.log(message + ' (' + gateway + ')'); | |
56 | + client.say('#' + config.globals.topup_message_channel, message + ' (' + gateway + ')'); | |
57 | + } | |
58 | +}); |