Commit 142a9ba6de89b830445dc6dfcdac4dfb9b770e9d
1 parent
e0affa02fa
Exists in
master
ready to run
Showing 2 changed files with 58 additions and 1 deletions Inline Diff
index.js
1 | var fs = require('fs'); | 1 | var fs = require('fs'); |
2 | var ini = require('ini'); | 2 | var ini = require('ini'); |
3 | var config = ini.parse(fs.readFileSync(__dirname + '/config.ini', 'utf-8')); | 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 | }); | ||
4 | 59 |
package.json
1 | { | 1 | { |
2 | "name": "r97-aaa-pull-irc", | 2 | "name": "r97-aaa-pull-irc", |
3 | "version": "0.0.1", | 3 | "version": "0.0.1", |
4 | "description": "Broadcast ST24 AAA-PULL to IRC", | 4 | "description": "Broadcast ST24 AAA-PULL to IRC", |
5 | "main": "index.js", | 5 | "main": "index.js", |
6 | "scripts": { | 6 | "scripts": { |
7 | "test": "echo \"Error: no test specified\" && exit 1" | 7 | "test": "echo \"Error: no test specified\" && exit 1" |
8 | }, | 8 | }, |
9 | "repository": { | 9 | "repository": { |
10 | "type": "git", | 10 | "type": "git", |
11 | "url": "git@gitlab.kodesumber.com:reload97/r97-aaa-pull-irc.git" | 11 | "url": "git@gitlab.kodesumber.com:reload97/r97-aaa-pull-irc.git" |
12 | }, | 12 | }, |
13 | "keywords": [ | 13 | "keywords": [ |
14 | "r97", | 14 | "r97", |
15 | "st24", | 15 | "st24", |
16 | "ppob" | 16 | "ppob" |
17 | ], | 17 | ], |
18 | "author": "Adhidarma Hadiwinoto <gua@adhisimon.org>", | 18 | "author": "Adhidarma Hadiwinoto <gua@adhisimon.org>", |
19 | "license": "BSD", | 19 | "license": "BSD", |
20 | "dependencies": { | 20 | "dependencies": { |
21 | "ini": "~1.3.4" | 21 | "ini": "~1.3.4", |
22 | "irc": "~0.4.0", | ||
23 | "redis": "~2.3.1" | ||
22 | } | 24 | } |
23 | } | 25 | } |
24 | 26 |