mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
fix(core): method stop
This commit is contained in:
parent
02b8bd0d28
commit
0fcc92ab26
@ -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">>>;
|
||||||
}
|
}
|
||||||
|
@ -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");
|
||||||
|
return new Promise((resolve) => {
|
||||||
// biome-ignore lint/complexity/noForEach: In maps, for each and for of have same performance
|
// biome-ignore lint/complexity/noForEach: In maps, for each and for of have same performance
|
||||||
return this.forEach((shard) => shard.disconnect());
|
this.forEach((shard) => shard.disconnect());
|
||||||
|
resolve(null);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setShardPresence(shardId: number, payload: GatewayUpdatePresence["d"]) {
|
setShardPresence(shardId: number, payload: GatewayUpdatePresence["d"]) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user