feat(core): stop session

This commit is contained in:
Marcos Susaña 2023-06-29 01:41:23 -04:00
parent 75401227ca
commit 4cf1cad35e

View File

@ -1,11 +1,10 @@
import { GatewayIntentBits, Identify, When } from '@biscuitland/common';
import type { BiscuitRESTOptions, CDNRoutes, Routes } from '@biscuitland/rest'; import type { BiscuitRESTOptions, CDNRoutes, Routes } from '@biscuitland/rest';
import { CDN, BiscuitREST, Router } from '@biscuitland/rest'; import { BiscuitREST, CDN, Router } from '@biscuitland/rest';
import { Identify, When } from '@biscuitland/common'; import { CreateGatewayManagerOptions, GatewayEvents, GatewayManager } from '@biscuitland/ws';
import EventEmitter2 from 'eventemitter2'; import EventEmitter2 from 'eventemitter2';
import { MainManager, getBotIdFromToken } from '.'; import { MainManager, getBotIdFromToken } from '.';
import { GatewayManager, CreateGatewayManagerOptions, GatewayEvents } from '@biscuitland/ws'; import { Handler, actionHandler } from './events/handler';
import { GatewayIntentBits } from '@biscuitland/common';
import { actionHandler, Handler } 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,8 +66,8 @@ export class Session<On extends boolean = boolean> extends EventEmitter2 {
private createRest(rest: any) { private createRest(rest: any) {
if (!rest) { if (!rest) {
return new BiscuitREST({ return new BiscuitREST({
...this.options.defaultRestOptions, token: this.options.token,
token: this.options.token ...this.options.defaultRestOptions
}); });
} }
@ -103,6 +102,11 @@ export class Session<On extends boolean = boolean> extends EventEmitter2 {
await ctx.gateway.spawnShards(); await ctx.gateway.spawnShards();
} }
async stop(code = 1000, error = 'Stopped') {
this.removeAllListeners();
await this.gateway.shutdown(code, error);
}
} }
export type HandlePayload = Pick<CreateGatewayManagerOptions, 'handlePayload'>['handlePayload']; export type HandlePayload = Pick<CreateGatewayManagerOptions, 'handlePayload'>['handlePayload'];