Commit f74e48d9b711939b35471d11d838eb9c5dec07f4

Authored by Adhidarma Hadiwinoto
1 parent b4182bc993
Exists in master

kembali tanpa color

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