- slack: bugfix

- update flumm-fetch-cookies
- version bump to 1.0.5
This commit is contained in:
Flummi 2020-02-13 12:35:39 +01:00
parent f18d318334
commit a221ef715a
2 changed files with 21 additions and 18 deletions

View File

@ -1,6 +1,6 @@
{
"name": "cuffeo",
"version": "1.0.4",
"version": "1.0.5",
"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.1.1"
"flumm-fetch-cookies": "^1.3.4"
},
"bugs": {
"url": "https://github.com/kein-Bot/cuffeo/issues"

View File

@ -31,15 +31,15 @@ export default class slack extends EventEmitter {
async connect() {
const res = await (await fetch(`${this.api}/rtm.start?token=${this.token}`)).json();
if (!res.ok)
return this.emit("data", [ "error", res.description ]); // more infos
res.channels.forEach(channel => this.server.channel.set(channel.id, channel.name));
res.users.forEach(user => this.server.user.set(user.id, {
account: user.name,
nickname: user.real_name
}));
if (!res.ok)
return this.emit("data", [ "error", res.description ]); // more infos
this.server.wss.url = url.parse(res.url);
https.get({
@ -90,21 +90,21 @@ export default class slack extends EventEmitter {
this.emit("data", [ "error", err ]);
}
})
.on("end", () => {
.on("end", async () => {
this.emit("data", [ "debug", "stream ended" ]);
this.reconnect();
await this.reconnect();
})
.on("error", err => {
.on("error", async err => {
this.emit("data", [ "error", err ]);
this.reconnect();
await this.reconnect();
});
});
}
reconnect() {
async reconnect() {
this.server.wss.url = null;
this.server.wss.socket = null;
this.connect();
await this.connect();
}
async getChannel(channelId) {
@ -167,6 +167,9 @@ export default class slack extends EventEmitter {
if(frame_length > 6)
frame.writeUInt16BE(payload.length, 2);
if (!this.server.wss.socket)
await this.reconnect();
this.server.wss.socket.cork();
this.server.wss.socket.write(frame);
this.server.wss.socket.write(Buffer.from(msg));