Commit a2be776da280a1e17680a475f57a823d4ea7f0be
1 parent
ff738b17db
Exists in
master
debug
Showing 1 changed file with 3 additions and 0 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 | 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, config.globals.messages_in_channel] | 14 | channels: [config.globals.aaa_pull_channel, config.globals.topup_message_channel, config.globals.messages_in_channel] |
15 | }; | 15 | }; |
16 | console.log('Connecting to irc with options:'); | ||
17 | console.log(options); | ||
18 | |||
16 | var client = new irc.Client(config.globals.irc_server, config.globals.irc_nick, options); | 19 | var client = new irc.Client(config.globals.irc_server, config.globals.irc_nick, options); |
17 | 20 | ||
18 | var redisClient = redis.createClient(config.globals.redis_port, config.globals.redis_host); | 21 | var redisClient = redis.createClient(config.globals.redis_port, config.globals.redis_host); |
19 | 22 | ||
20 | client.addListener('message', function (from, to, message) { | 23 | client.addListener('message', function (from, to, message) { |
21 | console.log('MESSAGE ' + from + ' => ' + to + ': ' + message); | 24 | console.log('MESSAGE ' + from + ' => ' + to + ': ' + message); |
22 | }); | 25 | }); |
23 | 26 | ||
24 | client.addListener('registered', function () { | 27 | client.addListener('registered', function () { |
25 | console.log('Connected'); | 28 | console.log('Connected'); |
26 | //client.say('NickServ', 'identify ' + config.globals.nickserv_password); | 29 | //client.say('NickServ', 'identify ' + config.globals.nickserv_password); |
27 | }); | 30 | }); |
28 | 31 | ||
29 | client.addListener('join', function (channel, nick, message) { | 32 | client.addListener('join', function (channel, nick, message) { |
30 | console.log('JOIN ' + channel); | 33 | console.log('JOIN ' + channel); |
31 | 34 | ||
32 | if (channel == config.globals.aaa_pull_channel) { | 35 | if (channel == config.globals.aaa_pull_channel) { |
33 | redisClient.psubscribe('kimochi.*.text'); | 36 | redisClient.psubscribe('kimochi.*.text'); |
34 | } | 37 | } |
35 | else if (channel == config.globals.topup_message_channel) { | 38 | else if (channel == config.globals.topup_message_channel) { |
36 | redisClient.psubscribe('echi.topup_report.*.message'); | 39 | redisClient.psubscribe('echi.topup_report.*.message'); |
37 | } | 40 | } |
38 | else if (channel == config.globals.messages_in_channel) { | 41 | else if (channel == config.globals.messages_in_channel) { |
39 | redisClient.psubscribe('epic.*'); | 42 | redisClient.psubscribe('epic.*'); |
40 | } | 43 | } |
41 | }); | 44 | }); |
42 | 45 | ||
43 | client.addListener('notice', function (from, to, message) { | 46 | client.addListener('notice', function (from, to, message) { |
44 | console.log('NOTICE ' + from + ' => ' + to + ': ' + message); | 47 | console.log('NOTICE ' + from + ' => ' + to + ': ' + message); |
45 | return; | 48 | return; |
46 | 49 | ||
47 | if (from == 'NickServ' && message.match('You are now identified for')) { | 50 | if (from == 'NickServ' && message.match('You are now identified for')) { |
48 | console.log('Joining ' + config.globals.aaa_pull_channel); | 51 | console.log('Joining ' + config.globals.aaa_pull_channel); |
49 | client.join(config.globals.aaa_pull_channel); | 52 | client.join(config.globals.aaa_pull_channel); |
50 | 53 | ||
51 | console.log('Joining ' + config.globals.topup_message_channel); | 54 | console.log('Joining ' + config.globals.topup_message_channel); |
52 | client.join(config.globals.topup_message_channel); | 55 | client.join(config.globals.topup_message_channel); |
53 | 56 | ||
54 | console.log('Joining ' + config.globals.messages_in_channel); | 57 | console.log('Joining ' + config.globals.messages_in_channel); |
55 | client.join(config.globals.messages_in_channel); | 58 | client.join(config.globals.messages_in_channel); |
56 | } | 59 | } |
57 | }); | 60 | }); |
58 | 61 | ||
59 | client.addListener('pm', function (from, message) { | 62 | client.addListener('pm', function (from, message) { |
60 | console.log('PM ' + from + ' => ME: ' + message); | 63 | console.log('PM ' + from + ' => ME: ' + message); |
61 | }); | 64 | }); |
62 | 65 | ||
63 | redisClient.on("pmessage", function (pattern, channel, message) { | 66 | redisClient.on("pmessage", function (pattern, channel, message) { |
64 | if (channel.match(/^kimochi/)) { | 67 | if (channel.match(/^kimochi/)) { |
65 | var gateway = channel.match(/gw:(.*)\.text/)[1]; | 68 | var gateway = channel.match(/gw:(.*)\.text/)[1]; |
66 | client.say(config.globals.aaa_pull_channel, message + ' (' + gateway + ')'); | 69 | client.say(config.globals.aaa_pull_channel, message + ' (' + gateway + ')'); |
67 | } | 70 | } |
68 | else if (channel.match(/^echi/)) { | 71 | else if (channel.match(/^echi/)) { |
69 | var gateway = channel.match(/gw:(.*)\.message$/)[1]; | 72 | var gateway = channel.match(/gw:(.*)\.message$/)[1]; |
70 | if (config.globals.echi_gw_blacklist.split(',').indexOf(gateway) >= 0) { | 73 | if (config.globals.echi_gw_blacklist.split(',').indexOf(gateway) >= 0) { |
71 | return; | 74 | return; |
72 | } | 75 | } |
73 | client.say(config.globals.topup_message_channel, message + ' (' + gateway + ')'); | 76 | client.say(config.globals.topup_message_channel, message + ' (' + gateway + ')'); |
74 | } | 77 | } |
75 | else if (channel.match(/^epic\./)) { | 78 | else if (channel.match(/^epic\./)) { |
76 | client.say(config.globals.messages_in_channel, message); | 79 | client.say(config.globals.messages_in_channel, message); |
77 | } | 80 | } |
78 | }); | 81 | }); |
79 | 82 |