From 4cf1cad35e1720645a4b6aaaae02dd49344bb5c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Susa=C3=B1a?= Date: Thu, 29 Jun 2023 01:41:23 -0400 Subject: [PATCH] feat(core): stop session --- packages/core/src/session.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/core/src/session.ts b/packages/core/src/session.ts index fbe085a..144f462 100644 --- a/packages/core/src/session.ts +++ b/packages/core/src/session.ts @@ -1,11 +1,10 @@ +import { GatewayIntentBits, Identify, When } from '@biscuitland/common'; import type { BiscuitRESTOptions, CDNRoutes, Routes } from '@biscuitland/rest'; -import { CDN, BiscuitREST, Router } from '@biscuitland/rest'; -import { Identify, When } from '@biscuitland/common'; +import { BiscuitREST, CDN, Router } from '@biscuitland/rest'; +import { CreateGatewayManagerOptions, GatewayEvents, GatewayManager } from '@biscuitland/ws'; import EventEmitter2 from 'eventemitter2'; import { MainManager, getBotIdFromToken } from '.'; -import { GatewayManager, CreateGatewayManagerOptions, GatewayEvents } from '@biscuitland/ws'; -import { GatewayIntentBits } from '@biscuitland/common'; -import { actionHandler, Handler } from './events/handler'; +import { Handler, actionHandler } from './events/handler'; export class Session extends EventEmitter2 { constructor(public options: BiscuitOptions) { @@ -67,8 +66,8 @@ export class Session extends EventEmitter2 { private createRest(rest: any) { if (!rest) { return new BiscuitREST({ - ...this.options.defaultRestOptions, - token: this.options.token + token: this.options.token, + ...this.options.defaultRestOptions }); } @@ -103,6 +102,11 @@ export class Session extends EventEmitter2 { await ctx.gateway.spawnShards(); } + + async stop(code = 1000, error = 'Stopped') { + this.removeAllListeners(); + await this.gateway.shutdown(code, error); + } } export type HandlePayload = Pick['handlePayload'];