-
Notifications
You must be signed in to change notification settings - Fork 0
/
irc.js
47 lines (46 loc) · 1.67 KB
/
irc.js
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
var irc = require('irc');
var events = require('events');
var eventEmitter = new events.EventEmitter;
var utils = require('./utils');
var config = require('./config');
module.exports = function(){
var self=this;
this.eventEmitter = eventEmitter;
this.sanitize = function(text) {
text = text.replace(/\*/g, '\\*');
text = text.replace(/_/g, '\\_');
text = text.replace(/\[/g, '\\[');
text = text.replace(/`/g, '\\`');
return text;
};
this.broadcaster = function(message){
message.text = this.sanitize(message.text);
eventEmitter.emit('ircmsg', message);
};
this.initialize = function(){
self.freebot = new irc.Client('chat.freenode.net', 'node-telegrambot', {
channels: ["#test"],
port: 8001,
debug: true,
secure: false,
sasl: false
});
self.freebot.addListener('error', function(message) {
console.log('error: ', message);
});
self.freebot.addListener('message', function(from, to, message){
self.broadcaster({"from": from, "to": to, "text": message, "server": "freenode"});
});
self.freebot.addListener('action', function(from, to, text, message){
self.broadcaster({"from": from, "to": to, "text": text, "server": "freenode", "action": true});
});
};
this.receiver = function(message){
if (config.tg[message.chat.id]){
var to = config.tg[message.chat.id];
if (to[0]=="freenode"){
self.freebot.say(to[1], irc.colors.wrap("dark_red",utils.gettgname(message)) + ": " + message.text);
}
}
};
}