@seedcord/gateway 0.1.0-next.3 → 0.1.0-next.4
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.cjs +95 -182
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +37 -131
- package/dist/index.mjs +96 -169
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -9
package/dist/index.cjs
CHANGED
|
@@ -38,16 +38,16 @@ let _seedcord_utils_internal = require("@seedcord/utils/internal");
|
|
|
38
38
|
let discord_js = require("discord.js");
|
|
39
39
|
let node_crypto = require("node:crypto");
|
|
40
40
|
node_crypto = __toESM(node_crypto, 1);
|
|
41
|
-
let _seedcord_event_emitter = require("@seedcord/event-emitter");
|
|
42
41
|
let chalk = require("chalk");
|
|
43
42
|
chalk = __toESM(chalk, 1);
|
|
44
43
|
let envapt = require("envapt");
|
|
45
44
|
let discord_api_types_v10 = require("discord-api-types/v10");
|
|
46
45
|
let _seedcord_utils = require("@seedcord/utils");
|
|
47
46
|
let _discordjs_rest = require("@discordjs/rest");
|
|
48
|
-
let
|
|
47
|
+
let _seedcord_core_node_internal = require("@seedcord/core/node/internal");
|
|
49
48
|
let _seedcord_rate_limiter = require("@seedcord/rate-limiter");
|
|
50
49
|
let _seedcord_types_internal = require("@seedcord/types/internal");
|
|
50
|
+
let _seedcord_event_emitter = require("@seedcord/event-emitter");
|
|
51
51
|
let envapt_legacy = require("envapt/legacy");
|
|
52
52
|
let node_path = require("node:path");
|
|
53
53
|
let _seedcord_core_hmr = require("@seedcord/core/hmr");
|
|
@@ -1142,112 +1142,6 @@ async function getConfirmation(interaction, prompt, options) {
|
|
|
1142
1142
|
return confirmed;
|
|
1143
1143
|
}
|
|
1144
1144
|
|
|
1145
|
-
//#endregion
|
|
1146
|
-
//#region src/interfaces/Plugin.ts
|
|
1147
|
-
/**
|
|
1148
|
-
* Base class for Seedcord plugins
|
|
1149
|
-
*
|
|
1150
|
-
* Extend this class to create plugins that integrate with the Seedcord lifecycle.
|
|
1151
|
-
* Plugins have access to the core instance and must implement initialization logic.
|
|
1152
|
-
*/
|
|
1153
|
-
var Plugin = class extends _seedcord_event_emitter.TypedEventEmitter {
|
|
1154
|
-
pluggable;
|
|
1155
|
-
name = this.constructor.name;
|
|
1156
|
-
constructor(pluggable) {
|
|
1157
|
-
super();
|
|
1158
|
-
this.pluggable = pluggable;
|
|
1159
|
-
}
|
|
1160
|
-
/**
|
|
1161
|
-
* Reloads plugin state on an HMR update. The base implementation is a no-op, override it in your plugin.
|
|
1162
|
-
* @virtual
|
|
1163
|
-
*/
|
|
1164
|
-
onHmr(_event) {
|
|
1165
|
-
return Promise.resolve();
|
|
1166
|
-
}
|
|
1167
|
-
/**
|
|
1168
|
-
* Registers critical file patterns that should trigger a full restart when changed in Dev HMR.
|
|
1169
|
-
* @param patterns - Glob patterns relative to the project root
|
|
1170
|
-
*/
|
|
1171
|
-
registerCriticalFiles(patterns) {
|
|
1172
|
-
(0, _seedcord_core_internal.getDevChannel)()?.send("seedcord:register-critical-files", { patterns });
|
|
1173
|
-
}
|
|
1174
|
-
/** @internal */
|
|
1175
|
-
removeListener(event, listener) {
|
|
1176
|
-
return super.removeListener(event, listener);
|
|
1177
|
-
}
|
|
1178
|
-
/** @internal */
|
|
1179
|
-
removeAllListeners(event) {
|
|
1180
|
-
return super.removeAllListeners(event);
|
|
1181
|
-
}
|
|
1182
|
-
};
|
|
1183
|
-
/**
|
|
1184
|
-
* Base class for objects that can have plugins attached.
|
|
1185
|
-
*
|
|
1186
|
-
* Provides plugin attachment capabilities and lifecycle management. Plugins are attached during
|
|
1187
|
-
* configuration and initialized during startup. Not constructed directly, the host is a {@link Seedcord}.
|
|
1188
|
-
*/
|
|
1189
|
-
var Pluggable = class Pluggable extends _seedcord_event_emitter.TypedEventEmitter {
|
|
1190
|
-
isInitialized = false;
|
|
1191
|
-
shutdown;
|
|
1192
|
-
startup;
|
|
1193
|
-
plugins = [];
|
|
1194
|
-
static PLUGIN_INIT_TIMEOUT_MS = 15e3;
|
|
1195
|
-
constructor(shutdown, startup) {
|
|
1196
|
-
super();
|
|
1197
|
-
this.shutdown = shutdown;
|
|
1198
|
-
this.startup = startup;
|
|
1199
|
-
}
|
|
1200
|
-
/** @internal */
|
|
1201
|
-
async init() {
|
|
1202
|
-
if (this.isInitialized) return this;
|
|
1203
|
-
await this.startup.run();
|
|
1204
|
-
this.isInitialized = true;
|
|
1205
|
-
return this;
|
|
1206
|
-
}
|
|
1207
|
-
/**
|
|
1208
|
-
* Attaches a plugin to this instance
|
|
1209
|
-
*
|
|
1210
|
-
* Plugins provide external functionality and are initialized during the specified startup phase.
|
|
1211
|
-
* The plugin instance becomes available as a property in `core` wherever it's available.
|
|
1212
|
-
*
|
|
1213
|
-
* Make sure to augment the {@link Core} interface with the plugin type to ensure TypeScript recognizes it and provides intellisense.
|
|
1214
|
-
*
|
|
1215
|
-
* @typeParam Key - The property name for accessing the plugin
|
|
1216
|
-
* @typeParam Ctor - The plugin constructor type
|
|
1217
|
-
* @param key - Property name to access the plugin instance
|
|
1218
|
-
* @param Plugin - Plugin constructor class
|
|
1219
|
-
* @param startupPhase - When during startup to initialize this plugin ({@link StartupPhase})
|
|
1220
|
-
* @param args - Additional arguments to pass to the plugin constructor
|
|
1221
|
-
* @returns This instance with the plugin attached as a typed property
|
|
1222
|
-
* @throws A **SeedcordError** When called after initialization or if key already exists
|
|
1223
|
-
* @example
|
|
1224
|
-
* ```typescript
|
|
1225
|
-
* seedcord.attach('db', Mongo, StartupPhase.Configuration, { uri: 'mongodb://...', name: 'seedcord', dir: ... })
|
|
1226
|
-
* ```
|
|
1227
|
-
*/
|
|
1228
|
-
attach(key, Plugin, startupPhase, ...args) {
|
|
1229
|
-
if (this.isInitialized) throw new _seedcord_errors_internal.SeedcordError(_seedcord_errors.SeedcordErrorCode.CorePluginAfterInit);
|
|
1230
|
-
if (key in this) throw new _seedcord_errors_internal.SeedcordError(_seedcord_errors.SeedcordErrorCode.CorePluginKeyExists, [key]);
|
|
1231
|
-
const instance = new Plugin(this, ...args);
|
|
1232
|
-
this.plugins.push(instance);
|
|
1233
|
-
const entry = { [key]: instance };
|
|
1234
|
-
this.startup.addTask(startupPhase, `Plugin:${key}`, async () => {
|
|
1235
|
-
instance.logger.utils.initialization(key, "start");
|
|
1236
|
-
await instance.init();
|
|
1237
|
-
instance.logger.utils.initialization(key, "end");
|
|
1238
|
-
}, Pluggable.PLUGIN_INIT_TIMEOUT_MS);
|
|
1239
|
-
return Object.assign(this, entry);
|
|
1240
|
-
}
|
|
1241
|
-
/** @internal */
|
|
1242
|
-
removeListener(event, listener) {
|
|
1243
|
-
return super.removeListener(event, listener);
|
|
1244
|
-
}
|
|
1245
|
-
/** @internal */
|
|
1246
|
-
removeAllListeners(event) {
|
|
1247
|
-
return super.removeAllListeners(event);
|
|
1248
|
-
}
|
|
1249
|
-
};
|
|
1250
|
-
|
|
1251
1145
|
//#endregion
|
|
1252
1146
|
//#region src/handlers/BaseHandler.ts
|
|
1253
1147
|
/**
|
|
@@ -2293,7 +2187,6 @@ function slashRouteLeaves(commands) {
|
|
|
2293
2187
|
var CommandRegistry = class {
|
|
2294
2188
|
core;
|
|
2295
2189
|
onDeployed;
|
|
2296
|
-
name = "Commands";
|
|
2297
2190
|
logger = new _seedcord_logger.Logger("Commands");
|
|
2298
2191
|
isInitialised = false;
|
|
2299
2192
|
globalCommands = [];
|
|
@@ -2589,11 +2482,12 @@ var EventDispatcher = class {
|
|
|
2589
2482
|
core;
|
|
2590
2483
|
logger = new _seedcord_logger.Logger("Events");
|
|
2591
2484
|
isInitialized = false;
|
|
2592
|
-
name = "Events";
|
|
2593
2485
|
eventMap = /* @__PURE__ */ new Map();
|
|
2594
2486
|
middlewares = [];
|
|
2595
2487
|
executedOnceHandlers = /* @__PURE__ */ new Set();
|
|
2596
2488
|
attachedEvents = /* @__PURE__ */ new Set();
|
|
2489
|
+
inFlight = /* @__PURE__ */ new Set();
|
|
2490
|
+
draining = false;
|
|
2597
2491
|
loading = false;
|
|
2598
2492
|
loadedHandlers = [];
|
|
2599
2493
|
loadedMiddlewares = [];
|
|
@@ -2762,15 +2656,22 @@ var EventDispatcher = class {
|
|
|
2762
2656
|
const handlerEntries = this.eventMap.get(eventName);
|
|
2763
2657
|
this.logger.debug(`Attaching ${_seedcord_logger.paint.mint.bold(eventName)} to the client with ${_seedcord_logger.paint.mute(handlerEntries?.length ?? 0)} handler(s)`);
|
|
2764
2658
|
this.core.bot.client.on(eventName, (...args) => {
|
|
2659
|
+
if (this.draining) return;
|
|
2765
2660
|
this.core.bot.emitSafe("any:event", eventName, ...args);
|
|
2766
|
-
(
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2661
|
+
const run = this.processEvent(eventName, args).catch((err) => {
|
|
2662
|
+
this.logger.error(`[${_seedcord_logger.paint.coral.bold("UNHANDLED ERROR AT ROOT")}] ${err.name}`, err.stack);
|
|
2663
|
+
this.core.bot.emit("error:unhandled:event", err);
|
|
2664
|
+
});
|
|
2665
|
+
this.inFlight.add(run);
|
|
2666
|
+
run.finally(() => this.inFlight.delete(run));
|
|
2772
2667
|
});
|
|
2773
2668
|
}
|
|
2669
|
+
stopAccepting() {
|
|
2670
|
+
this.draining = true;
|
|
2671
|
+
}
|
|
2672
|
+
drain(timeoutMs) {
|
|
2673
|
+
return (0, _seedcord_core_node_internal.settleWithin)(Promise.allSettled(this.inFlight), timeoutMs);
|
|
2674
|
+
}
|
|
2774
2675
|
async processEvent(eventName, args) {
|
|
2775
2676
|
const handlerEntries = this.eventMap.get(eventName);
|
|
2776
2677
|
if (!handlerEntries || handlerEntries.length === 0) return;
|
|
@@ -2896,7 +2797,6 @@ var InteractionDispatcher = class {
|
|
|
2896
2797
|
core;
|
|
2897
2798
|
logger = new _seedcord_logger.Logger("Interactions");
|
|
2898
2799
|
isInitialized = false;
|
|
2899
|
-
name = "Interactions";
|
|
2900
2800
|
slashMap = /* @__PURE__ */ new Map();
|
|
2901
2801
|
buttonMap = /* @__PURE__ */ new Map();
|
|
2902
2802
|
modalMap = /* @__PURE__ */ new Map();
|
|
@@ -2910,6 +2810,8 @@ var InteractionDispatcher = class {
|
|
|
2910
2810
|
autocompleteMap = /* @__PURE__ */ new Map();
|
|
2911
2811
|
keysToIgnore = /* @__PURE__ */ new Set();
|
|
2912
2812
|
middlewares = [];
|
|
2813
|
+
inFlight = /* @__PURE__ */ new Set();
|
|
2814
|
+
draining = false;
|
|
2913
2815
|
loading = false;
|
|
2914
2816
|
loadedHandlers = [];
|
|
2915
2817
|
loadedMiddlewares = [];
|
|
@@ -3110,13 +3012,22 @@ var InteractionDispatcher = class {
|
|
|
3110
3012
|
}
|
|
3111
3013
|
attachToClient() {
|
|
3112
3014
|
this.core.bot.client.on(discord_js.Events.InteractionCreate, (interaction) => {
|
|
3015
|
+
if (this.draining) return;
|
|
3113
3016
|
this.core.bot.emitSafe("any:interaction", interaction);
|
|
3114
|
-
this.handleInteraction(interaction).catch((err) => {
|
|
3017
|
+
const run = this.handleInteraction(interaction).catch((err) => {
|
|
3115
3018
|
this.logger.error(`[${_seedcord_logger.paint.coral.bold("UNHANDLED ERROR AT ROOT")}] ${err.name}`, err.stack);
|
|
3116
3019
|
this.core.bot.emit("error:unhandled:interaction", err);
|
|
3117
3020
|
});
|
|
3021
|
+
this.inFlight.add(run);
|
|
3022
|
+
run.finally(() => this.inFlight.delete(run));
|
|
3118
3023
|
});
|
|
3119
3024
|
}
|
|
3025
|
+
stopAccepting() {
|
|
3026
|
+
this.draining = true;
|
|
3027
|
+
}
|
|
3028
|
+
drain(timeoutMs) {
|
|
3029
|
+
return (0, _seedcord_core_node_internal.settleWithin)(Promise.allSettled(this.inFlight), timeoutMs);
|
|
3030
|
+
}
|
|
3120
3031
|
async handleCustomIdInteraction(interaction, getMap, interactionType) {
|
|
3121
3032
|
if ([...this.keysToIgnore].some((matcher) => matcher.owns(interaction.customId))) return;
|
|
3122
3033
|
const prefix = (0, _seedcord_core_internal.prefixOf)(interaction.customId);
|
|
@@ -3244,23 +3155,25 @@ function __decorate(decorators, target, key, desc) {
|
|
|
3244
3155
|
|
|
3245
3156
|
//#endregion
|
|
3246
3157
|
//#region src/bot/Bot.ts
|
|
3158
|
+
const DISPATCH_DRAIN_TIMEOUT_MS = 5e3;
|
|
3159
|
+
const DRAIN_TASK_TIMEOUT_MS = 6e3;
|
|
3160
|
+
const UNBIND_TIMEOUT_MS = 2e3;
|
|
3161
|
+
const LOGOUT_TIMEOUT_MS = 2e3;
|
|
3247
3162
|
/**
|
|
3248
|
-
* Discord
|
|
3249
|
-
*
|
|
3250
|
-
* Don't instantiate this class directly. Use `core.bot` instead.
|
|
3163
|
+
* The Discord client and its controllers. Access it through `core.bot`.
|
|
3251
3164
|
*/
|
|
3252
|
-
var Bot = class extends
|
|
3165
|
+
var Bot = class extends _seedcord_event_emitter.TypedEventEmitter {
|
|
3253
3166
|
/** @internal */
|
|
3254
3167
|
logger = new _seedcord_logger.Logger("Bot");
|
|
3255
3168
|
isInitialized = false;
|
|
3256
3169
|
_client;
|
|
3257
3170
|
interactions;
|
|
3258
3171
|
events;
|
|
3259
|
-
commands;
|
|
3260
3172
|
emojiInjector;
|
|
3173
|
+
commands;
|
|
3261
3174
|
emojis = Emojis;
|
|
3262
3175
|
mentions = CommandMentions;
|
|
3263
|
-
/** @internal
|
|
3176
|
+
/** @internal */
|
|
3264
3177
|
async onHmr(event) {
|
|
3265
3178
|
if (this.interactions) await this.interactions.onHmr(event);
|
|
3266
3179
|
if (this.events) await this.events.onHmr(event);
|
|
@@ -3268,7 +3181,7 @@ var Bot = class extends Plugin {
|
|
|
3268
3181
|
}
|
|
3269
3182
|
/** @internal */
|
|
3270
3183
|
constructor(core) {
|
|
3271
|
-
super(
|
|
3184
|
+
super();
|
|
3272
3185
|
this._client = new discord_js.Client(core.config.bot.clientOptions);
|
|
3273
3186
|
if (core.config.bot.interactions.path) this.interactions = new InteractionDispatcher(core);
|
|
3274
3187
|
if (core.config.bot.events.path) this.events = new EventDispatcher(core);
|
|
@@ -3279,12 +3192,24 @@ var Bot = class extends Plugin {
|
|
|
3279
3192
|
});
|
|
3280
3193
|
}
|
|
3281
3194
|
this.emojiInjector = new EmojiInjector(core);
|
|
3282
|
-
|
|
3195
|
+
this.registerShutdownTasks(core);
|
|
3283
3196
|
}
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3197
|
+
registerShutdownTasks(core) {
|
|
3198
|
+
core.shutdown.addTask(_seedcord_core_node_internal.ShutdownPhase.Unbind, "stop-dispatch", () => {
|
|
3199
|
+
this.stopAccepting();
|
|
3200
|
+
return Promise.resolve();
|
|
3201
|
+
}, UNBIND_TIMEOUT_MS);
|
|
3202
|
+
core.shutdown.addTask(_seedcord_core_node_internal.ShutdownPhase.Drain, "drain-dispatch", () => this.drain(), DRAIN_TASK_TIMEOUT_MS);
|
|
3203
|
+
core.shutdown.addTask(_seedcord_core_node_internal.ShutdownPhase.Logout, "stop-bot", async () => await this.stop(), LOGOUT_TIMEOUT_MS);
|
|
3204
|
+
}
|
|
3205
|
+
stopAccepting() {
|
|
3206
|
+
this.interactions?.stopAccepting();
|
|
3207
|
+
this.events?.stopAccepting();
|
|
3208
|
+
}
|
|
3209
|
+
async drain() {
|
|
3210
|
+
await Promise.allSettled([this.interactions?.drain(DISPATCH_DRAIN_TIMEOUT_MS), this.events?.drain(DISPATCH_DRAIN_TIMEOUT_MS)]);
|
|
3211
|
+
}
|
|
3212
|
+
/** @internal */
|
|
3288
3213
|
async init() {
|
|
3289
3214
|
if (this.isInitialized) return;
|
|
3290
3215
|
this.isInitialized = true;
|
|
@@ -3300,17 +3225,11 @@ var Bot = class extends Plugin {
|
|
|
3300
3225
|
this.interactions?.warnUnhandledContextMenuRoutes(this.commands.contextMenuLeaves());
|
|
3301
3226
|
}
|
|
3302
3227
|
}
|
|
3303
|
-
/**
|
|
3304
|
-
* Stops the bot and cleans up connections
|
|
3305
|
-
* @internal
|
|
3306
|
-
*/
|
|
3228
|
+
/** @internal */
|
|
3307
3229
|
async stop() {
|
|
3308
3230
|
this._client.removeAllListeners();
|
|
3309
3231
|
await this.logout();
|
|
3310
3232
|
}
|
|
3311
|
-
/**
|
|
3312
|
-
* Logs the bot into Discord using the configured token
|
|
3313
|
-
*/
|
|
3314
3233
|
async login(token) {
|
|
3315
3234
|
this._client.once(discord_js.Events.ClientReady, () => this.emit("ready"));
|
|
3316
3235
|
this._client.login(token);
|
|
@@ -3318,9 +3237,6 @@ var Bot = class extends Plugin {
|
|
|
3318
3237
|
this.logger.info(`Logged in as ${chalk.default.bold.magenta(this._client.user?.username)}!`);
|
|
3319
3238
|
return this;
|
|
3320
3239
|
}
|
|
3321
|
-
/**
|
|
3322
|
-
* Logs out and destroys the Discord client connection
|
|
3323
|
-
*/
|
|
3324
3240
|
async logout() {
|
|
3325
3241
|
await this._client.destroy();
|
|
3326
3242
|
this.logger.info(chalk.default.bold.red("Logged out of Discord!"));
|
|
@@ -3328,6 +3244,12 @@ var Bot = class extends Plugin {
|
|
|
3328
3244
|
get client() {
|
|
3329
3245
|
return this._client;
|
|
3330
3246
|
}
|
|
3247
|
+
/**
|
|
3248
|
+
* The overloads enforce the key/args correlation at compile time only. At runtime this forwards
|
|
3249
|
+
* straight to the underlying TypedEventEmitter.
|
|
3250
|
+
*
|
|
3251
|
+
* @internal
|
|
3252
|
+
*/
|
|
3331
3253
|
emit(event, ...args) {
|
|
3332
3254
|
return super.emit(event, ...args);
|
|
3333
3255
|
}
|
|
@@ -3421,18 +3343,16 @@ var UnhandledErrorContainer = class extends _seedcord_core.BuilderComponent {
|
|
|
3421
3343
|
* Registers and dispatches subscribers. Subscribers load from the configured directories and run
|
|
3422
3344
|
* on a programmatic or framework-event publish. Accessed via `core.bus`. Do not construct it directly.
|
|
3423
3345
|
*/
|
|
3424
|
-
var Bus = class extends
|
|
3346
|
+
var Bus = class extends _seedcord_event_emitter.TypedEventEmitter {
|
|
3425
3347
|
core;
|
|
3426
3348
|
logger = new _seedcord_logger.Logger("Subscribers");
|
|
3427
|
-
/** @internal */
|
|
3428
|
-
name = "Subscribers";
|
|
3429
3349
|
isInitialized = false;
|
|
3430
3350
|
subscribersMap = /* @__PURE__ */ new Map();
|
|
3431
3351
|
executedOnceHandlers = /* @__PURE__ */ new Set();
|
|
3432
3352
|
webhookProbes = /* @__PURE__ */ new Map();
|
|
3433
3353
|
hmrHandler;
|
|
3434
3354
|
constructor(core) {
|
|
3435
|
-
super(
|
|
3355
|
+
super();
|
|
3436
3356
|
this.core = core;
|
|
3437
3357
|
if (this.core.config.subscribers.path) {
|
|
3438
3358
|
if (!envapt.Envapter.isDevelopment && !envapt.Envapter.isTest) return;
|
|
@@ -3561,17 +3481,15 @@ var Bus = class extends Plugin {
|
|
|
3561
3481
|
//#endregion
|
|
3562
3482
|
//#region src/version.ts
|
|
3563
3483
|
/** Package version */
|
|
3564
|
-
const version = "0.1.0-next.
|
|
3484
|
+
const version = "0.1.0-next.4";
|
|
3565
3485
|
|
|
3566
3486
|
//#endregion
|
|
3567
3487
|
//#region src/Seedcord.ts
|
|
3568
3488
|
/**
|
|
3569
|
-
*
|
|
3570
|
-
*
|
|
3571
|
-
* Primary entry point for creating Discord bots with Seedcord.
|
|
3572
|
-
* Manages component lifecycle and provides plugin support.
|
|
3489
|
+
* The gateway bot host. Opens a discord.js gateway session, discovers handlers, and runs
|
|
3490
|
+
* coordinated startup and shutdown. Attach plugins with `attach()`.
|
|
3573
3491
|
*/
|
|
3574
|
-
var Seedcord = class Seedcord extends Pluggable {
|
|
3492
|
+
var Seedcord = class Seedcord extends _seedcord_core_node_internal.Pluggable {
|
|
3575
3493
|
config;
|
|
3576
3494
|
/** @internal */
|
|
3577
3495
|
[_seedcord_types_internal.SeedcordBrand] = true;
|
|
@@ -3579,7 +3497,6 @@ var Seedcord = class Seedcord extends Pluggable {
|
|
|
3579
3497
|
augmentTarget = "@seedcord/gateway";
|
|
3580
3498
|
/** @internal */
|
|
3581
3499
|
version = version;
|
|
3582
|
-
static isInstantiated = false;
|
|
3583
3500
|
healthCheck;
|
|
3584
3501
|
hmrManager;
|
|
3585
3502
|
/** @see {@link CoordinatedShutdown} */
|
|
@@ -3593,16 +3510,12 @@ var Seedcord = class Seedcord extends Pluggable {
|
|
|
3593
3510
|
/** @see {@link IRateLimiter} */
|
|
3594
3511
|
rateLimiter;
|
|
3595
3512
|
/**
|
|
3596
|
-
* Creates a new Seedcord instance
|
|
3597
|
-
*
|
|
3598
3513
|
* @param config - Bot configuration including paths and Discord client options
|
|
3599
3514
|
* @throws A **SeedcordError** When attempting to create multiple instances (singleton)
|
|
3600
3515
|
*/
|
|
3601
3516
|
constructor(config) {
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
const shutdown = new _seedcord_core_node.CoordinatedShutdown(config.shutdownEnabled);
|
|
3605
|
-
const startup = new _seedcord_core_node.CoordinatedStartup();
|
|
3517
|
+
const shutdown = new _seedcord_core_node_internal.CoordinatedShutdown();
|
|
3518
|
+
const startup = new _seedcord_core_node_internal.CoordinatedStartup();
|
|
3606
3519
|
super(shutdown, startup);
|
|
3607
3520
|
this.config = config;
|
|
3608
3521
|
(0, _seedcord_logger_node.installNodeDefaults)(config.logger);
|
|
@@ -3614,46 +3527,60 @@ var Seedcord = class Seedcord extends Pluggable {
|
|
|
3614
3527
|
this.bus = new Bus(this);
|
|
3615
3528
|
this.bot = new Bot(this);
|
|
3616
3529
|
this.rateLimiter = config.store ?? new _seedcord_rate_limiter.MemoryRateLimiter();
|
|
3617
|
-
this.healthCheck =
|
|
3530
|
+
this.healthCheck = _seedcord_core_node_internal.HealthCheck.fromOption(this.shutdown, config.healthCheck);
|
|
3618
3531
|
this.registerStartupTasks();
|
|
3619
3532
|
}
|
|
3620
3533
|
/** The bot's discord username, populated after login. */
|
|
3621
3534
|
get username() {
|
|
3622
3535
|
return this.bot.client.user?.username;
|
|
3623
3536
|
}
|
|
3537
|
+
pluginCapabilities() {
|
|
3538
|
+
return {
|
|
3539
|
+
client: this.bot.client,
|
|
3540
|
+
token: this.bot.botToken,
|
|
3541
|
+
rest: this.bot.client.rest
|
|
3542
|
+
};
|
|
3543
|
+
}
|
|
3624
3544
|
static reset() {
|
|
3625
|
-
|
|
3545
|
+
super.reset();
|
|
3626
3546
|
_seedcord_logger.LoggerChannelRegistry.instance.reset();
|
|
3627
3547
|
}
|
|
3628
3548
|
registerStartupTasks() {
|
|
3629
3549
|
if (envapt.Envapter.isDevelopment || envapt.Envapter.isTest) this.registerHmrAwareModules();
|
|
3630
|
-
this.startup.addTask(
|
|
3550
|
+
this.startup.addTask(_seedcord_core_node_internal.StartupPhase.Configuration, "Bus Initialization", async () => {
|
|
3631
3551
|
this.bus.logger.utils.initialization("Subscribers", "start");
|
|
3632
3552
|
await this.bus.init();
|
|
3633
3553
|
this.bus.logger.utils.initialization("Subscribers", "end");
|
|
3634
3554
|
});
|
|
3635
|
-
this.startup.addTask(
|
|
3555
|
+
this.startup.addTask(_seedcord_core_node_internal.StartupPhase.Login, "Bot Initialization", async () => {
|
|
3636
3556
|
this.bot.logger.utils.initialization("Bot", "start");
|
|
3637
3557
|
await this.bot.init();
|
|
3638
3558
|
this.bot.logger.utils.initialization("Bot", "end");
|
|
3639
3559
|
});
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3560
|
+
const { healthCheck } = this;
|
|
3561
|
+
if (healthCheck) this.startup.addTask(_seedcord_core_node_internal.StartupPhase.Ready, "Health Check", async () => {
|
|
3562
|
+
healthCheck.logger.utils.initialization("HealthCheck", "start");
|
|
3563
|
+
await healthCheck.init();
|
|
3564
|
+
healthCheck.logger.utils.initialization("HealthCheck", "end");
|
|
3644
3565
|
});
|
|
3645
3566
|
}
|
|
3646
3567
|
/**
|
|
3647
3568
|
* Starts the bot and runs all initialization tasks
|
|
3648
3569
|
*
|
|
3649
|
-
* @returns This Seedcord instance when
|
|
3570
|
+
* @returns This Seedcord instance when initialized
|
|
3650
3571
|
*/
|
|
3651
3572
|
async start() {
|
|
3652
|
-
|
|
3573
|
+
try {
|
|
3574
|
+
await super.init();
|
|
3575
|
+
} catch (caught) {
|
|
3576
|
+
await this.shutdown.run(1, false);
|
|
3577
|
+
Seedcord.reset();
|
|
3578
|
+
throw caught;
|
|
3579
|
+
}
|
|
3653
3580
|
return this;
|
|
3654
3581
|
}
|
|
3655
3582
|
registerHmrAwareModules() {
|
|
3656
|
-
this.startup.addTask(
|
|
3583
|
+
this.startup.addTask(_seedcord_core_node_internal.StartupPhase.Configuration, "HMR Registration", async () => {
|
|
3657
3584
|
this.hmrManager.register(this.bot);
|
|
3658
3585
|
this.hmrManager.register(this.bus);
|
|
3659
3586
|
for (const plugin of this.plugins) this.hmrManager.register(plugin);
|
|
@@ -3681,25 +3608,11 @@ exports.MiddlewareType = MiddlewareType;
|
|
|
3681
3608
|
exports.ModalHandler = ModalHandler;
|
|
3682
3609
|
exports.Nsfw = Nsfw;
|
|
3683
3610
|
exports.Paginator = Paginator;
|
|
3684
|
-
exports.Pluggable = Pluggable;
|
|
3685
|
-
exports.Plugin = Plugin;
|
|
3686
3611
|
exports.RegisterEvent = RegisterEvent;
|
|
3687
3612
|
exports.RepliableHandler = RepliableHandler;
|
|
3688
3613
|
exports.Seedcord = Seedcord;
|
|
3689
3614
|
exports.SelectMenuHandler = SelectMenuHandler;
|
|
3690
|
-
Object.defineProperty(exports, 'ShutdownPhase', {
|
|
3691
|
-
enumerable: true,
|
|
3692
|
-
get: function () {
|
|
3693
|
-
return _seedcord_core_node.ShutdownPhase;
|
|
3694
|
-
}
|
|
3695
|
-
});
|
|
3696
3615
|
exports.SlashHandler = SlashHandler;
|
|
3697
|
-
Object.defineProperty(exports, 'StartupPhase', {
|
|
3698
|
-
enumerable: true,
|
|
3699
|
-
get: function () {
|
|
3700
|
-
return _seedcord_core_node.StartupPhase;
|
|
3701
|
-
}
|
|
3702
|
-
});
|
|
3703
3616
|
exports.Subscribe = Subscribe;
|
|
3704
3617
|
exports.Subscriber = Subscriber;
|
|
3705
3618
|
exports.WebhookLog = WebhookLog;
|