Commit dcf01d0142f3f6c4923ff209ea38f883aa27830c
1 parent
31772ff5db
Exists in
master
auto join to messagess in channel
Showing 1 changed file with 1 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 | 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, config.globals.message_in_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 | else if (channel == config.globals.messages_in_channel) { | 38 | else if (channel == config.globals.messages_in_channel) { |
39 | redisClient.psubscribe('epic.*'); | 39 | redisClient.psubscribe('epic.*'); |
40 | } | 40 | } |
41 | }); | 41 | }); |
42 | 42 | ||
43 | client.addListener('notice', function (from, to, message) { | 43 | client.addListener('notice', function (from, to, message) { |
44 | console.log('NOTICE ' + from + ' => ' + to + ': ' + message); | 44 | console.log('NOTICE ' + from + ' => ' + to + ': ' + message); |
45 | return; | 45 | return; |
46 | 46 | ||
47 | if (from == 'NickServ' && message.match('You are now identified for')) { | 47 | if (from == 'NickServ' && message.match('You are now identified for')) { |
48 | console.log('Joining ' + config.globals.aaa_pull_channel); | 48 | console.log('Joining ' + config.globals.aaa_pull_channel); |
49 | client.join(config.globals.aaa_pull_channel); | 49 | client.join(config.globals.aaa_pull_channel); |
50 | 50 | ||
51 | console.log('Joining ' + config.globals.topup_message_channel); | 51 | console.log('Joining ' + config.globals.topup_message_channel); |
52 | client.join(config.globals.topup_message_channel); | 52 | client.join(config.globals.topup_message_channel); |
53 | 53 | ||
54 | console.log('Joining ' + config.globals.messages_in_channel); | 54 | console.log('Joining ' + config.globals.messages_in_channel); |
55 | client.join(config.globals.messages_in_channel); | 55 | client.join(config.globals.messages_in_channel); |
56 | } | 56 | } |
57 | }); | 57 | }); |
58 | 58 | ||
59 | client.addListener('pm', function (from, message) { | 59 | client.addListener('pm', function (from, message) { |
60 | console.log('PM ' + from + ' => ME: ' + message); | 60 | console.log('PM ' + from + ' => ME: ' + message); |
61 | }); | 61 | }); |
62 | 62 | ||
63 | redisClient.on("pmessage", function (pattern, channel, message) { | 63 | redisClient.on("pmessage", function (pattern, channel, message) { |
64 | if (channel.match(/^kimochi/)) { | 64 | if (channel.match(/^kimochi/)) { |
65 | var gateway = channel.match(/gw:(.*)\.text/)[1]; | 65 | var gateway = channel.match(/gw:(.*)\.text/)[1]; |
66 | client.say(config.globals.aaa_pull_channel, message + ' (' + gateway + ')'); | 66 | client.say(config.globals.aaa_pull_channel, message + ' (' + gateway + ')'); |
67 | } | 67 | } |
68 | else if (channel.match(/^echi/)) { | 68 | else if (channel.match(/^echi/)) { |
69 | var gateway = channel.match(/gw:(.*)\.message$/)[1]; | 69 | var gateway = channel.match(/gw:(.*)\.message$/)[1]; |
70 | if (config.globals.echi_gw_blacklist.split(',').indexOf(gateway) >= 0) { | 70 | if (config.globals.echi_gw_blacklist.split(',').indexOf(gateway) >= 0) { |
71 | return; | 71 | return; |
72 | } | 72 | } |
73 | client.say(config.globals.topup_message_channel, message + ' (' + gateway + ')'); | 73 | client.say(config.globals.topup_message_channel, message + ' (' + gateway + ')'); |
74 | } | 74 | } |
75 | else if (channel.match(/^epic\./)) { | 75 | else if (channel.match(/^epic\./)) { |
76 | client.say(config.globals.messages_in_channel, message); | 76 | client.say(config.globals.messages_in_channel, message); |
77 | } | 77 | } |
78 | }); | 78 | }); |
79 | 79 |