fix: client.destroy()

This commit is contained in:
Elysia 2023-02-28 13:18:09 +07:00
parent 47b420d289
commit ba22a5f550
5 changed files with 10 additions and 11 deletions

View File

@ -247,6 +247,10 @@ class Client extends BaseClient {
*/
this.usedCodes = [];
setInterval(() => {
this.usedCodes = [];
}, 1000 * 60 * 60).unref();
this.session_id = null;
if (this.options.messageSweepInterval > 0) {
@ -259,11 +263,6 @@ class Client extends BaseClient {
this.options.messageSweepInterval * 1_000,
).unref();
}
setInterval(() => {
this.usedCodes = [];
// 1 hours
}, 3_600_000);
}
/**
@ -667,7 +666,7 @@ class Client extends BaseClient {
let redeem = false;
this.emit('debug', `${chalk.greenBright('[Nitro]')} Redeem Nitro: ${nitroArray.join(', ')}`);
for await (const code of codeArray) {
if (this.usedCodes.indexOf(code) > -1) continue;
if (this.usedCodes.includes(code)) continue;
await this.api.entitlements['gift-codes'](code)
.redeem.post({
auth: true,
@ -1002,7 +1001,7 @@ class Client extends BaseClient {
* @returns {Promise<void> | null}
*/
sleep(miliseconds) {
return typeof miliseconds === 'number' ? new Promise(r => setTimeout(r, miliseconds)) : null;
return typeof miliseconds === 'number' ? new Promise(r => setTimeout(r, miliseconds).unref()) : null;
}
/**

View File

@ -100,7 +100,7 @@ class ClientUser extends User {
this.client.emit('debug', `Samsung Presence: ${this._packageName}`);
if (!this._packageName) return;
this.setSamsungActivity(this._packageName, 'UPDATE');
}, 1000 * 60 * 10);
}, 1000 * 60 * 10).unref();
// 20 minutes max
}
}

View File

@ -280,7 +280,7 @@ new DiscordAuthWebsocket({
_heartbeatAck() {
setTimeout(() => {
this._heartbeat();
}, this.heartbeatInterval);
}, this.heartbeatInterval).unref();
}
_ready(data) {
this._logger('debug', 'Attempting server handshake...');

View File

@ -22,7 +22,7 @@ module.exports = class ProcessServer {
this.scan = this.scan.bind(this);
this.scan();
setInterval(this.scan, 5000);
setInterval(this.scan, 5000).unref();
if (this.debug) log('started');
}

View File

@ -134,7 +134,7 @@ const socketIsAvailable = async socket => {
// eslint-disable-next-line prefer-promise-reject-errors
new Promise((res, rej) => socket.on('pong', () => rej('socket ponged'))), // Ponged
// eslint-disable-next-line prefer-promise-reject-errors
new Promise((res, rej) => setTimeout(() => rej('timed out'), 1000)), // Timed out
new Promise((res, rej) => setTimeout(() => rej('timed out'), 1000).unref()), // Timed out
]).then(
() => true,
e => e,