-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (48 loc) · 1.21 KB
/
index.js
File metadata and controls
59 lines (48 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const IRC = require('irc-framework');
const ip = require('ip');
const bot = new IRC.Client();
const RssFeedEmitter = require('rss-feed-emitter');
const c = require('irc-colors');
const config = require('./config.js');
const feeder = new RssFeedEmitter();
function ip2Hex(address) {
return address.split('.').map((octet) => {
let hex = parseInt(octet, 10).toString(16);
if (hex.length === 1) {
hex = `0${hex}`;
}
return hex;
}).join('');
}
function initReader() {
config.feeds.forEach((e) => {
feeder.add({
url: e.url,
refresh: e.refresh,
});
});
}
bot.connect({
host: config.server,
nick: config.botName,
gecos: config.realName,
username: config.hexip ? ip2Hex(ip.address()) : config.botName,
password: config.password,
auto_reconnect: true,
auto_reconnect_wait: 4000,
auto_reconnect_max_retries: 3,
ping_interval: 30,
ping_timeout: 120,
});
bot.on('join', (event) => {
if (event.nick === config.botName) {
feeder.on('new-item', (item) => {
bot.say(config.channel, `${c.blue(item.title)} - ${item.link} by ${item.author}`);
});
}
});
bot.on('registered', () => {
console.log('Connected!');
bot.join(config.channel);
initReader();
});