fix(core): method stop

This commit is contained in:
socram03 2023-11-08 20:24:24 -04:00
parent 02b8bd0d28
commit 0fcc92ab26
2 changed files with 19 additions and 16 deletions

View File

@ -1,10 +1,10 @@
import { GatewayIntentBits, Identify, When } from '@biscuitland/common'; import { GatewayIntentBits, Identify, When } from "@biscuitland/common";
import type { BiscuitRESTOptions, CDNRoutes, Routes } from '@biscuitland/rest'; import type { BiscuitRESTOptions, CDNRoutes, Routes } from "@biscuitland/rest";
import { BiscuitREST, CDN, Router } from '@biscuitland/rest'; import { BiscuitREST, CDN, Router } from "@biscuitland/rest";
import { GatewayEvents, ShardManager, ShardManagerOptions } from '@biscuitland/ws'; import { GatewayEvents, ShardManager, ShardManagerOptions } from "@biscuitland/ws";
import EventEmitter2 from 'eventemitter2'; import EventEmitter2 from "eventemitter2";
import { MainManager, getBotIdFromToken } from '.'; import { MainManager, getBotIdFromToken } from ".";
import { Handler, actionHandler } from './events/handler'; import { Handler, actionHandler } from "./events/handler";
export class Session<On extends boolean = boolean> extends EventEmitter2 { export class Session<On extends boolean = boolean> extends EventEmitter2 {
constructor(public options: BiscuitOptions) { constructor(public options: BiscuitOptions) {
@ -67,7 +67,7 @@ export class Session<On extends boolean = boolean> extends EventEmitter2 {
if (!rest) { if (!rest) {
return new BiscuitREST({ return new BiscuitREST({
token: this.options.token, token: this.options.token,
...this.options.defaultRestOptions ...this.options.defaultRestOptions,
}); });
} }
@ -75,7 +75,7 @@ export class Session<On extends boolean = boolean> extends EventEmitter2 {
return rest; return rest;
} }
throw new Error('[CORE] REST not found'); throw new Error("[CORE] REST not found");
} }
async start() { async start() {
@ -92,10 +92,10 @@ export class Session<On extends boolean = boolean> extends EventEmitter2 {
// @ts-expect-error // @ts-expect-error
actionHandler([ctx, { t, d }, shard]); actionHandler([ctx, { t, d }, shard]);
}, },
...this.options.defaultGatewayOptions ...this.options.defaultGatewayOptions,
}); });
ctx.once('READY', (payload) => { ctx.once("READY", (payload) => {
const { user, application } = payload; const { user, application } = payload;
this.botId = user.id; this.botId = user.id;
this.applicationId = application.id; this.applicationId = application.id;
@ -106,16 +106,16 @@ export class Session<On extends boolean = boolean> extends EventEmitter2 {
async stop() { async stop() {
this.removeAllListeners(); this.removeAllListeners();
await this.gateway.explode(); await this.gateway.disconnectAll();
} }
} }
export type HandlePayload = Pick<ShardManagerOptions, 'handlePayload'>['handlePayload']; export type HandlePayload = Pick<ShardManagerOptions, "handlePayload">["handlePayload"];
export interface BiscuitOptions { export interface BiscuitOptions {
token: string; token: string;
intents: number | GatewayIntentBits; intents: number | GatewayIntentBits;
rest?: BiscuitREST; rest?: BiscuitREST;
defaultRestOptions?: Partial<BiscuitRESTOptions>; defaultRestOptions?: Partial<BiscuitRESTOptions>;
defaultGatewayOptions?: Identify<Partial<Omit<ShardManagerOptions, 'token' | 'intents'>>>; defaultGatewayOptions?: Identify<Partial<Omit<ShardManagerOptions, "token" | "intents">>>;
} }

View File

@ -108,8 +108,11 @@ export class ShardManager extends Collection<number, Shard> {
disconnectAll() { disconnectAll() {
this.logger.info("Disconnect all shards"); this.logger.info("Disconnect all shards");
// biome-ignore lint/complexity/noForEach: In maps, for each and for of have same performance return new Promise((resolve) => {
return this.forEach((shard) => shard.disconnect()); // 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"]) { setShardPresence(shardId: number, payload: GatewayUpdatePresence["d"]) {