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