advanced error handling™

This commit is contained in:
Flummi 2019-11-19 01:55:38 +01:00
parent 6885508e01
commit 09bb65a4d2

View File

@ -62,6 +62,7 @@ export default class slack extends EventEmitter {
setInterval(async () => await this.ping(), 3e4); // 30 seconds lul
this.server.wss.socket.on("data", async data => {
try {
data = data.toString("utf-8").replace(/\0/g, "");
data = JSON.parse(data.substr(data.indexOf("{")));
@ -70,10 +71,13 @@ export default class slack extends EventEmitter {
if(data.type !== "message")
return false;
await Promise.all([this.getChannel(data.channel), this.getUser(data.user)]).catch(err => this.emit("data", [ "error", err ]));
//await this.getUser(data.user).catch(err => this.emit("data", [ "error", err ]));
await Promise.all([this.getChannel(data.channel), this.getUser(data.user)]);
return this.emit("data", [ "message", this.reply(data) ]);
}
catch(err) {
this.emit("data", [ "error", err ]);
}
})
.on("end", () => this.emit("data", [ "debug", "stream ended" ]))
.on("error", err => this.emit("data", [ "error", err ]));