mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
feat(gateway): add stopGateway function (#2078)
* Move the shard stopping to gatewayManager in order to stop the gateway standalone. * Update gateway/gateway_manager.ts Co-authored-by: ITOH <to@itoh.at> * Update gateway/stopGateway.ts Co-authored-by: ITOH <to@itoh.at> * Update gateway/stopGateway.ts * Update gateway/stopGateway.ts * Update gateway/stopGateway.ts Co-authored-by: ITOH <to@itoh.at> Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
This commit is contained in:
@@ -235,17 +235,7 @@ export interface HelperUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function stopBot(bot: Bot) {
|
export async function stopBot(bot: Bot) {
|
||||||
// STOP WS
|
await bot.gateway.stopGateway(bot.gateway);
|
||||||
bot.gateway.shards.forEach((shard) => {
|
|
||||||
clearInterval(shard.heartbeat.intervalId);
|
|
||||||
bot.gateway.closeWS(
|
|
||||||
shard.ws,
|
|
||||||
3061,
|
|
||||||
"Discordeno Testing Finished! Do Not RESUME!",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
await delay(5000);
|
|
||||||
|
|
||||||
return bot;
|
return bot;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
import { resume } from "./resume.ts";
|
import { resume } from "./resume.ts";
|
||||||
import { sendShardMessage } from "./sendShardMessage.ts";
|
import { sendShardMessage } from "./sendShardMessage.ts";
|
||||||
import { prepareBuckets, spawnShards } from "./spawnShards.ts";
|
import { prepareBuckets, spawnShards } from "./spawnShards.ts";
|
||||||
|
import { stopGateway } from "./stopGateway";
|
||||||
import { tellWorkerToIdentify } from "./tellWorkerToIdentify.ts";
|
import { tellWorkerToIdentify } from "./tellWorkerToIdentify.ts";
|
||||||
import { DiscordenoShard } from "./shard.ts";
|
import { DiscordenoShard } from "./shard.ts";
|
||||||
|
|
||||||
@@ -88,6 +89,7 @@ export function createGatewayManager(
|
|||||||
handleOnMessage: options.handleOnMessage ?? handleOnMessage,
|
handleOnMessage: options.handleOnMessage ?? handleOnMessage,
|
||||||
processGatewayQueue: options.processGatewayQueue ?? processGatewayQueue,
|
processGatewayQueue: options.processGatewayQueue ?? processGatewayQueue,
|
||||||
closeWS: options.closeWS ?? closeWS,
|
closeWS: options.closeWS ?? closeWS,
|
||||||
|
stopGateway: options.stopGateway ?? stopGateway,
|
||||||
sendShardMessage: options.sendShardMessage ?? sendShardMessage,
|
sendShardMessage: options.sendShardMessage ?? sendShardMessage,
|
||||||
resume: options.resume ?? resume,
|
resume: options.resume ?? resume,
|
||||||
safeRequestsPerShard: options.safeRequestsPerShard ?? safeRequestsPerShard,
|
safeRequestsPerShard: options.safeRequestsPerShard ?? safeRequestsPerShard,
|
||||||
@@ -209,6 +211,8 @@ export interface GatewayManager {
|
|||||||
processGatewayQueue: typeof processGatewayQueue;
|
processGatewayQueue: typeof processGatewayQueue;
|
||||||
/** Closes shard WebSocket connection properly. */
|
/** Closes shard WebSocket connection properly. */
|
||||||
closeWS: typeof closeWS;
|
closeWS: typeof closeWS;
|
||||||
|
/** Use this function to stop the gateway properly. */
|
||||||
|
stopGateway: typeof stopGateway;
|
||||||
/** Properly adds a message to the shards queue. */
|
/** Properly adds a message to the shards queue. */
|
||||||
sendShardMessage: typeof sendShardMessage;
|
sendShardMessage: typeof sendShardMessage;
|
||||||
/** Properly resume an old shards session. */
|
/** Properly resume an old shards session. */
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/** Use this function to stop the gateway properly */
|
||||||
|
export async function stopGateway(gateway: GatewayManager, code = 3061, reason = "Discordeno Testing Finished! Do Not RESUME!") {
|
||||||
|
|
||||||
|
// STOP WS
|
||||||
|
gateway.shards.forEach((shard) => {
|
||||||
|
clearInterval(shard.heartbeat.intervalId);
|
||||||
|
gateway.closeWS(
|
||||||
|
shard.ws,
|
||||||
|
code,
|
||||||
|
|
||||||
|
reason,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
await delay(5000);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user