prevent duplicate messages

This commit is contained in:
Flummi 2017-12-19 10:42:21 +01:00
parent b8bc1c28b0
commit 1dab59ea67

View File

@ -14,6 +14,7 @@ export class tg extends EventEmitter {
this.network = "Telegram"; this.network = "Telegram";
this.api = `https://api.telegram.org/bot${this.token}`; this.api = `https://api.telegram.org/bot${this.token}`;
this.lastUpdate = 0; this.lastUpdate = 0;
this.lastMessage = 0;
this.server = { this.server = {
channel: new Map(), channel: new Map(),
user: new Map(), user: new Map(),
@ -56,7 +57,8 @@ export class tg extends EventEmitter {
if(res.ok && res.result.length > 0) { if(res.ok && res.result.length > 0) {
res = res.result[res.result.length-1]; res = res.result[res.result.length-1];
this.lastUpdate = res.update_id + 1; this.lastUpdate = res.update_id + 1;
if (res.message.date >= ~~(Date.now() / 1000) - 10) { if (res.message.date >= ~~(Date.now() / 1000) - 10 && res.message.message_id !== this.lastMessage) {
this.lastMessage = res.message.message_id;
if(!this.server.user.has(res.message.from.username || res.message.from.first_name)) { if(!this.server.user.has(res.message.from.username || res.message.from.first_name)) {
this.server.user.set(res.message.from.username || res.message.from.first_name, { this.server.user.set(res.message.from.username || res.message.from.first_name, {
nick: res.message.from.first_name, nick: res.message.from.first_name,