Usercache, removed split error

This commit is contained in:
Flummi 2017-11-20 02:16:08 +01:00
parent fa3d48ad98
commit 692324b3a7

View File

@ -1,6 +1,7 @@
let tgapi = require("node-telegram-bot-api"); import { logger } from "../log.js";
let EventEmitter = require("events").EventEmitter; const tgapi = require("node-telegram-bot-api")
let util = require("util"); , EventEmitter = require("events").EventEmitter
, util = require("util");
class tg { class tg {
constructor(options) { constructor(options) {
@ -10,15 +11,22 @@ class tg {
this.options.polling = options.polling || true; this.options.polling = options.polling || true;
this.client = new tgapi(this.options.token, this.options); this.client = new tgapi(this.options.token, this.options);
this.server = {
channel: new Map(),
user: new Map()
};
this.client.on("message", msg => { this.client.on("message", msg => {
if (msg.date >= (~~(Date.now() / 1000) - 10)) { if (!this.server.user.has(msg.from.first_name))
try { this.server.user.set(msg.from.username || msg.from.first_name, {
msg.text = msg.text && msg.text.match(/^\//g) ? msg.text.replace(/^\//g, ".") : msg.text; nick: msg.from.first_name,
this.emit("data", ["message", this.reply(msg)]); username: msg.from.username,
} id: msg.from.id
catch(err) { });
console.log(err);
} if (msg.date >= (~~(Date.now() / 1000) - 10) && msg.text !== undefined) {
msg.text = msg.text.replace(/^\//g, ".");
this.emit("data", ["message", this.reply(msg)]);
} }
}); });
} }
@ -39,15 +47,10 @@ class tg {
message: tmp.text, message: tmp.text,
time: tmp.date, time: tmp.date,
raw: tmp, raw: tmp,
reply: msg => { reply: msg => this.send(tmp.chat.id, msg),
this.send(tmp.chat.id, msg); replyAction: msg => this.send(tmp.chat.id, `Uwe ${msg}`),
}, replyNotice: msg => this.send(tmp.chat.id, msg),
replyAction: msg => { _user: this.server.user
this.send(tmp.chat.id, `Uwe ${msg}`);
},
replyNotice: msg => {
this.send(tmp.chat.id, msg);
}
}; };
} }
} }