Commit b4182bc993260aceb0e09cfc9c5e7231c23e70ea

Authored by Adhidarma Hadiwinoto
1 parent 4dcab66a17
Exists in master

use irc-colors

Showing 2 changed files with 6 additions and 3 deletions Inline Diff

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 var redis = require('redis'); 4 var redis = require('redis');
5 5
6 var irc = require('irc'); 6 var irc = require('irc');
7 var colors = require('irc-colors');
8
7 var options = { 9 var options = {
8 userName: config.globals.irc_nick, 10 userName: config.globals.irc_nick,
9 password: config.globals.nickserv_password, 11 password: config.globals.nickserv_password,
10 sasl: true, 12 sasl: true,
11 stripColors: true, 13 stripColors: true,
12 channels: [config.globals.aaa_pull_channel, config.globals.topup_message_channel] 14 channels: [config.globals.aaa_pull_channel, config.globals.topup_message_channel]
13 }; 15 };
14 var client = new irc.Client(config.globals.irc_server, config.globals.irc_nick, options); 16 var client = new irc.Client(config.globals.irc_server, config.globals.irc_nick, options);
15 17
16 var redisClient = redis.createClient(config.globals.redis_port, config.globals.redis_host); 18 var redisClient = redis.createClient(config.globals.redis_port, config.globals.redis_host);
17 19
18 client.addListener('message', function (from, to, message) { 20 client.addListener('message', function (from, to, message) {
19 console.log('MESSAGE ' + from + ' => ' + to + ': ' + message); 21 console.log('MESSAGE ' + from + ' => ' + to + ': ' + message);
20 }); 22 });
21 23
22 client.addListener('registered', function () { 24 client.addListener('registered', function () {
23 console.log('Connected'); 25 console.log('Connected');
24 //client.say('NickServ', 'identify ' + config.globals.nickserv_password); 26 //client.say('NickServ', 'identify ' + config.globals.nickserv_password);
25 }); 27 });
26 28
27 client.addListener('join', function (channel, nick, message) { 29 client.addListener('join', function (channel, nick, message) {
28 console.log('JOIN ' + channel); 30 console.log('JOIN ' + channel);
29 31
30 if (channel == config.globals.aaa_pull_channel) { 32 if (channel == config.globals.aaa_pull_channel) {
31 redisClient.psubscribe('kimochi.*.text'); 33 redisClient.psubscribe('kimochi.*.text');
32 } 34 }
33 else if (channel == config.globals.topup_message_channel) { 35 else if (channel == config.globals.topup_message_channel) {
34 redisClient.psubscribe('echi.topup_report.*.message'); 36 redisClient.psubscribe('echi.topup_report.*.message');
35 } 37 }
36 }); 38 });
37 39
38 client.addListener('notice', function (from, to, message) { 40 client.addListener('notice', function (from, to, message) {
39 console.log('NOTICE ' + from + ' => ' + to + ': ' + message); 41 console.log('NOTICE ' + from + ' => ' + to + ': ' + message);
40 return; 42 return;
41 43
42 if (from == 'NickServ' && message.match('You are now identified for')) { 44 if (from == 'NickServ' && message.match('You are now identified for')) {
43 console.log('Joining ' + config.globals.aaa_pull_channel); 45 console.log('Joining ' + config.globals.aaa_pull_channel);
44 client.join(config.globals.aaa_pull_channel); 46 client.join(config.globals.aaa_pull_channel);
45 47
46 console.log('Joining ' + config.globals.topup_message_channel); 48 console.log('Joining ' + config.globals.topup_message_channel);
47 client.join(config.globals.topup_message_channel); 49 client.join(config.globals.topup_message_channel);
48 } 50 }
49 }); 51 });
50 52
51 client.addListener('pm', function (from, message) { 53 client.addListener('pm', function (from, message) {
52 console.log('PM ' + from + ' => ME: ' + message); 54 console.log('PM ' + from + ' => ME: ' + message);
53 }); 55 });
54 56
55 redisClient.on("pmessage", function (pattern, channel, message) { 57 redisClient.on("pmessage", function (pattern, channel, message) {
56 if (channel.match(/^kimochi/)) { 58 if (channel.match(/^kimochi/)) {
57 var gateway = channel.match(/gw:(.*)\.text/)[1]; 59 var gateway = channel.match(/gw:(.*)\.text/)[1];
58 client.say(config.globals.aaa_pull_channel, message + irc.colors.wrap(irc.colors.code.dark_red, ' (' + gateway + ')')); 60 client.say(config.globals.aaa_pull_channel, message + colors.purple(' (' + gateway + ')'));
59 } 61 }
60 else if (channel.match(/^echi/)) { 62 else if (channel.match(/^echi/)) {
61 var gateway = channel.match(/gw:(.*)\.message$/)[1]; 63 var gateway = channel.match(/gw:(.*)\.message$/)[1];
62 if (gateway == config.globals.echi_gw_blacklist) { 64 if (gateway == config.globals.echi_gw_blacklist) {
63 return; 65 return;
64 } 66 }
65 client.say(config.globals.topup_message_channel, message + irc.colors.wrap(irc.colors.code.dark_red, ' (' + gateway + ')')); 67 client.say(config.globals.topup_message_channel, message + colors.purple(' (' + gateway + ')'));
66 } 68 }
67 }); 69 });
68 70
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", 22 "irc": "~0.4.0",
23 "redis": "~2.3.1" 23 "redis": "~2.3.1",
24 "irc-colors": "~1.2.0"
24 } 25 }
25 } 26 }
26 27