catch poll timeout
This commit is contained in:
parent
82ab5f7c91
commit
bde8819e19
|
@ -41,8 +41,9 @@ export default class tg extends EventEmitter {
|
|||
};
|
||||
}
|
||||
async poll() {
|
||||
try {
|
||||
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)
|
||||
return this.emit("data", ["error", res.description]);
|
||||
if (res.result.length === 0)
|
||||
|
@ -64,6 +65,13 @@ export default class tg extends EventEmitter {
|
|||
return this.emit("data", ["message", this.reply(res.message)]);
|
||||
}
|
||||
}
|
||||
catch(lel) {
|
||||
return this.emit("data", ["error", "tg timed out lol"]);
|
||||
}
|
||||
finally {
|
||||
setTimeout(async () => { await this.poll(); }, this.options.pollrate);
|
||||
}
|
||||
}
|
||||
async send(chatid, msg, reply = null) {
|
||||
msg = Array.isArray(msg) ? msg.join("\n") : msg;
|
||||
if (msg.length === 0 || msg.length > 2048)
|
||||
|
|
Loading…
Reference in New Issue
Block a user