.
This commit is contained in:
@ -12,6 +12,7 @@ class irc {
|
||||
this.options.port = this.options.port || 6667;
|
||||
this.options.ssl = this.options.ssl || false;
|
||||
this.options.selfSigned = this.options.selfSigned || false;
|
||||
this.options.sasl = this.options.sasl || false;
|
||||
this.network = this.options.network || "test";
|
||||
this.nickname = this.options.nickname || "test";
|
||||
this.username = this.options.username || "test";
|
||||
@ -36,7 +37,7 @@ class irc {
|
||||
case "001": // welcome
|
||||
this.server.me = msg.params[0];
|
||||
this.join(this.options.channels);
|
||||
this.emit('connected', msg.params[1]);
|
||||
this.emit('data', ['connected', msg.params[1]]);
|
||||
break;
|
||||
case "372": // motd
|
||||
this.server.motd += `${msg.params[1]}\n`;
|
||||
@ -46,7 +47,7 @@ class irc {
|
||||
break;
|
||||
case "376": // motd_end
|
||||
this.server.motd += `${msg.params[1]}\n`;
|
||||
this.emit('motd', this.server.motd);
|
||||
this.emit('data', ['motd', this.server.motd]);
|
||||
break;
|
||||
case "464": // Password required
|
||||
if (this.options.password.length > 0)
|
||||
@ -56,10 +57,13 @@ class irc {
|
||||
this.send("PONG ", msg.params.join``);
|
||||
break;
|
||||
case "PRIVMSG":
|
||||
this.emit('message', this.reply(msg));
|
||||
if (msg.params[1] === "\u0001VERSION\u0001")
|
||||
this.emit('data', ['ctcp:version', this.reply(msg)]);
|
||||
else
|
||||
this.emit('data', ['message', this.reply(msg)]);
|
||||
break;
|
||||
case "NOTICE":
|
||||
this.emit('notice', msg.params[1]);
|
||||
this.emit('data', ['notice', msg.params[1]]);
|
||||
break;
|
||||
default:
|
||||
console.log(msg);
|
||||
@ -130,16 +134,10 @@ class irc {
|
||||
};
|
||||
}
|
||||
join(channel) {
|
||||
if(typeof channel === "object")
|
||||
this.send(`JOIN ${channel.join(',')}`);
|
||||
else
|
||||
this.send(`JOIN ${channel}`);
|
||||
this.send(`JOIN ${(typeof channel === "object") ? channel.join(',') : channel}`);
|
||||
}
|
||||
part(channel, msg=false) {
|
||||
if (typeof channel === "object")
|
||||
this.send(`PART ${channel.join(',')}${msg ? " " + msg : ""}`);
|
||||
else
|
||||
this.send(`PART ${channel}${msg ? " " + msg : ""}`);
|
||||
this.send(`PART ${(typeof channel === "object") ? channel.join(',') : channel}${msg ? " " + msg : "part"}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,17 +10,17 @@ class tg {
|
||||
this.options.polling = options.polling || true;
|
||||
this.client = new tgapi(this.options.token, this.options);
|
||||
|
||||
this.client.on('message', msg => {
|
||||
let time = ~~(Date.now() / 1000);
|
||||
if (msg.date >= (time - 10))
|
||||
this.emit('message', this.reply(msg));
|
||||
this.client.onText(/.*/, msg => {
|
||||
if (msg.date >= (~~(Date.now() / 1000) - 10)) {
|
||||
msg.text = msg.text.replace(/^\//g, "\.");
|
||||
this.emit('data', ['message', this.reply(msg)]);
|
||||
}
|
||||
});
|
||||
}
|
||||
send(id, msg) {
|
||||
this.client.sendMessage(id, msg);
|
||||
}
|
||||
reply(tmp) {
|
||||
console.log("Telegram", tmp);
|
||||
return {
|
||||
type: "tg",
|
||||
network: "Telegram",
|
||||
@ -34,13 +34,13 @@ class tg {
|
||||
message: tmp.text,
|
||||
time: tmp.date,
|
||||
raw: tmp,
|
||||
reply: function (msg) {
|
||||
reply: msg => {
|
||||
this.send(tmp.chat.id, msg);
|
||||
},
|
||||
replyAction: function (msg) {
|
||||
this.send(tmp.chat.id, msg);
|
||||
replyAction: msg => {
|
||||
this.send(tmp.chat.id, `Uwe ${msg}`);
|
||||
},
|
||||
replyNotice: function (msg) {
|
||||
replyNotice: msg => {
|
||||
this.send(tmp.chat.id, msg);
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user