-slack: interval management
This commit is contained in:
parent
e13a494ea2
commit
a382d0fda7
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cuffeo",
|
||||
"version": "1.0.5-3",
|
||||
"version": "1.0.6",
|
||||
"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.3.4"
|
||||
"flumm-fetch-cookies": "^1.3.5"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/kein-Bot/cuffeo/issues"
|
||||
|
@ -12,6 +12,7 @@ export default class slack extends EventEmitter {
|
||||
this.network = "Slack";
|
||||
this.api = "https://slack.com/api";
|
||||
this.socket = null;
|
||||
this.interval = null;
|
||||
this.server = {
|
||||
set: this.set,
|
||||
channel: new Map(),
|
||||
@ -56,7 +57,7 @@ export default class slack extends EventEmitter {
|
||||
this.server.wss.socket = sock;
|
||||
this.server.wss.socket.setDefaultEncoding("utf-8");
|
||||
|
||||
setInterval(async () => await this.ping(), 3e4); // 30 seconds lul
|
||||
this.interval = setInterval(async () => await this.ping(), 3e4); // 30 seconds lul
|
||||
|
||||
this.server.wss.socket.on("data", async data => {
|
||||
try {
|
||||
@ -104,6 +105,7 @@ export default class slack extends EventEmitter {
|
||||
async reconnect() {
|
||||
this.server.wss.url = null;
|
||||
this.server.wss.socket = null;
|
||||
clearTimeout(this.interval);
|
||||
this.emit("data", [ "info", "reconnecting slack" ]);
|
||||
return await this.connect();
|
||||
}
|
||||
@ -139,7 +141,7 @@ export default class slack extends EventEmitter {
|
||||
}
|
||||
|
||||
async ping() {
|
||||
await this.write({
|
||||
return await this.write({
|
||||
type: "ping"
|
||||
});
|
||||
}
|
||||
@ -171,10 +173,14 @@ export default class slack extends EventEmitter {
|
||||
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));
|
||||
this.server.wss.socket.uncork();
|
||||
try {
|
||||
this.server.wss.socket.cork();
|
||||
this.server.wss.socket.write(frame);
|
||||
this.server.wss.socket.write(Buffer.from(msg));
|
||||
this.server.wss.socket.uncork();
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
reply(tmp) {
|
||||
|
Loading…
Reference in New Issue
Block a user