migrate irc + tg client changes from uwe
This commit is contained in:
parent
5a33c21887
commit
3a895eda83
|
@ -5,9 +5,11 @@ import tls from "tls";
|
|||
import EventEmitter from "events";
|
||||
|
||||
const colors = {
|
||||
red: "\x0304$1\x0304",
|
||||
blue: "\x0312$1\x0312",
|
||||
yellow: "\x0308$1\x0308"
|
||||
red: "04",
|
||||
blue: "12",
|
||||
yellow: "08",
|
||||
green: "03",
|
||||
brown: "05"
|
||||
};
|
||||
const msgmodes = {
|
||||
normal: "PRIVMSG {recipient} :{msg}",
|
||||
|
@ -17,7 +19,7 @@ const msgmodes = {
|
|||
|
||||
const replaceColor = (match, color, text) => {
|
||||
if (colors.hasOwnProperty(color))
|
||||
return colors[color].replace("\$1", text);
|
||||
return `\x03${colors[color]}${text}\x0F`;
|
||||
return text;
|
||||
};
|
||||
|
||||
|
@ -45,7 +47,6 @@ export class irc extends EventEmitter {
|
|||
this.server = {
|
||||
set: this.set,
|
||||
motd: "",
|
||||
debug: false,
|
||||
me: {},
|
||||
channel: [],
|
||||
user: new Map()
|
||||
|
@ -80,16 +81,14 @@ export class irc extends EventEmitter {
|
|||
this.send( msgmodes[mode].replace("{recipient}", recipient).replace("{msg}", e) );
|
||||
});
|
||||
}
|
||||
parse(data, [a, ...b] = data.split(/ +:/)) {
|
||||
let tmp = a.split(" ").concat(b);
|
||||
return data.charAt(0) === ":" ? {
|
||||
prefix: tmp.shift(),
|
||||
command: tmp.shift(),
|
||||
params: tmp
|
||||
} : {
|
||||
prefix: null,
|
||||
command: tmp.shift(),
|
||||
params: tmp
|
||||
parse(data, [a, ...b] = data.split(/ +:/), tmp = a.split(" ").concat(b)) {
|
||||
let prefix = data.charAt(0) === ":" ? tmp.shift() : null
|
||||
, command = tmp.shift()
|
||||
, params = command.toLowerCase() === "privmsg" ? [ tmp.shift(), tmp.join(" :") ] : tmp;
|
||||
return {
|
||||
prefix: prefix,
|
||||
command: command,
|
||||
params: params
|
||||
};
|
||||
}
|
||||
reply(tmp) {
|
||||
|
@ -99,10 +98,14 @@ export class irc extends EventEmitter {
|
|||
channel: tmp.params[0],
|
||||
channelid: tmp.params[0],
|
||||
user: Object.assign(this.parsePrefix(tmp.prefix), {
|
||||
account: this.server.user.geti(this.parsePrefix(tmp.prefix).nick).account,
|
||||
prefix: tmp.prefix.charAt(0) === ":" ? tmp.prefix.substring(1) : tmp.prefix,
|
||||
level: getLevel(this.network, Object.assign(this.parsePrefix(tmp.prefix), {
|
||||
account: this.server.user.geti(this.parsePrefix(tmp.prefix).nick).account,
|
||||
prefix: tmp.prefix.charAt(0) === ":" ? tmp.prefix.substring(1) : tmp.prefix
|
||||
}))
|
||||
}),
|
||||
message: tmp.params[1],
|
||||
message: tmp.params[1].replace(/\u0002/, ""),
|
||||
time: ~~(Date.now() / 1000),
|
||||
raw: tmp,
|
||||
reply: msg => this.sendmsg("normal", tmp.params[0], this.format(""+msg)),
|
||||
|
@ -128,8 +131,8 @@ export class irc extends EventEmitter {
|
|||
whois(user, force = false) {
|
||||
user = user.toLowerCase();
|
||||
let tmpuser = {};
|
||||
if(this.server.user.hasi(user) && !force) {
|
||||
tmpuser = this.server.user.geti(user);
|
||||
if(this.server.user.has(user) && !force) {
|
||||
tmpuser = this.server.user.get(user);
|
||||
if(tmpuser.cached >= ~~(Date.now() / 1000) - this._recachetime)
|
||||
return;
|
||||
}
|
||||
|
@ -167,21 +170,3 @@ export class irc extends EventEmitter {
|
|||
;
|
||||
}
|
||||
}
|
||||
|
||||
Map.prototype.hasi = function(val) {
|
||||
for (let [key] of this)
|
||||
if(key.toLowerCase() === val.toLowerCase())
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
Map.prototype.geti = function(val) {
|
||||
for (let [key, value] of this)
|
||||
if(key.toLowerCase() === val.toLowerCase())
|
||||
return value;
|
||||
return false;
|
||||
};
|
||||
Map.prototype.deli = function(val) {
|
||||
for (let [key] of this)
|
||||
if(key.toLowerCase() === val.toLowerCase())
|
||||
this.delete(key);
|
||||
};
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
export default client => {
|
||||
client._cmd.set("PRIVMSG", function (msg) { // privmsg
|
||||
this.emit("data", msg.params[1] === "\u0001VERSION\u0001" ? ["ctcp:version", this.reply(msg)] : ["message", this.reply(msg)]);
|
||||
if(msg.params[1] === "\u0001VERSION\u0001")
|
||||
return this.emit("data", ["ctcp:version", this.reply(msg)]);
|
||||
else if(msg.params[1].match(/^\u0001PING .*\u0001/i))
|
||||
return this.emit("data", ["ctcp:ping", this.reply(msg)]);
|
||||
else
|
||||
this.emit("data", ["message", this.reply(msg)]);
|
||||
}.bind(client));
|
||||
|
||||
client._cmd.set("NOTICE", function (msg) { // notice
|
||||
|
|
|
@ -75,21 +75,3 @@ export default client => {
|
|||
this.server.user.set(msg.params[1], tmpuser);
|
||||
}.bind(client));
|
||||
};
|
||||
|
||||
Map.prototype.hasi = function (val) {
|
||||
for (let [key] of this)
|
||||
if (key.toLowerCase() === val.toLowerCase())
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
Map.prototype.geti = function (val) {
|
||||
for (let [key, value] of this)
|
||||
if (key.toLowerCase() === val.toLowerCase())
|
||||
return value;
|
||||
return false;
|
||||
};
|
||||
Map.prototype.deli = function (val) {
|
||||
for (let [key] of this)
|
||||
if (key.toLowerCase() === val.toLowerCase())
|
||||
this.delete(key);
|
||||
};
|
||||
|
|
|
@ -79,7 +79,7 @@ export class tg extends EventEmitter {
|
|||
method: "POST",
|
||||
body: {
|
||||
chat_id: chatid,
|
||||
text: msg,
|
||||
text: msg.split("\n").length > 1 ? `<code>${msg}</code>` : msg,
|
||||
parse_mode: "HTML"
|
||||
}
|
||||
};
|
||||
|
@ -100,17 +100,23 @@ export class tg extends EventEmitter {
|
|||
channel: tmp.chat.title,
|
||||
channelid: tmp.chat.id,
|
||||
user: {
|
||||
prefix: `${tmp.from.username}!${tmp.from.id}`,
|
||||
nick: tmp.from.first_name,
|
||||
username: tmp.from.username,
|
||||
account: tmp.from.id.toString(),
|
||||
level: getLevel("Telegram", {
|
||||
prefix: `${tmp.from.username}!${tmp.from.id}`,
|
||||
nick: tmp.from.first_name,
|
||||
username: tmp.from.username,
|
||||
account: tmp.from.id.toString()
|
||||
})
|
||||
},
|
||||
self: this.server,
|
||||
message: tmp.text,
|
||||
time: tmp.date,
|
||||
raw: tmp,
|
||||
reply: msg => this.send(tmp.chat.id, this.format(msg), tmp.message_id),
|
||||
replyAction: msg => this.send(tmp.chat.id, this.format(`f0ck ${msg}`), tmp.message_id),
|
||||
replyAction: msg => this.send(tmp.chat.id, this.format(`Uwe ${msg}`), tmp.message_id),
|
||||
replyNotice: msg => this.send(tmp.chat.id, this.format(msg), tmp.message_id),
|
||||
_user: this.server.user
|
||||
};
|
||||
|
@ -125,21 +131,3 @@ export class tg extends EventEmitter {
|
|||
;
|
||||
}
|
||||
}
|
||||
|
||||
Map.prototype.hasi = function(val) {
|
||||
for (let [key] of this)
|
||||
if(key.toLowerCase() === val.toLowerCase())
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
Map.prototype.geti = function(val) {
|
||||
for (let [key, value] of this)
|
||||
if(key.toLowerCase() === val.toLowerCase())
|
||||
return value;
|
||||
return false;
|
||||
};
|
||||
Map.prototype.deli = function(val) {
|
||||
for (let [key] of this)
|
||||
if(key.toLowerCase() === val.toLowerCase())
|
||||
this.delete(key);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user