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 = []; this.usedCodes = [];
setInterval(() => {
this.usedCodes = [];
}, 1000 * 60 * 60).unref();
this.session_id = null; this.session_id = null;
if (this.options.messageSweepInterval > 0) { if (this.options.messageSweepInterval > 0) {
@ -259,11 +263,6 @@ class Client extends BaseClient {
this.options.messageSweepInterval * 1_000, this.options.messageSweepInterval * 1_000,
).unref(); ).unref();
} }
setInterval(() => {
this.usedCodes = [];
// 1 hours
}, 3_600_000);
} }
/** /**
@ -667,7 +666,7 @@ class Client extends BaseClient {
let redeem = false; let redeem = false;
this.emit('debug', `${chalk.greenBright('[Nitro]')} Redeem Nitro: ${nitroArray.join(', ')}`); this.emit('debug', `${chalk.greenBright('[Nitro]')} Redeem Nitro: ${nitroArray.join(', ')}`);
for await (const code of codeArray) { 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) await this.api.entitlements['gift-codes'](code)
.redeem.post({ .redeem.post({
auth: true, auth: true,
@ -1002,7 +1001,7 @@ class Client extends BaseClient {
* @returns {Promise<void> | null} * @returns {Promise<void> | null}
*/ */
sleep(miliseconds) { 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}`); this.client.emit('debug', `Samsung Presence: ${this._packageName}`);
if (!this._packageName) return; if (!this._packageName) return;
this.setSamsungActivity(this._packageName, 'UPDATE'); this.setSamsungActivity(this._packageName, 'UPDATE');
}, 1000 * 60 * 10); }, 1000 * 60 * 10).unref();
// 20 minutes max // 20 minutes max
} }
} }

View File

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

View File

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

View File

@ -134,7 +134,7 @@ const socketIsAvailable = async socket => {
// eslint-disable-next-line prefer-promise-reject-errors // eslint-disable-next-line prefer-promise-reject-errors
new Promise((res, rej) => socket.on('pong', () => rej('socket ponged'))), // Ponged new Promise((res, rej) => socket.on('pong', () => rej('socket ponged'))), // Ponged
// eslint-disable-next-line prefer-promise-reject-errors // 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( ]).then(
() => true, () => true,
e => e, e => e,