From 0fcc92ab26bf079b82e4a93f8f581fb2f631e3f2 Mon Sep 17 00:00:00 2001 From: socram03 Date: Wed, 8 Nov 2023 20:24:24 -0400 Subject: [PATCH] fix(core): method stop --- packages/core/src/session.ts | 28 ++++++++++++++-------------- packages/ws/src/discord/sharder.ts | 7 +++++-- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/packages/core/src/session.ts b/packages/core/src/session.ts index 7ca9f11..66e4130 100644 --- a/packages/core/src/session.ts +++ b/packages/core/src/session.ts @@ -1,10 +1,10 @@ -import { GatewayIntentBits, Identify, When } from '@biscuitland/common'; -import type { BiscuitRESTOptions, CDNRoutes, Routes } from '@biscuitland/rest'; -import { BiscuitREST, CDN, Router } from '@biscuitland/rest'; -import { GatewayEvents, ShardManager, ShardManagerOptions } from '@biscuitland/ws'; -import EventEmitter2 from 'eventemitter2'; -import { MainManager, getBotIdFromToken } from '.'; -import { Handler, actionHandler } from './events/handler'; +import { GatewayIntentBits, Identify, When } from "@biscuitland/common"; +import type { BiscuitRESTOptions, CDNRoutes, Routes } from "@biscuitland/rest"; +import { BiscuitREST, CDN, Router } from "@biscuitland/rest"; +import { GatewayEvents, ShardManager, ShardManagerOptions } from "@biscuitland/ws"; +import EventEmitter2 from "eventemitter2"; +import { MainManager, getBotIdFromToken } from "."; +import { Handler, actionHandler } from "./events/handler"; export class Session extends EventEmitter2 { constructor(public options: BiscuitOptions) { @@ -67,7 +67,7 @@ export class Session extends EventEmitter2 { if (!rest) { return new BiscuitREST({ token: this.options.token, - ...this.options.defaultRestOptions + ...this.options.defaultRestOptions, }); } @@ -75,7 +75,7 @@ export class Session extends EventEmitter2 { return rest; } - throw new Error('[CORE] REST not found'); + throw new Error("[CORE] REST not found"); } async start() { @@ -92,10 +92,10 @@ export class Session extends EventEmitter2 { // @ts-expect-error actionHandler([ctx, { t, d }, shard]); }, - ...this.options.defaultGatewayOptions + ...this.options.defaultGatewayOptions, }); - ctx.once('READY', (payload) => { + ctx.once("READY", (payload) => { const { user, application } = payload; this.botId = user.id; this.applicationId = application.id; @@ -106,16 +106,16 @@ export class Session extends EventEmitter2 { async stop() { this.removeAllListeners(); - await this.gateway.explode(); + await this.gateway.disconnectAll(); } } -export type HandlePayload = Pick['handlePayload']; +export type HandlePayload = Pick["handlePayload"]; export interface BiscuitOptions { token: string; intents: number | GatewayIntentBits; rest?: BiscuitREST; defaultRestOptions?: Partial; - defaultGatewayOptions?: Identify>>; + defaultGatewayOptions?: Identify>>; } diff --git a/packages/ws/src/discord/sharder.ts b/packages/ws/src/discord/sharder.ts index f960059..a48258a 100644 --- a/packages/ws/src/discord/sharder.ts +++ b/packages/ws/src/discord/sharder.ts @@ -108,8 +108,11 @@ export class ShardManager extends Collection { disconnectAll() { this.logger.info("Disconnect all shards"); - // biome-ignore lint/complexity/noForEach: In maps, for each and for of have same performance - return this.forEach((shard) => shard.disconnect()); + return new Promise((resolve) => { + // biome-ignore lint/complexity/noForEach: In maps, for each and for of have same performance + this.forEach((shard) => shard.disconnect()); + resolve(null); + }); } setShardPresence(shardId: number, payload: GatewayUpdatePresence["d"]) {