diff --git a/index.js b/index.js index 235ed8f..2e367c1 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,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 + ')'); + } +}); diff --git a/package.json b/package.json index 5550bc7..874a3db 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,8 @@ "author": "Adhidarma Hadiwinoto <gua@adhisimon.org>", "license": "BSD", "dependencies": { - "ini": "~1.3.4" + "ini": "~1.3.4", + "irc": "~0.4.0", + "redis": "~2.3.1" } }