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