qaut.js 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.d.ts +3 -2
- package/src/index.js +25 -1
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -121,11 +121,12 @@ export declare class Client extends EventEmitter {
|
|
|
121
121
|
polling: boolean;
|
|
122
122
|
pollIntervalMs: number;
|
|
123
123
|
keepAlive: boolean;
|
|
124
|
-
constructor(options?: { token?: string; intents?: Array<number | bigint | string> | number | bigint | string; restBaseUrl?: string; keepAlive?: boolean; polling?: boolean; pollIntervalMs?: number });
|
|
124
|
+
constructor(options?: { token?: string; intents?: Array<number | bigint | string> | number | bigint | string; restBaseUrl?: string; keepAlive?: boolean; polling?: boolean; pollIntervalMs?: number; registerProcessShutdown?: boolean });
|
|
125
125
|
login(token?: string): Promise<string>;
|
|
126
126
|
startKeepAlive(): this;
|
|
127
127
|
startPolling(): this;
|
|
128
|
-
destroy(): this
|
|
128
|
+
destroy(options?: { setOffline?: boolean }): Promise<this>;
|
|
129
|
+
attachProcessShutdown(): this;
|
|
129
130
|
setPresence(presence?: Record<string, unknown>): Promise<unknown>;
|
|
130
131
|
setStatus(status: string): Promise<unknown>;
|
|
131
132
|
channel(id: string): TextChannel;
|
package/src/index.js
CHANGED
|
@@ -261,6 +261,9 @@ class Client extends EventEmitter {
|
|
|
261
261
|
this.pollIntervalMs = Number(options.pollIntervalMs || 1500);
|
|
262
262
|
this.pollInterval = null;
|
|
263
263
|
this.gatewayCursor = null;
|
|
264
|
+
this.destroyed = false;
|
|
265
|
+
this.registerProcessShutdown = options.registerProcessShutdown !== false;
|
|
266
|
+
this.boundShutdown = null;
|
|
264
267
|
}
|
|
265
268
|
|
|
266
269
|
async login(token = this.token) {
|
|
@@ -271,6 +274,7 @@ class Client extends EventEmitter {
|
|
|
271
274
|
this.user = me;
|
|
272
275
|
if (this.keepAlive) this.startKeepAlive();
|
|
273
276
|
if (this.polling) this.startPolling();
|
|
277
|
+
if (this.registerProcessShutdown) this.attachProcessShutdown();
|
|
274
278
|
this.emit(Events.ClientReady, me);
|
|
275
279
|
return token;
|
|
276
280
|
}
|
|
@@ -283,7 +287,16 @@ class Client extends EventEmitter {
|
|
|
283
287
|
return this;
|
|
284
288
|
}
|
|
285
289
|
|
|
286
|
-
destroy() {
|
|
290
|
+
async destroy(options = {}) {
|
|
291
|
+
if (this.destroyed) return this;
|
|
292
|
+
this.destroyed = true;
|
|
293
|
+
if (options.setOffline !== false && this.token) {
|
|
294
|
+
try {
|
|
295
|
+
await this.setPresence({ status: Status.Offline });
|
|
296
|
+
} catch (err) {
|
|
297
|
+
this.emit(Events.Debug, `Failed to set offline presence: ${err.message}`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
287
300
|
if (this.keepAliveInterval) clearInterval(this.keepAliveInterval);
|
|
288
301
|
if (this.pollInterval) clearInterval(this.pollInterval);
|
|
289
302
|
this.keepAliveInterval = null;
|
|
@@ -292,6 +305,17 @@ class Client extends EventEmitter {
|
|
|
292
305
|
return this;
|
|
293
306
|
}
|
|
294
307
|
|
|
308
|
+
attachProcessShutdown() {
|
|
309
|
+
if (this.boundShutdown || typeof process === 'undefined') return this;
|
|
310
|
+
this.boundShutdown = async () => {
|
|
311
|
+
await this.destroy();
|
|
312
|
+
process.exit(0);
|
|
313
|
+
};
|
|
314
|
+
process.once('SIGINT', this.boundShutdown);
|
|
315
|
+
process.once('SIGTERM', this.boundShutdown);
|
|
316
|
+
return this;
|
|
317
|
+
}
|
|
318
|
+
|
|
295
319
|
startPolling() {
|
|
296
320
|
if (this.pollInterval) return this;
|
|
297
321
|
this.gatewayCursor = new Date().toISOString();
|