@seedcord/gateway 0.1.0-next.6 → 0.1.1-next.0
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 +43 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +52 -28
- package/dist/index.mjs +43 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
1
2
|
import { AnyCustomId, AutocompletableNames, BaseReplySender, ChoiceValueOf, EntryFor, FocusedField, GateFitsWith, HasComponentDefs, MatchArms, ModalLike, PageCursor, SingleParams, SlashOptions as SlashOptions$1 } from "@seedcord/core/internal";
|
|
2
3
|
import { ArraySource as ArraySource$1, AutocompleteOptions, BaseHandler, Bus, ContextMenuKind, CoreBase, CursorSource as CursorSource$1, DispatchContext, Gate, GateContextBase, GateNoticeOptions, GuildPermissionsContext, Initializeable, Notice, PaginatorBase, PaginatorConfig, PermissionNoticeOverrides, PermissionScope, RepliableHandler as RepliableHandler$1, RequiredOf, SelectMenuKind, SlashOptionRegistry, Subscriber as Subscriber$1, SubscriptionKey, WebhookLog as WebhookLog$1 } from "@seedcord/core";
|
|
3
4
|
import { Logger } from "@seedcord/logger";
|
|
4
|
-
import { APIInteractionGuildMember, APIModalInteractionResponseCallbackData, AnySelectMenuInteraction, ApplicationCommandOptionChoiceData, ApplicationCommandType, ApplicationEmoji, AutocompleteInteraction, BooleanCache, ButtonInteraction, ButtonStyle, CacheType, CacheTypeReducer, ChannelSelectMenuInteraction, ChatInputCommandInteraction, Client, ClientEvents, ClientOptions, CommandInteractionOption, ContextMenuCommandInteraction, Events, Guild, GuildEmoji, GuildMember, Interaction, MentionableSelectMenuInteraction, Message, MessageContextMenuCommandInteraction, ModalSubmitInteraction, Role, RoleSelectMenuInteraction, StringSelectMenuInteraction, TextChannel, User, UserContextMenuCommandInteraction, UserSelectMenuInteraction } from "discord.js";
|
|
5
|
+
import { APIInteractionGuildMember, APIModalInteractionResponseCallbackData, AnySelectMenuInteraction, ApplicationCommandOptionChoiceData, ApplicationCommandType, ApplicationEmoji, AutocompleteInteraction, BaseMessageOptions, BooleanCache, ButtonInteraction, ButtonStyle, CacheType, CacheTypeReducer, ChannelSelectMenuInteraction, ChatInputCommandInteraction, Client, ClientEvents, ClientOptions, CommandInteractionOption, ContextMenuCommandInteraction, Events, Guild, GuildEmoji, GuildMember, Interaction, MentionableSelectMenuInteraction, Message, MessageContextMenuCommandInteraction, ModalSubmitInteraction, Role, RoleSelectMenuInteraction, StringSelectMenuInteraction, TextChannel, User, UserContextMenuCommandInteraction, UserSelectMenuInteraction } from "discord.js";
|
|
5
6
|
import { Plugin as Plugin$1, PluginLifecycleSpec, PluginOptions, PluginOptions as PluginOptions$1 } from "@seedcord/core/plugin";
|
|
6
7
|
import { CoordinatedShutdown, CoordinatedStartup, Pluggable } from "@seedcord/core/node/internal";
|
|
7
8
|
import { SeedcordBrand, SeedcordInstance } from "@seedcord/types/internal";
|
|
@@ -14,7 +15,6 @@ export * from "@seedcord/rate-limiter";
|
|
|
14
15
|
export * from "@seedcord/utils";
|
|
15
16
|
export * from "@seedcord/event-emitter";
|
|
16
17
|
export type * from "@seedcord/types";
|
|
17
|
-
|
|
18
18
|
//#region src/subscriptions.d.ts
|
|
19
19
|
declare module '@seedcord/core/internal' {
|
|
20
20
|
interface DefaultSubscriptions {
|
|
@@ -26,7 +26,7 @@ declare module '@seedcord/core/internal' {
|
|
|
26
26
|
anyEvent: { [Name in keyof ClientEvents]: {
|
|
27
27
|
name: Name;
|
|
28
28
|
args: ClientEvents[Name];
|
|
29
|
-
} }[keyof ClientEvents];
|
|
29
|
+
}; }[keyof ClientEvents];
|
|
30
30
|
/** Triggered for every interaction the bot receives, before routing. */
|
|
31
31
|
anyInteraction: {
|
|
32
32
|
interaction: Interaction;
|
|
@@ -48,7 +48,8 @@ type EventsConfig = {
|
|
|
48
48
|
*/
|
|
49
49
|
middlewares?: string;
|
|
50
50
|
} | {
|
|
51
|
-
/** No events configured */
|
|
51
|
+
/** No events configured */
|
|
52
|
+
path: null;
|
|
52
53
|
};
|
|
53
54
|
/**
|
|
54
55
|
* The gateway transport's bot configuration, the shared {@link BotConfig} plus the pieces only a
|
|
@@ -131,6 +132,28 @@ interface Core extends CoreBase {
|
|
|
131
132
|
readonly config: GatewayConfig;
|
|
132
133
|
}
|
|
133
134
|
//#endregion
|
|
135
|
+
//#region src/interfaces/ReplyResponse.d.ts
|
|
136
|
+
/**
|
|
137
|
+
* Every file form discord.js accepts in a message's `files` field: `AttachmentBuilder`, `Attachment`, a
|
|
138
|
+
* `Buffer`, a node `Stream`, a path or URL string, and an `{ attachment, name }` payload.
|
|
139
|
+
*/
|
|
140
|
+
type GatewayFile = NonNullable<BaseMessageOptions['files']>[number];
|
|
141
|
+
/**
|
|
142
|
+
* A reply that may attach files in any form discord.js accepts, on top of the portable `ReplyFile`. The
|
|
143
|
+
* reply verbs already take this, so name it only to type a variable or a helper's return. A `Notice`
|
|
144
|
+
* render or a paginator page returns the plain `ReplyResponse`, which takes a `ReplyFile` alone.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* // any discord.js file form
|
|
149
|
+
* await this.reply({
|
|
150
|
+
* components: [container],
|
|
151
|
+
* files: [new AttachmentBuilder(createReadStream('./report.pdf'), { name: 'report.pdf' })]
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
type GatewayReplyResponse = ReplyResponse<GatewayFile>;
|
|
156
|
+
//#endregion
|
|
134
157
|
//#region src/handlers/interactionTypes.d.ts
|
|
135
158
|
type ValidInteractionTypes = ChatInputCommandInteraction | ButtonInteraction | ModalSubmitInteraction | AutocompleteInteraction | AnySelectMenuInteraction | ContextMenuCommandInteraction;
|
|
136
159
|
type ValidNonInteractionKeys = Exclude<keyof ClientEvents, Events.InteractionCreate>;
|
|
@@ -148,7 +171,7 @@ declare abstract class BaseHandler$1<ValidEvent extends ValidEventTypes> extends
|
|
|
148
171
|
getEvent(): ValidEvent;
|
|
149
172
|
}
|
|
150
173
|
//#endregion
|
|
151
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
174
|
+
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/basic.d.ts
|
|
152
175
|
/**
|
|
153
176
|
Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
|
154
177
|
|
|
@@ -156,7 +179,7 @@ Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/Jav
|
|
|
156
179
|
*/
|
|
157
180
|
type Constructor<T, Arguments extends unknown[] = any[]> = new (...arguments_: Arguments) => T;
|
|
158
181
|
//#endregion
|
|
159
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
182
|
+
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/is-never.d.ts
|
|
160
183
|
/**
|
|
161
184
|
Returns a boolean for whether the given type is `never`.
|
|
162
185
|
|
|
@@ -212,7 +235,7 @@ type B = IsTrueFixed<never>;
|
|
|
212
235
|
*/
|
|
213
236
|
type IsNever<T> = [T] extends [never] ? true : false;
|
|
214
237
|
//#endregion
|
|
215
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
238
|
+
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/is-equal.d.ts
|
|
216
239
|
/**
|
|
217
240
|
Returns a boolean for whether the two given types are equal.
|
|
218
241
|
|
|
@@ -243,7 +266,7 @@ type IsEqual<A, B> = [A] extends [B] ? [B] extends [A] ? _IsEqual<A, B> : false
|
|
|
243
266
|
// This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
|
|
244
267
|
type _IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
|
|
245
268
|
//#endregion
|
|
246
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
269
|
+
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/non-empty-tuple.d.ts
|
|
247
270
|
/**
|
|
248
271
|
Matches any non-empty tuple.
|
|
249
272
|
|
|
@@ -267,7 +290,7 @@ sum();
|
|
|
267
290
|
*/
|
|
268
291
|
type NonEmptyTuple<T = unknown> = readonly [T, ...T[]];
|
|
269
292
|
//#endregion
|
|
270
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
293
|
+
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/is-union.d.ts
|
|
271
294
|
/**
|
|
272
295
|
Returns a boolean for whether the given type is a union.
|
|
273
296
|
|
|
@@ -286,12 +309,13 @@ type IsUnion<T> = InternalIsUnion<T>;
|
|
|
286
309
|
/**
|
|
287
310
|
The actual implementation of `IsUnion`.
|
|
288
311
|
*/
|
|
289
|
-
type InternalIsUnion<T, U = T> = (IsNever<T> extends true ? false : T extends any ? IsEqual<U, T> extends true ? false : true : never) extends infer Result
|
|
312
|
+
type InternalIsUnion<T, U = T> = (IsNever<T> extends true ? false : T extends any ? IsEqual<U, T> extends true ? false : true : never) extends (infer Result) ?
|
|
313
|
+
// In some cases `Result` will return `false | true` which is `boolean`,
|
|
290
314
|
// that means `T` has at least two types and it's a union type,
|
|
291
315
|
// so we will return `true` instead of `boolean`.
|
|
292
|
-
|
|
316
|
+
boolean extends Result ? true : Result : never; // Should never happen
|
|
293
317
|
//#endregion
|
|
294
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
318
|
+
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/promisable.d.ts
|
|
295
319
|
/**
|
|
296
320
|
Create a type that represents either the value or the value wrapped in `PromiseLike`.
|
|
297
321
|
|
|
@@ -323,7 +347,7 @@ type Promisable<T> = T | PromiseLike<T>;
|
|
|
323
347
|
type SingleEventPayload<Names extends ValidNonInteractionKeys> = IsUnion<Names> extends true ? never : ClientEvents[Names];
|
|
324
348
|
//#endregion
|
|
325
349
|
//#region src/handlers/event/EventHandler.d.ts
|
|
326
|
-
type EventMatchArms<Names extends ValidNonInteractionKeys, Ret> = { [Name in Names]: (...args: ClientEvents[Name]) => Promisable<Ret
|
|
350
|
+
type EventMatchArms<Names extends ValidNonInteractionKeys, Ret> = { [Name in Names]: (...args: ClientEvents[Name]) => Promisable<Ret>; };
|
|
327
351
|
/**
|
|
328
352
|
* Base class for a Discord client event handler.
|
|
329
353
|
*
|
|
@@ -550,16 +574,16 @@ type SentMessage = Message;
|
|
|
550
574
|
* Writes interaction responses through the discord.js interaction. Construction is internal to the repliable
|
|
551
575
|
* handler bases and the dispatcher.
|
|
552
576
|
*/
|
|
553
|
-
declare class ReplySender extends BaseReplySender<SentMessage> {
|
|
577
|
+
declare class ReplySender extends BaseReplySender<SentMessage, GatewayFile> {
|
|
554
578
|
private readonly interaction;
|
|
555
|
-
constructor(interaction: Repliables, routeId: string, bus
|
|
556
|
-
protected writeReply(response:
|
|
579
|
+
constructor(interaction: Repliables, routeId: string, bus: Bus);
|
|
580
|
+
protected writeReply(response: GatewayReplyResponse | string, opts?: SendOpts): Promise<SentMessage | undefined>;
|
|
557
581
|
protected writeDefer(opts?: DeferOpts): Promise<void>;
|
|
558
582
|
protected writeDeferUpdate(): Promise<void>;
|
|
559
|
-
protected writeUpdate(response:
|
|
560
|
-
protected writeFollowUp(response:
|
|
561
|
-
protected writeEditOriginal(response:
|
|
562
|
-
protected writeEditTarget(targetId: string, response:
|
|
583
|
+
protected writeUpdate(response: GatewayReplyResponse | string): Promise<SentMessage | undefined>;
|
|
584
|
+
protected writeFollowUp(response: GatewayReplyResponse | string, opts?: SendOpts): Promise<SentMessage>;
|
|
585
|
+
protected writeEditOriginal(response: GatewayReplyResponse | string): Promise<SentMessage>;
|
|
586
|
+
protected writeEditTarget(targetId: string, response: GatewayReplyResponse | string): Promise<SentMessage>;
|
|
563
587
|
protected writeDeleteOriginal(): Promise<void>;
|
|
564
588
|
protected writeDeleteTarget(targetId: string): Promise<void>;
|
|
565
589
|
protected writeModal(data: APIModalInteractionResponseCallbackData): Promise<void>;
|
|
@@ -582,7 +606,7 @@ declare class ReplySender extends BaseReplySender<SentMessage> {
|
|
|
582
606
|
*
|
|
583
607
|
* @typeParam Event - The repliable interaction type this handler processes
|
|
584
608
|
*/
|
|
585
|
-
declare abstract class RepliableHandler<Event extends Repliables> extends RepliableHandler$1<Event, Core, SentMessage, ReplySender> {
|
|
609
|
+
declare abstract class RepliableHandler<Event extends Repliables> extends RepliableHandler$1<Event, Core, SentMessage, GatewayFile, ReplySender> {
|
|
586
610
|
/** @internal */
|
|
587
611
|
getEvent(): Event;
|
|
588
612
|
protected buildSender(event: Event, core: Core, routeId: string): ReplySender;
|
|
@@ -618,7 +642,7 @@ interface Ungateable {
|
|
|
618
642
|
}
|
|
619
643
|
type ProvidedContext<TCtor extends AnyHandlerCtor> = InstanceType<TCtor> extends InteractionHandler<infer Repliable> ? InteractionGateContext<Repliable> : InstanceType<TCtor> extends EventHandler<infer Names> ? EventGateContext<Names> : Ungateable;
|
|
620
644
|
type KindName<Ctx> = Ctx extends Ungateable ? 'autocomplete' : Ctx extends InteractionGateContext<infer R> ? R extends ChatInputCommandInteraction ? 'Slash' : R extends MessageContextMenuCommandInteraction ? 'MessageMenu' : R extends UserContextMenuCommandInteraction ? 'UserMenu' : R extends StringSelectMenuInteraction ? 'StringSelect' : R extends UserSelectMenuInteraction ? 'UserSelect' : R extends RoleSelectMenuInteraction ? 'RoleSelect' : R extends ChannelSelectMenuInteraction ? 'ChannelSelect' : R extends MentionableSelectMenuInteraction ? 'MentionableSelect' : R extends ButtonInteraction ? 'Button' : R extends ModalSubmitInteraction ? 'Modal' : 'an interaction' : Ctx extends EventGateContext<infer N> ? `${N & string} event` : 'an agnostic';
|
|
621
|
-
type FitAll<TCtor extends AnyHandlerCtor, Gates extends readonly Gate<GateContextBase>[]> = { [Index in keyof Gates]: GateFitsWith<ProvidedContext<TCtor>, KindName<ProvidedContext<TCtor>>, Gates[Index], KindName<RequiredOf<Gates[Index]
|
|
645
|
+
type FitAll<TCtor extends AnyHandlerCtor, Gates extends readonly Gate<GateContextBase>[]> = { [Index in keyof Gates]: GateFitsWith<ProvidedContext<TCtor>, KindName<ProvidedContext<TCtor>>, Gates[Index], KindName<RequiredOf<Gates[Index]>>>; };
|
|
622
646
|
//#endregion
|
|
623
647
|
//#region src/bot/decorators/Gated.d.ts
|
|
624
648
|
/**
|
|
@@ -691,7 +715,7 @@ interface GatewayLens<Cache extends CacheType> {
|
|
|
691
715
|
type SlashOptions<Route extends keyof SlashOptionRegistry, Cache extends CacheType = 'cached'> = SlashOptions$1<Route, GatewayLens<Cache>>;
|
|
692
716
|
//#endregion
|
|
693
717
|
//#region src/handlers/interaction/SlashHandler.d.ts
|
|
694
|
-
type SlashMatchArms<Route extends keyof SlashOptionRegistry, Cache extends CacheType, Ret> = { [Key in Route]: (options: SlashOptions<Key, Cache>) => Promisable<Ret
|
|
718
|
+
type SlashMatchArms<Route extends keyof SlashOptionRegistry, Cache extends CacheType, Ret> = { [Key in Route]: (options: SlashOptions<Key, Cache>) => Promisable<Ret>; };
|
|
695
719
|
/**
|
|
696
720
|
* Base class for a chat-input (slash) command handler.
|
|
697
721
|
*
|
|
@@ -786,7 +810,7 @@ declare abstract class ContextMenuHandler<Kind extends ContextMenuKind, Cache ex
|
|
|
786
810
|
}
|
|
787
811
|
//#endregion
|
|
788
812
|
//#region src/handlers/interaction/AutocompleteHandler.d.ts
|
|
789
|
-
type FocusedArms<Route extends keyof SlashOptionRegistry, Ret> = { [Name in AutocompletableNames<Route>]: (value: string, respond: (choices: readonly ApplicationCommandOptionChoiceData<ChoiceValueOf<EntryFor<Route, Name>>>[]) => Promise<void>) => Promisable<Ret
|
|
813
|
+
type FocusedArms<Route extends keyof SlashOptionRegistry, Ret> = { [Name in AutocompletableNames<Route>]: (value: string, respond: (choices: readonly ApplicationCommandOptionChoiceData<ChoiceValueOf<EntryFor<Route, Name>>>[]) => Promise<void>) => Promisable<Ret>; };
|
|
790
814
|
/**
|
|
791
815
|
* Base class for a Discord autocomplete handler.
|
|
792
816
|
*
|
|
@@ -872,7 +896,7 @@ declare abstract class ComponentHandler<Event extends ComponentInteraction, Defs
|
|
|
872
896
|
/** @internal */
|
|
873
897
|
readonly __componentDefs?: Defs;
|
|
874
898
|
/** Rewrite the source message this component interaction came from. */
|
|
875
|
-
protected update(response:
|
|
899
|
+
protected update(response: GatewayReplyResponse | string): Promise<SentMessage>;
|
|
876
900
|
/** Acknowledge the component without changing the source message. */
|
|
877
901
|
protected deferUpdate(): Promise<void>;
|
|
878
902
|
private decoded?;
|
|
@@ -971,7 +995,7 @@ declare abstract class ModalHandler<Defs extends readonly AnyCustomId[], Cache e
|
|
|
971
995
|
/** @internal */
|
|
972
996
|
readonly __component?: 'modal';
|
|
973
997
|
/** Rewrite the message this modal was opened from. Throws when a command opened the modal. */
|
|
974
|
-
protected update(response:
|
|
998
|
+
protected update(response: GatewayReplyResponse | string): Promise<SentMessage>;
|
|
975
999
|
/** Acknowledge the submit without changing the source message. Throws when a command opened the modal. */
|
|
976
1000
|
protected deferUpdate(): Promise<void>;
|
|
977
1001
|
private ensureSourceMessage;
|
|
@@ -1098,7 +1122,7 @@ declare function Nsfw(options?: GateNoticeOptions): Gate<InteractionGateContext<
|
|
|
1098
1122
|
* The global {@link Emojis} accessor type. Each key resolves to its precise class, `GuildEmoji` for a `'guild'`
|
|
1099
1123
|
* tag and `ApplicationEmoji` for an `'application'` tag, the tags `seedcord codegen` writes into {@link EmojiMap}.
|
|
1100
1124
|
*/
|
|
1101
|
-
type InjectedEmojiMap = { [K in keyof EmojiMap]: EmojiMap[K] extends 'guild' ? GuildEmoji : ApplicationEmoji };
|
|
1125
|
+
type InjectedEmojiMap = { [K in keyof EmojiMap]: EmojiMap[K] extends 'guild' ? GuildEmoji : ApplicationEmoji; };
|
|
1102
1126
|
/**
|
|
1103
1127
|
* The bot's resolved emojis, keyed by {@link EmojiMap}. Filled by {@link EmojiInjector} during startup.
|
|
1104
1128
|
* A read before that throws.
|
|
@@ -1504,5 +1528,5 @@ declare class Seedcord extends Pluggable<'gateway', 'server'> implements Core, S
|
|
|
1504
1528
|
/** Package version */
|
|
1505
1529
|
declare const version: string;
|
|
1506
1530
|
//#endregion
|
|
1507
|
-
export { ArraySource, AssignRoleNoticeOverrides, AutocompleteHandler, ButtonHandler, type CheckPermissionOptions, type ConfirmOptions, ContextMenuHandler, type Core, CursorSource, type DefaultConfirmOptions, Emojis, type EventGateContext, EventHandler, EventMiddleware, type EventSpec, type EventsConfig, type GateContext, Gated, type GatewayBotConfig, type GatewayConfig, type GatewayPluginOptions, HasPermsToAssignOptions, IgnoreBots, type InjectedEmojiMap, type InteractionGateContext, InteractionHandler, InteractionMiddleware, Middleware, type MiddlewareOptions, MiddlewareType, ModalHandler, Nsfw, type PageContext, Paginator, Plugin, type PluginLifecycleSpec, type PluginOptions, RegisterEvent, type RegisterEventOptions, RepliableHandler, type Repliables, Seedcord, SelectMenuHandler, SlashHandler, type SlashOptions, Subscriber, type ValidEventTypes, type ValidInteractionTypes, type ValidNonInteractionKeys, WebhookLog, checkBotPermissions, checkPermissions, getConfirmation, hasPermsToAssign, version };
|
|
1531
|
+
export { ArraySource, AssignRoleNoticeOverrides, AutocompleteHandler, ButtonHandler, type CheckPermissionOptions, type ConfirmOptions, ContextMenuHandler, type Core, CursorSource, type DefaultConfirmOptions, Emojis, type EventGateContext, EventHandler, EventMiddleware, type EventSpec, type EventsConfig, type GateContext, Gated, type GatewayBotConfig, type GatewayConfig, type GatewayFile, type GatewayPluginOptions, type GatewayReplyResponse, HasPermsToAssignOptions, IgnoreBots, type InjectedEmojiMap, type InteractionGateContext, InteractionHandler, InteractionMiddleware, Middleware, type MiddlewareOptions, MiddlewareType, ModalHandler, Nsfw, type PageContext, Paginator, Plugin, type PluginLifecycleSpec, type PluginOptions, RegisterEvent, type RegisterEventOptions, RepliableHandler, type Repliables, Seedcord, SelectMenuHandler, SlashHandler, type SlashOptions, Subscriber, type ValidEventTypes, type ValidInteractionTypes, type ValidNonInteractionKeys, WebhookLog, checkBotPermissions, checkPermissions, getConfirmation, hasPermsToAssign, version };
|
|
1508
1532
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import { installNodeDefaults } from "@seedcord/logger/node";
|
|
3
|
-
import { BaseReplySender, CommandInjector, EventMetadataKey, FaultThrottle, GateNotice, GatedMetadataKey, HmrManager, InteractionMetadataKey, InteractionRouteKeys, InteractionRoutes, MiddlewareMetadataKey, MissingPermissions, NoticeCard, PermissionNames, PublishDefault, accessorStore, areRoutes, asError, clearStore, decodeComponentRoute, deferFlags,
|
|
3
|
+
import { BaseReplySender, CommandInjector, EventMetadataKey, FaultThrottle, GateNotice, GatedMetadataKey, HmrManager, InteractionMetadataKey, InteractionRouteKeys, InteractionRoutes, MiddlewareMetadataKey, MissingPermissions, NoticeCard, PermissionNames, PublishDefault, accessorStore, areRoutes, asError, clearStore, decodeComponentRoute, deferFlags, guardedAccessor, isEmojiTuple, outcomeFor, pickNotice, prefixOf, queuedMsFor, reportDispatch, reportedWrite, routeIdOf, runHandlerGates, sendFlags, setBotColor, slowGateMonitor } from "@seedcord/core/internal";
|
|
4
4
|
import { SeedcordErrorCode } from "@seedcord/errors";
|
|
5
5
|
import { SeedcordError, SeedcordTypeError, validateDiscordToken } from "@seedcord/errors/internal";
|
|
6
6
|
import { ArraySource as ArraySource$1, BaseHandler, BuilderComponent, Bus, CursorSource as CursorSource$1, CustomId, DispatchContext, Fault, Notice, PaginatorBase, RepliableHandler as RepliableHandler$1, RowComponent, Silence, Subscriber as Subscriber$1, WebhookLog as WebhookLog$1, assertPermissions, defineGate } from "@seedcord/core";
|
|
@@ -531,6 +531,18 @@ var InteractionMiddleware = class extends BaseHandler$1 {
|
|
|
531
531
|
|
|
532
532
|
//#endregion
|
|
533
533
|
//#region src/bot/ReplySender.ts
|
|
534
|
+
function isReplyFile(file) {
|
|
535
|
+
return typeof file === "object" && "data" in file && ArrayBuffer.isView(file.data);
|
|
536
|
+
}
|
|
537
|
+
function toDjsFile(file) {
|
|
538
|
+
if (!isReplyFile(file)) return file;
|
|
539
|
+
return {
|
|
540
|
+
attachment: Buffer.from(file.data),
|
|
541
|
+
name: file.name,
|
|
542
|
+
...file.description !== void 0 && { description: file.description },
|
|
543
|
+
...file.title !== void 0 && { title: file.title }
|
|
544
|
+
};
|
|
545
|
+
}
|
|
534
546
|
function seedState(interaction) {
|
|
535
547
|
if (interaction.deferred && interaction.ephemeral === null) return "deferred-update";
|
|
536
548
|
if (interaction.replied) return "replied";
|
|
@@ -544,10 +556,10 @@ function seedState(interaction) {
|
|
|
544
556
|
var ReplySender = class extends BaseReplySender {
|
|
545
557
|
interaction;
|
|
546
558
|
constructor(interaction, routeId, bus) {
|
|
547
|
-
super(routeId,
|
|
559
|
+
super(routeId, {
|
|
548
560
|
bus,
|
|
549
561
|
interactionId: interaction.id
|
|
550
|
-
});
|
|
562
|
+
}, seedState(interaction));
|
|
551
563
|
this.interaction = interaction;
|
|
552
564
|
}
|
|
553
565
|
async writeReply(response, opts) {
|
|
@@ -613,7 +625,7 @@ var ReplySender = class extends BaseReplySender {
|
|
|
613
625
|
components: reply.components,
|
|
614
626
|
flags,
|
|
615
627
|
...reply.allowedMentions && { allowedMentions: reply.allowedMentions },
|
|
616
|
-
...reply.files && { files:
|
|
628
|
+
...reply.files && { files: reply.files.map(toDjsFile) }
|
|
617
629
|
};
|
|
618
630
|
}
|
|
619
631
|
editOptions(response) {
|
|
@@ -622,7 +634,7 @@ var ReplySender = class extends BaseReplySender {
|
|
|
622
634
|
components: reply.components,
|
|
623
635
|
flags: MessageFlags.IsComponentsV2,
|
|
624
636
|
...reply.allowedMentions && { allowedMentions: reply.allowedMentions },
|
|
625
|
-
...reply.files && { files:
|
|
637
|
+
...reply.files && { files: reply.files.map(toDjsFile) }
|
|
626
638
|
};
|
|
627
639
|
}
|
|
628
640
|
updateOptions(response) {
|
|
@@ -631,7 +643,7 @@ var ReplySender = class extends BaseReplySender {
|
|
|
631
643
|
components: reply.components,
|
|
632
644
|
flags: MessageFlags.IsComponentsV2,
|
|
633
645
|
...reply.allowedMentions && { allowedMentions: reply.allowedMentions },
|
|
634
|
-
...reply.files && { files:
|
|
646
|
+
...reply.files && { files: reply.files.map(toDjsFile) }
|
|
635
647
|
};
|
|
636
648
|
}
|
|
637
649
|
createdMessage(result) {
|
|
@@ -1487,7 +1499,7 @@ function interactionKind(interaction) {
|
|
|
1487
1499
|
|
|
1488
1500
|
//#endregion
|
|
1489
1501
|
//#region src/bot/handleEventFault.ts
|
|
1490
|
-
const logger$1 = new Logger("
|
|
1502
|
+
const logger$1 = new Logger("Faults", { channel: "errors" });
|
|
1491
1503
|
/**
|
|
1492
1504
|
* The event controller boundary. Reports a throw from an event handler and never replies, since a
|
|
1493
1505
|
* generic event has no reply target. A {@link Silence} or a non-reporting {@link Notice} stops quietly, a
|
|
@@ -1589,11 +1601,11 @@ var EventDispatcher = class {
|
|
|
1589
1601
|
utils.summary("Loaded", {
|
|
1590
1602
|
"event handlers": this.loadedHandlers.length,
|
|
1591
1603
|
middlewares: this.loadedMiddlewares.length
|
|
1592
|
-
});
|
|
1593
|
-
if (this.loadedMiddlewares.length > 0) utils.block("Loaded event middlewares", utils.entries(this.loadedMiddlewares));
|
|
1604
|
+
}, "debug");
|
|
1605
|
+
if (this.loadedMiddlewares.length > 0) utils.block("Loaded event middlewares", utils.entries(this.loadedMiddlewares), "debug");
|
|
1594
1606
|
const perEvent = {};
|
|
1595
1607
|
for (const [event, handlers] of this.eventMap) perEvent[event] = handlers.length;
|
|
1596
|
-
utils.block("Loaded event handlers", [...utils.entries(this.loadedHandlers), ...utils.counts(perEvent)]);
|
|
1608
|
+
utils.block("Loaded event handlers", [...utils.entries(this.loadedHandlers), ...utils.counts(perEvent)], "debug");
|
|
1597
1609
|
}
|
|
1598
1610
|
async loadHandlers(dir) {
|
|
1599
1611
|
await traverseDirectory(dir, (fullPath, relativePath, imported) => {
|
|
@@ -1643,14 +1655,10 @@ var EventDispatcher = class {
|
|
|
1643
1655
|
...metadata.events && { events: metadata.events }
|
|
1644
1656
|
});
|
|
1645
1657
|
this.middlewares.sort((a, b) => a.priority - b.priority);
|
|
1646
|
-
if (this.loading) {
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
});
|
|
1651
|
-
return;
|
|
1652
|
-
}
|
|
1653
|
-
this.logger.utils.registration(`${middlewareCtor.name} ${paint.mute(`(${metadata.priority})`)}`, relativePath, "event middleware");
|
|
1658
|
+
if (this.loading) this.loadedMiddlewares.push({
|
|
1659
|
+
name: `${middlewareCtor.name} (${metadata.priority})`,
|
|
1660
|
+
from: formatFilePath(relativePath)
|
|
1661
|
+
});
|
|
1654
1662
|
}
|
|
1655
1663
|
async runMiddlewares(eventName, args) {
|
|
1656
1664
|
for (const { ctor, events } of this.middlewares) {
|
|
@@ -1696,7 +1704,6 @@ var EventDispatcher = class {
|
|
|
1696
1704
|
name: handlerClass.name,
|
|
1697
1705
|
from
|
|
1698
1706
|
});
|
|
1699
|
-
else this.logger.utils.registration(handlerClass.name, from);
|
|
1700
1707
|
}
|
|
1701
1708
|
attachToClient() {
|
|
1702
1709
|
for (const [eventName] of this.eventMap) this.attachListener(eventName);
|
|
@@ -1745,7 +1752,8 @@ var EventDispatcher = class {
|
|
|
1745
1752
|
try {
|
|
1746
1753
|
this.logger.debug(`Processing ${paint.mint.bold(eventName)} with ${paint.mute(ctor.name)}`);
|
|
1747
1754
|
const handler = new ctor(args, this.core, eventName);
|
|
1748
|
-
|
|
1755
|
+
const eventCtx = eventGateContext(eventName, args, this.core);
|
|
1756
|
+
await runHandlerGates(ctor, eventCtx);
|
|
1749
1757
|
await handler.execute();
|
|
1750
1758
|
} catch (caught) {
|
|
1751
1759
|
handleEventFault(caught, String(eventName), ctor.name, args, this.core);
|
|
@@ -1783,7 +1791,7 @@ var UnhandledAutocomplete = class extends AutocompleteHandler {
|
|
|
1783
1791
|
*
|
|
1784
1792
|
* @internal
|
|
1785
1793
|
*/
|
|
1786
|
-
const HARMLESS_API_CODES = new Set([
|
|
1794
|
+
const HARMLESS_API_CODES = /* @__PURE__ */ new Set([
|
|
1787
1795
|
RESTJSONErrorCodes.UnknownInteraction,
|
|
1788
1796
|
RESTJSONErrorCodes.InteractionHasAlreadyBeenAcknowledged,
|
|
1789
1797
|
RESTJSONErrorCodes.UnknownMessage
|
|
@@ -1791,7 +1799,7 @@ const HARMLESS_API_CODES = new Set([
|
|
|
1791
1799
|
|
|
1792
1800
|
//#endregion
|
|
1793
1801
|
//#region src/bot/handleInteractionFault.ts
|
|
1794
|
-
const logger = new Logger("
|
|
1802
|
+
const logger = new Logger("Faults", { channel: "errors" });
|
|
1795
1803
|
/**
|
|
1796
1804
|
* The interaction controller boundary. Sorts a throw from any handler-lifecycle phase into the right
|
|
1797
1805
|
* user reply plus the right bus event. When a handler is built its sender is passed in, so the boundary
|
|
@@ -1959,8 +1967,8 @@ var InteractionDispatcher = class {
|
|
|
1959
1967
|
utils.summary("Loaded", {
|
|
1960
1968
|
"interaction handlers": this.loadedHandlers.length,
|
|
1961
1969
|
middlewares: this.loadedMiddlewares.length
|
|
1962
|
-
});
|
|
1963
|
-
if (this.loadedMiddlewares.length > 0) utils.block("Loaded middlewares", utils.entries(this.loadedMiddlewares));
|
|
1970
|
+
}, "debug");
|
|
1971
|
+
if (this.loadedMiddlewares.length > 0) utils.block("Loaded middlewares", utils.entries(this.loadedMiddlewares), "debug");
|
|
1964
1972
|
utils.block("Loaded interaction handlers", [...utils.entries(this.loadedHandlers), ...utils.counts({
|
|
1965
1973
|
slash: this.slashMap.size,
|
|
1966
1974
|
buttons: this.buttonMap.size,
|
|
@@ -1973,7 +1981,7 @@ var InteractionDispatcher = class {
|
|
|
1973
1981
|
"message menus": this.messageContextMenuMap.size,
|
|
1974
1982
|
"user menus": this.userContextMenuMap.size,
|
|
1975
1983
|
autocomplete: this.autocompleteMap.size
|
|
1976
|
-
})]);
|
|
1984
|
+
})], "debug");
|
|
1977
1985
|
}
|
|
1978
1986
|
async loadHandlers(dir) {
|
|
1979
1987
|
await traverseDirectory(dir, (fullPath, relativePath, imported) => {
|
|
@@ -2003,14 +2011,10 @@ var InteractionDispatcher = class {
|
|
|
2003
2011
|
priority: metadata.priority
|
|
2004
2012
|
});
|
|
2005
2013
|
this.middlewares.sort((a, b) => a.priority - b.priority);
|
|
2006
|
-
if (this.loading) {
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
});
|
|
2011
|
-
return;
|
|
2012
|
-
}
|
|
2013
|
-
this.logger.utils.registration(`${middlewareCtor.name} ${paint.mute(`(${metadata.priority})`)}`, relativePath, "middleware");
|
|
2014
|
+
if (this.loading) this.loadedMiddlewares.push({
|
|
2015
|
+
name: `${middlewareCtor.name} (${metadata.priority})`,
|
|
2016
|
+
from: formatFilePath(relativePath)
|
|
2017
|
+
});
|
|
2014
2018
|
}
|
|
2015
2019
|
isHandlerClass(obj) {
|
|
2016
2020
|
if (typeof obj !== "function") return false;
|
|
@@ -2043,7 +2047,6 @@ var InteractionDispatcher = class {
|
|
|
2043
2047
|
name: handlerClass.name,
|
|
2044
2048
|
from
|
|
2045
2049
|
});
|
|
2046
|
-
else this.logger.utils.registration(handlerClass.name, from);
|
|
2047
2050
|
}
|
|
2048
2051
|
/** @internal For use in dev mode */
|
|
2049
2052
|
async onHmr(event) {
|
|
@@ -2103,7 +2106,7 @@ var InteractionDispatcher = class {
|
|
|
2103
2106
|
const report = (outcome) => {
|
|
2104
2107
|
if (reported) return;
|
|
2105
2108
|
reported = true;
|
|
2106
|
-
this.core.bus
|
|
2109
|
+
reportDispatch(this.core.bus, {
|
|
2107
2110
|
routeId,
|
|
2108
2111
|
interactionId: interaction.id,
|
|
2109
2112
|
kind,
|
|
@@ -2111,7 +2114,7 @@ var InteractionDispatcher = class {
|
|
|
2111
2114
|
startedAt,
|
|
2112
2115
|
fallback: !matched,
|
|
2113
2116
|
queuedMs
|
|
2114
|
-
})
|
|
2117
|
+
});
|
|
2115
2118
|
};
|
|
2116
2119
|
let sender;
|
|
2117
2120
|
try {
|
|
@@ -2193,9 +2196,7 @@ var InteractionDispatcher = class {
|
|
|
2193
2196
|
case interaction.isAutocomplete():
|
|
2194
2197
|
await this.handleAutocomplete(interaction);
|
|
2195
2198
|
break;
|
|
2196
|
-
default:
|
|
2197
|
-
this.logger.warn(`Unhandled interaction type: ${interaction.type}`);
|
|
2198
|
-
break;
|
|
2199
|
+
default: this.logger.warn(`Unhandled interaction type: ${interaction.type}`);
|
|
2199
2200
|
}
|
|
2200
2201
|
}
|
|
2201
2202
|
async handleSlashCommand(interaction) {
|
|
@@ -2236,7 +2237,7 @@ var InteractionDispatcher = class {
|
|
|
2236
2237
|
};
|
|
2237
2238
|
|
|
2238
2239
|
//#endregion
|
|
2239
|
-
//#region \0@oxc-project+runtime@0.
|
|
2240
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorate.js
|
|
2240
2241
|
function __decorate(decorators, target, key, desc) {
|
|
2241
2242
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2242
2243
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2351,7 +2352,7 @@ __decorate([Envapt("DISCORD_BOT_TOKEN", { converter: (raw) => validateDiscordTok
|
|
|
2351
2352
|
//#endregion
|
|
2352
2353
|
//#region src/version.ts
|
|
2353
2354
|
/** Package version */
|
|
2354
|
-
const version = "0.1.
|
|
2355
|
+
const version = "0.1.1-next.0";
|
|
2355
2356
|
|
|
2356
2357
|
//#endregion
|
|
2357
2358
|
//#region src/Seedcord.ts
|
|
@@ -2403,7 +2404,7 @@ var Seedcord = class Seedcord extends Pluggable {
|
|
|
2403
2404
|
}
|
|
2404
2405
|
static reset() {
|
|
2405
2406
|
super.reset();
|
|
2406
|
-
LoggerChannelRegistry.instance.
|
|
2407
|
+
LoggerChannelRegistry.instance.configure({});
|
|
2407
2408
|
}
|
|
2408
2409
|
registerStartupTasks() {
|
|
2409
2410
|
if (Envapter.isDevelopment || Envapter.isTest) this.registerHmrAwareModules();
|