multimsg in tg

This commit is contained in:
Flummi 2022-05-07 12:35:09 +02:00
parent d510b14880
commit 3b75d441f0
3 changed files with 37 additions and 36 deletions

View File

@ -1,6 +1,6 @@
{
"name": "cuffeo",
"version": "1.0.8-1",
"version": "1.1.0",
"description": "A multi-protocol chatbot library with nearly zero dependencies.",
"main": "src/index.mjs",
"scripts": {},
@ -17,7 +17,7 @@
"author": "Flummi & jkhsjdhjs",
"license": "MIT",
"dependencies": {
"flumm-fetch-cookies": "^1.4.0"
"flumm-fetch": "^1.0.1"
},
"bugs": {
"url": "https://github.com/kein-Bot/cuffeo/issues"

View File

@ -1,7 +1,7 @@
import https from "https";
import url from "url";
import EventEmitter from "events";
import fetch from "flumm-fetch-cookies";
import fetch from "flumm-fetch";
export default class slack extends EventEmitter {
constructor(options) {

View File

@ -1,4 +1,4 @@
import fetch from "flumm-fetch-cookies";
import fetch from "flumm-fetch";
import EventEmitter from "events";
const allowedFiles = [ 'audio', 'video', 'photo', 'document' ];
@ -50,16 +50,16 @@ export default class tg extends EventEmitter {
}
async poll() {
try {
let res = await (await fetch(`${this.api}/getUpdates?offset=${this.lastUpdate}&allowed_updates=message`)).json();
const _res = await (await fetch(`${this.api}/getUpdates?offset=${this.lastUpdate}&allowed_updates=message`)).json();
if(!res.ok)
throw { type: "tg", message: res.description};
if(res.result.length === 0)
if(!_res.ok)
throw { type: "tg", message: _res.description};
if(_res.result.length === 0)
return;
res = res.result[res.result.length - 1];
this.lastUpdate = res.update_id + 1;
this.lastUpdate = _res.result[_res.result.length - 1].update_id + 1;
_res.result.forEach(async res => {
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)) {
@ -88,6 +88,7 @@ export default class tg extends EventEmitter {
this.emit("data", ["message", this.reply(res.message)]);
}
});
}
catch(err) {
if(!err.type)