@seedcord/gateway 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +17 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -14
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { ButtonBuilder, TextDisplayBuilder } from "@discordjs/builders";
|
|
|
10
10
|
import { buildSlashRoute } from "@seedcord/utils/internal";
|
|
11
11
|
import { Plugin as Plugin$1 } from "@seedcord/core/plugin";
|
|
12
12
|
import { CoordinatedShutdown, CoordinatedStartup, Pluggable } from "@seedcord/core/node";
|
|
13
|
-
import { CommandRegistry, HealthCheck, ShutdownPhase, StartupPhase, SubscriberLoader,
|
|
13
|
+
import { CommandRegistry, DRAIN_TASK_TIMEOUT_MS, DRAIN_WINDOW_MS, HealthCheck, ShutdownPhase, StartupPhase, SubscriberLoader, drainInFlight, shutdownOf } from "@seedcord/core/node/internal";
|
|
14
14
|
import { MemoryRateLimiter } from "@seedcord/rate-limiter";
|
|
15
15
|
import { HostAugmentTarget, HostVersion, SeedcordBrand } from "@seedcord/types/internal";
|
|
16
16
|
import { Envapter } from "envapt";
|
|
@@ -1589,10 +1589,10 @@ function extractErrorResponse(error, core, origin) {
|
|
|
1589
1589
|
};
|
|
1590
1590
|
}
|
|
1591
1591
|
reportRawFault(error, core, origin, uuid);
|
|
1592
|
-
const
|
|
1592
|
+
const Override = core.config.errors?.defaultError;
|
|
1593
1593
|
return {
|
|
1594
1594
|
uuid,
|
|
1595
|
-
response:
|
|
1595
|
+
response: Override ? new Override(uuid).render(ctx) : new Fault().render(ctx)
|
|
1596
1596
|
};
|
|
1597
1597
|
}
|
|
1598
1598
|
function reportFault(denial, core, origin, uuid) {
|
|
@@ -1844,12 +1844,12 @@ var EventDispatcher = class {
|
|
|
1844
1844
|
});
|
|
1845
1845
|
}
|
|
1846
1846
|
async runMiddlewares(eventName, args) {
|
|
1847
|
-
for (const { ctor, events } of this.middlewares) {
|
|
1847
|
+
for (const { ctor: Middleware, events } of this.middlewares) {
|
|
1848
1848
|
if (events && !events.includes(eventName)) continue;
|
|
1849
1849
|
try {
|
|
1850
|
-
await new
|
|
1850
|
+
await new Middleware(args, this.core, eventName).execute();
|
|
1851
1851
|
} catch (caught) {
|
|
1852
|
-
handleEventFault(caught, String(eventName),
|
|
1852
|
+
handleEventFault(caught, String(eventName), Middleware.name, args, this.core);
|
|
1853
1853
|
return false;
|
|
1854
1854
|
}
|
|
1855
1855
|
}
|
|
@@ -1915,7 +1915,7 @@ var EventDispatcher = class {
|
|
|
1915
1915
|
this.draining = true;
|
|
1916
1916
|
}
|
|
1917
1917
|
drain(timeoutMs) {
|
|
1918
|
-
return
|
|
1918
|
+
return drainInFlight(this.inFlight, timeoutMs, this.logger, "Events");
|
|
1919
1919
|
}
|
|
1920
1920
|
async processEvent(eventName, args) {
|
|
1921
1921
|
const handlerEntries = this.eventMap.get(eventName);
|
|
@@ -1931,15 +1931,15 @@ var EventDispatcher = class {
|
|
|
1931
1931
|
await this.processHandler(eventName, entry.ctor, args);
|
|
1932
1932
|
}
|
|
1933
1933
|
}
|
|
1934
|
-
async processHandler(eventName,
|
|
1934
|
+
async processHandler(eventName, Ctor, args) {
|
|
1935
1935
|
try {
|
|
1936
|
-
this.logger.debug(`Processing ${paint.sky.bold(eventName)} with ${paint.mute(
|
|
1937
|
-
const handler = new
|
|
1936
|
+
this.logger.debug(`Processing ${paint.sky.bold(eventName)} with ${paint.mute(Ctor.name)}`);
|
|
1937
|
+
const handler = new Ctor(args, this.core, eventName);
|
|
1938
1938
|
const eventCtx = eventGateContext(eventName, args, this.core);
|
|
1939
|
-
await runHandlerGates(
|
|
1939
|
+
await runHandlerGates(Ctor, eventCtx);
|
|
1940
1940
|
await handler.execute();
|
|
1941
1941
|
} catch (caught) {
|
|
1942
|
-
handleEventFault(caught, String(eventName),
|
|
1942
|
+
handleEventFault(caught, String(eventName), Ctor.name, args, this.core);
|
|
1943
1943
|
}
|
|
1944
1944
|
}
|
|
1945
1945
|
};
|
|
@@ -2223,7 +2223,7 @@ var InteractionDispatcher = class {
|
|
|
2223
2223
|
this.draining = true;
|
|
2224
2224
|
}
|
|
2225
2225
|
drain(timeoutMs) {
|
|
2226
|
-
return
|
|
2226
|
+
return drainInFlight(this.inFlight, timeoutMs, this.logger, "Interactions");
|
|
2227
2227
|
}
|
|
2228
2228
|
async handleCustomIdInteraction(interaction, kind) {
|
|
2229
2229
|
if ([...this.keysToIgnore].some((matcher) => matcher.owns(interaction.customId))) return;
|
|
@@ -2283,7 +2283,7 @@ var InteractionDispatcher = class {
|
|
|
2283
2283
|
return new HandlerCtor(interaction, this.core, dispatch);
|
|
2284
2284
|
}
|
|
2285
2285
|
async runMiddlewares(interaction) {
|
|
2286
|
-
for (const { ctor } of this.middlewares) await new
|
|
2286
|
+
for (const { ctor: Middleware } of this.middlewares) await new Middleware(interaction, this.core).execute();
|
|
2287
2287
|
}
|
|
2288
2288
|
async gateRefusal(HandlerCtor, interaction, routeId) {
|
|
2289
2289
|
const monitor = slowGateMonitor();
|
|
@@ -2396,8 +2396,6 @@ function __decorate(decorators, target, key, desc) {
|
|
|
2396
2396
|
|
|
2397
2397
|
//#endregion
|
|
2398
2398
|
//#region src/bot/Bot.ts
|
|
2399
|
-
const DISPATCH_DRAIN_TIMEOUT_MS = 5e3;
|
|
2400
|
-
const DRAIN_TASK_TIMEOUT_MS = 6e3;
|
|
2401
2399
|
const UNBIND_TIMEOUT_MS = 2e3;
|
|
2402
2400
|
const LOGOUT_TIMEOUT_MS = 2e3;
|
|
2403
2401
|
const loggerSlot = Symbol("seedcord:bot:logger");
|
|
@@ -2460,7 +2458,7 @@ var Bot = class {
|
|
|
2460
2458
|
this.#events?.stopAccepting();
|
|
2461
2459
|
}
|
|
2462
2460
|
async #drain() {
|
|
2463
|
-
await Promise.allSettled([this.#interactions?.drain(
|
|
2461
|
+
await Promise.allSettled([this.#interactions?.drain(DRAIN_WINDOW_MS), this.#events?.drain(DRAIN_WINDOW_MS)]);
|
|
2464
2462
|
}
|
|
2465
2463
|
/** @internal */
|
|
2466
2464
|
async [initSlot]() {
|
|
@@ -2510,7 +2508,7 @@ function initBot(bot) {
|
|
|
2510
2508
|
//#endregion
|
|
2511
2509
|
//#region src/version.ts
|
|
2512
2510
|
/** Package version */
|
|
2513
|
-
const version = "0.5.
|
|
2511
|
+
const version = "0.5.1";
|
|
2514
2512
|
|
|
2515
2513
|
//#endregion
|
|
2516
2514
|
//#region src/Seedcord.ts
|
|
@@ -2546,7 +2544,7 @@ var Seedcord = class Seedcord extends Pluggable {
|
|
|
2546
2544
|
* @throws A **SeedcordError** When attempting to create multiple instances (singleton)
|
|
2547
2545
|
*/
|
|
2548
2546
|
constructor(config) {
|
|
2549
|
-
super(new CoordinatedShutdown(), new CoordinatedStartup());
|
|
2547
|
+
super(new CoordinatedShutdown(config.lifecycle?.shutdownDeadline), new CoordinatedStartup());
|
|
2550
2548
|
this.config = config;
|
|
2551
2549
|
installNodeDefaults(config.logger);
|
|
2552
2550
|
setBotColor(config.botColor);
|