Revert "catch poll timeout"

This reverts commit 50142bd6f2
This commit is contained in:
Flummi 2019-09-14 14:55:03 +00:00
parent 50142bd6f2
commit 82ab5f7c91

View File

@ -41,8 +41,8 @@ export default class tg extends EventEmitter {
}; };
} }
async poll() { async poll() {
try {
let res = await (await fetch(`${this.api}/getUpdates?offset=${this.lastUpdate}&allowed_updates=message`)).json(); let res = await (await fetch(`${this.api}/getUpdates?offset=${this.lastUpdate}&allowed_updates=message`)).json();
setTimeout(async () => { await this.poll(); }, this.options.pollrate);
if (!res.ok) if (!res.ok)
return this.emit("data", ["error", res.description]); return this.emit("data", ["error", res.description]);
if (res.result.length === 0) if (res.result.length === 0)
@ -64,21 +64,15 @@ export default class tg extends EventEmitter {
return this.emit("data", ["message", this.reply(res.message)]); return this.emit("data", ["message", this.reply(res.message)]);
} }
} }
catch {
return this.emit("data", ["error", "tg timed out lol"]);
}
finally {
setTimeout(async () => { await this.poll(); }, this.options.pollrate);
}
}
async send(chatid, msg, reply = null) { async send(chatid, msg, reply = null) {
msg = Array.isArray(msg) ? msg.join("\n") : msg;
if (msg.length === 0 || msg.length > 2048) if (msg.length === 0 || msg.length > 2048)
return this.emit("data", ["error", "msg to short or to long lol"]); return this.emit("data", ["error", "msg to short or to long lol"]);
const opts = { const opts = {
method: "POST", method: "POST",
body: { body: {
chat_id: chatid, chat_id: chatid,
text: msg.split("\n").length > 1 ? `<code>${msg}</code>` : msg, text: this.format(msg),//msg.split("\n").length > 1 ? `<code>${this.format(msg)}</code>` : this.format(msg),
parse_mode: "HTML" parse_mode: "HTML"
} }
}; };
@ -105,9 +99,9 @@ export default class tg extends EventEmitter {
message: tmp.text, message: tmp.text,
time: tmp.date, time: tmp.date,
raw: tmp, raw: tmp,
reply: msg => this.send(tmp.chat.id, this.format(msg), tmp.message_id), reply: msg => this.send(tmp.chat.id, msg, tmp.message_id),
replyAction: msg => this.send(tmp.chat.id, this.format(`Uwe ${msg}`), tmp.message_id), replyAction: msg => this.send(tmp.chat.id, `Uwe ${msg}`, tmp.message_id),
replyNotice: msg => this.send(tmp.chat.id, this.format(msg), tmp.message_id), replyNotice: msg => this.send(tmp.chat.id, msg, tmp.message_id),
_user: this.server.user _user: this.server.user
}; };
} }
@ -115,6 +109,7 @@ export default class tg extends EventEmitter {
return msg.toString() return msg.toString()
.split("<").join("&lt;") .split("<").join("&lt;")
.split(">").join("&gt;") .split(">").join("&gt;")
.split("&").join("&amp;")
.replace(/\[b\](.*?)\[\/b\]/g, "<b>$1</b>") // bold .replace(/\[b\](.*?)\[\/b\]/g, "<b>$1</b>") // bold
.replace(/\[i\](.*?)\[\/i\]/g, "<i>$1</i>") // italic .replace(/\[i\](.*?)\[\/i\]/g, "<i>$1</i>") // italic
.replace(/\[color=(.*?)](.*?)\[\/color\]/g, "$2") .replace(/\[color=(.*?)](.*?)\[\/color\]/g, "$2")