seyfert 4.4.1 → 5.0.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.
Files changed (231) hide show
  1. package/README.md +7 -1
  2. package/lib/api/Routes/cdn.d.ts +2 -2
  3. package/lib/api/Routes/guilds.d.ts +2 -2
  4. package/lib/api/Routes/invites.d.ts +2 -2
  5. package/lib/api/api.d.ts +20 -8
  6. package/lib/api/api.js +198 -44
  7. package/lib/api/shared.d.ts +30 -1
  8. package/lib/api/utils/constants.d.ts +1 -1
  9. package/lib/api/utils/constants.js +1 -1
  10. package/lib/api/utils/utils.d.ts +2 -1
  11. package/lib/api/utils/utils.js +1 -1
  12. package/lib/builders/Attachment.d.ts +1 -1
  13. package/lib/builders/Attachment.js +30 -8
  14. package/lib/builders/MediaGallery.d.ts +2 -2
  15. package/lib/builders/MediaGallery.js +10 -0
  16. package/lib/builders/Modal.d.ts +18 -8
  17. package/lib/builders/Modal.js +36 -7
  18. package/lib/builders/Poll.js +18 -0
  19. package/lib/builders/RadioGroup.d.ts +4 -3
  20. package/lib/builders/RadioGroup.js +24 -3
  21. package/lib/builders/SelectMenu.d.ts +8 -6
  22. package/lib/builders/SelectMenu.js +24 -3
  23. package/lib/builders/types.d.ts +3 -2
  24. package/lib/cache/adapters/default.d.ts +1 -1
  25. package/lib/cache/adapters/default.js +23 -26
  26. package/lib/cache/adapters/limited.d.ts +1 -0
  27. package/lib/cache/adapters/limited.js +47 -33
  28. package/lib/cache/index.d.ts +19 -25
  29. package/lib/cache/index.js +58 -6
  30. package/lib/cache/resources/bans.d.ts +1 -1
  31. package/lib/cache/resources/bans.js +4 -4
  32. package/lib/cache/resources/channels.d.ts +1 -1
  33. package/lib/cache/resources/channels.js +4 -4
  34. package/lib/cache/resources/default/base.d.ts +1 -1
  35. package/lib/cache/resources/default/base.js +8 -8
  36. package/lib/cache/resources/default/guild-based.d.ts +5 -5
  37. package/lib/cache/resources/default/guild-based.js +29 -16
  38. package/lib/cache/resources/default/guild-related.d.ts +5 -5
  39. package/lib/cache/resources/default/guild-related.js +14 -14
  40. package/lib/cache/resources/emojis.d.ts +1 -1
  41. package/lib/cache/resources/emojis.js +4 -4
  42. package/lib/cache/resources/guilds.js +28 -15
  43. package/lib/cache/resources/members.d.ts +1 -1
  44. package/lib/cache/resources/members.js +6 -6
  45. package/lib/cache/resources/messages.d.ts +7 -2
  46. package/lib/cache/resources/messages.js +43 -20
  47. package/lib/cache/resources/overwrites.d.ts +1 -1
  48. package/lib/cache/resources/overwrites.js +5 -8
  49. package/lib/cache/resources/roles.d.ts +1 -1
  50. package/lib/cache/resources/roles.js +4 -4
  51. package/lib/cache/resources/stickers.d.ts +1 -1
  52. package/lib/cache/resources/stickers.js +4 -4
  53. package/lib/cache/resources/users.js +4 -4
  54. package/lib/cache/resources/voice-states.d.ts +1 -1
  55. package/lib/cache/resources/voice-states.js +4 -4
  56. package/lib/client/base.d.ts +83 -24
  57. package/lib/client/base.js +594 -39
  58. package/lib/client/client.d.ts +29 -4
  59. package/lib/client/client.js +38 -13
  60. package/lib/client/collectors.d.ts +9 -8
  61. package/lib/client/collectors.js +19 -52
  62. package/lib/client/httpclient.d.ts +3 -0
  63. package/lib/client/index.d.ts +3 -1
  64. package/lib/client/index.js +4 -0
  65. package/lib/client/intents.d.ts +3 -0
  66. package/lib/client/intents.js +9 -0
  67. package/lib/client/plugins/api.d.ts +4 -0
  68. package/lib/client/plugins/api.js +550 -0
  69. package/lib/client/plugins/errors.d.ts +25 -0
  70. package/lib/client/plugins/errors.js +79 -0
  71. package/lib/client/plugins/order.d.ts +10 -0
  72. package/lib/client/plugins/order.js +32 -0
  73. package/lib/client/plugins/registry.d.ts +273 -0
  74. package/lib/client/plugins/registry.js +868 -0
  75. package/lib/client/plugins/shared.d.ts +23 -0
  76. package/lib/client/plugins/shared.js +193 -0
  77. package/lib/client/plugins/types.d.ts +398 -0
  78. package/lib/client/plugins/types.js +8 -0
  79. package/lib/client/plugins.d.ts +78 -0
  80. package/lib/client/plugins.js +558 -0
  81. package/lib/client/transformers.d.ts +33 -33
  82. package/lib/client/workerclient.d.ts +11 -2
  83. package/lib/client/workerclient.js +33 -22
  84. package/lib/collection.d.ts +10 -8
  85. package/lib/collection.js +19 -25
  86. package/lib/commands/applications/chat.d.ts +20 -18
  87. package/lib/commands/applications/chat.js +39 -14
  88. package/lib/commands/applications/chatcontext.d.ts +23 -15
  89. package/lib/commands/applications/chatcontext.js +23 -2
  90. package/lib/commands/applications/entryPoint.d.ts +4 -3
  91. package/lib/commands/applications/entryPoint.js +1 -1
  92. package/lib/commands/applications/entrycontext.d.ts +7 -9
  93. package/lib/commands/applications/entrycontext.js +3 -1
  94. package/lib/commands/applications/menu.d.ts +4 -3
  95. package/lib/commands/applications/menucontext.d.ts +7 -9
  96. package/lib/commands/applications/menucontext.js +3 -1
  97. package/lib/commands/applications/options.d.ts +23 -23
  98. package/lib/commands/applications/shared.d.ts +39 -17
  99. package/lib/commands/decorators.d.ts +50 -38
  100. package/lib/commands/decorators.js +15 -5
  101. package/lib/commands/handle.d.ts +19 -8
  102. package/lib/commands/handle.js +224 -143
  103. package/lib/commands/handler.d.ts +21 -8
  104. package/lib/commands/handler.js +157 -69
  105. package/lib/commands/index.d.ts +1 -0
  106. package/lib/commands/optionresolver.d.ts +2 -2
  107. package/lib/common/it/colors.js +12 -2
  108. package/lib/common/it/error.d.ts +9 -0
  109. package/lib/common/it/error.js +8 -0
  110. package/lib/common/it/fake-promise.d.ts +4 -0
  111. package/lib/common/it/fake-promise.js +10 -0
  112. package/lib/common/it/formatter.d.ts +14 -11
  113. package/lib/common/it/formatter.js +4 -3
  114. package/lib/common/it/logger.d.ts +7 -1
  115. package/lib/common/it/logger.js +24 -6
  116. package/lib/common/it/utils.d.ts +6 -8
  117. package/lib/common/it/utils.js +44 -42
  118. package/lib/common/shorters/application.d.ts +3 -3
  119. package/lib/common/shorters/application.js +3 -2
  120. package/lib/common/shorters/bans.d.ts +8 -4
  121. package/lib/common/shorters/bans.js +13 -5
  122. package/lib/common/shorters/channels.d.ts +4 -4
  123. package/lib/common/shorters/channels.js +4 -4
  124. package/lib/common/shorters/emojis.js +1 -0
  125. package/lib/common/shorters/guilds.d.ts +8 -8
  126. package/lib/common/shorters/guilds.js +14 -31
  127. package/lib/common/shorters/interaction.d.ts +1 -1
  128. package/lib/common/shorters/invites.d.ts +201 -201
  129. package/lib/common/shorters/members.d.ts +7 -7
  130. package/lib/common/shorters/members.js +13 -14
  131. package/lib/common/shorters/messages.d.ts +2 -2
  132. package/lib/common/shorters/soundboard.d.ts +5 -5
  133. package/lib/common/shorters/users.d.ts +1 -1
  134. package/lib/common/shorters/webhook.d.ts +3 -2
  135. package/lib/common/shorters/webhook.js +0 -7
  136. package/lib/common/types/options.d.ts +4 -0
  137. package/lib/common/types/util.d.ts +8 -0
  138. package/lib/common/types/write.d.ts +2 -1
  139. package/lib/components/BaseSelectMenuComponent.d.ts +1 -1
  140. package/lib/components/BaseSelectMenuComponent.js +1 -1
  141. package/lib/components/ButtonComponent.d.ts +3 -3
  142. package/lib/components/ChannelSelectMenuComponent.d.ts +2 -2
  143. package/lib/components/File.d.ts +1 -1
  144. package/lib/components/MediaGallery.d.ts +1 -1
  145. package/lib/components/MentionableSelectMenuComponent.d.ts +1 -1
  146. package/lib/components/RoleSelectMenuComponent.d.ts +1 -1
  147. package/lib/components/Separator.d.ts +1 -1
  148. package/lib/components/StringSelectMenuComponent.d.ts +1 -1
  149. package/lib/components/TextInputComponent.d.ts +1 -1
  150. package/lib/components/Thumbnail.d.ts +1 -1
  151. package/lib/components/UserSelectMenuComponent.d.ts +1 -1
  152. package/lib/components/componentcommand.d.ts +8 -7
  153. package/lib/components/componentcontext.d.ts +24 -36
  154. package/lib/components/componentcontext.js +7 -17
  155. package/lib/components/handler.d.ts +17 -7
  156. package/lib/components/handler.js +108 -49
  157. package/lib/components/index.d.ts +1 -0
  158. package/lib/components/index.js +1 -0
  159. package/lib/components/interactioncontext.d.ts +45 -0
  160. package/lib/components/interactioncontext.js +93 -0
  161. package/lib/components/modalcommand.d.ts +5 -4
  162. package/lib/components/modalcontext.d.ts +39 -20
  163. package/lib/components/modalcontext.js +59 -6
  164. package/lib/events/event.d.ts +9 -3
  165. package/lib/events/handler.d.ts +51 -6
  166. package/lib/events/handler.js +165 -36
  167. package/lib/events/hooks/application_command.d.ts +1 -1
  168. package/lib/events/hooks/auto_moderation.d.ts +2 -2
  169. package/lib/events/hooks/guild.d.ts +150 -150
  170. package/lib/events/hooks/interactions.d.ts +1 -1
  171. package/lib/events/hooks/invite.d.ts +20 -20
  172. package/lib/events/hooks/message.d.ts +27 -27
  173. package/lib/events/hooks/presence.d.ts +11 -11
  174. package/lib/events/hooks/soundboard.d.ts +6 -6
  175. package/lib/events/hooks/stage.d.ts +2 -2
  176. package/lib/events/hooks/subscriptions.d.ts +3 -3
  177. package/lib/events/hooks/thread.d.ts +30 -30
  178. package/lib/events/hooks/voice.d.ts +3 -4
  179. package/lib/events/hooks/voice.js +2 -1
  180. package/lib/events/utils.d.ts +4 -0
  181. package/lib/events/utils.js +59 -0
  182. package/lib/index.d.ts +9 -4
  183. package/lib/index.js +14 -8
  184. package/lib/langs/handler.d.ts +14 -11
  185. package/lib/langs/handler.js +46 -9
  186. package/lib/langs/router.d.ts +10 -3
  187. package/lib/structures/Application.d.ts +1 -1
  188. package/lib/structures/Emoji.d.ts +3 -3
  189. package/lib/structures/Emoji.js +2 -2
  190. package/lib/structures/Guild.d.ts +154 -154
  191. package/lib/structures/GuildBan.d.ts +4 -4
  192. package/lib/structures/GuildBan.js +3 -3
  193. package/lib/structures/GuildMember.d.ts +7 -7
  194. package/lib/structures/GuildMember.js +28 -7
  195. package/lib/structures/GuildRole.d.ts +1 -1
  196. package/lib/structures/GuildRole.js +2 -2
  197. package/lib/structures/Interaction.d.ts +11 -9
  198. package/lib/structures/Interaction.js +33 -12
  199. package/lib/structures/Message.d.ts +21 -14
  200. package/lib/structures/Message.js +29 -14
  201. package/lib/structures/User.d.ts +1 -1
  202. package/lib/structures/VoiceState.d.ts +4 -0
  203. package/lib/structures/VoiceState.js +13 -1
  204. package/lib/structures/Webhook.d.ts +9 -1
  205. package/lib/structures/Webhook.js +4 -1
  206. package/lib/structures/channels.d.ts +148 -134
  207. package/lib/structures/channels.js +27 -26
  208. package/lib/structures/extra/BitField.d.ts +4 -4
  209. package/lib/structures/extra/BitField.js +20 -4
  210. package/lib/structures/extra/DiscordBase.js +1 -1
  211. package/lib/structures/extra/Permissions.d.ts +2 -4
  212. package/lib/structures/extra/Permissions.js +1 -17
  213. package/lib/types/payloads/_interactions/responses.d.ts +2 -2
  214. package/lib/types/payloads/components.d.ts +4 -4
  215. package/lib/websocket/SharedTypes.d.ts +4 -4
  216. package/lib/websocket/constants/index.d.ts +1 -1
  217. package/lib/websocket/constants/index.js +3 -2
  218. package/lib/websocket/discord/events/memberUpdate.js +2 -2
  219. package/lib/websocket/discord/heartbeater.d.ts +1 -0
  220. package/lib/websocket/discord/heartbeater.js +7 -0
  221. package/lib/websocket/discord/shard.d.ts +2 -2
  222. package/lib/websocket/discord/shard.js +16 -14
  223. package/lib/websocket/discord/sharder.d.ts +8 -7
  224. package/lib/websocket/discord/sharder.js +26 -6
  225. package/lib/websocket/discord/shared.d.ts +19 -6
  226. package/lib/websocket/discord/socket/custom.js +5 -0
  227. package/lib/websocket/discord/worker.d.ts +1 -0
  228. package/lib/websocket/discord/worker.js +2 -0
  229. package/lib/websocket/discord/workermanager.d.ts +25 -11
  230. package/lib/websocket/discord/workermanager.js +41 -10
  231. package/package.json +13 -17
@@ -38,39 +38,39 @@ export type WebhookStructure = InferCustomStructure<Webhook, 'Webhook'>;
38
38
  export type OptionResolverStructure = InferCustomStructure<OptionResolver, 'OptionResolver'>;
39
39
  export type EntitlementStructure = InferCustomStructure<Entitlement, 'Entitlement'>;
40
40
  export declare const Transformers: {
41
- Application(client: import("../commands").UsingClient, data: import("../types").APIApplication): ApplicationStructure;
42
- ApplicationEmoji(client: import("../commands").UsingClient, data: import("../types").APIApplicationEmoji): ApplicationEmojiStructure;
43
- AnonymousGuild(client: import("../commands").UsingClient, data: import("../types").APIPartialGuild): AnonymousGuildStructure;
44
- AutoModerationRule(client: import("../commands").UsingClient, data: import("../types").APIAutoModerationRule): AutoModerationRuleStructure;
45
- BaseChannel(client: import("../commands").UsingClient, data: import("../types").APIChannelBase<ChannelType>): BaseChannelStructure;
46
- BaseGuildChannel(client: import("../commands").UsingClient, data: import("../types").APIGuildChannel<ChannelType>): BaseGuildChannelStructure;
47
- TextGuildChannel(client: import("../commands").UsingClient, data: import("../types").APIGuildChannel<ChannelType>): TextGuildChannelStructure;
48
- DMChannel(client: import("../commands").UsingClient, data: import("../types").APIChannelBase<ChannelType>): DMChannelStructure;
49
- VoiceChannel(client: import("../commands").UsingClient, data: import("../types").APIGuildChannel<ChannelType>): VoiceChannelStructure;
50
- StageChannel(client: import("../commands").UsingClient, data: import("../types").APIGuildChannel<ChannelType>): StageChannelStructure;
51
- MediaChannel(client: import("../commands").UsingClient, data: import("../types").APIGuildChannel<ChannelType>): MediaChannelStructure;
52
- ForumChannel(client: import("../commands").UsingClient, data: import("../types").APIGuildChannel<ChannelType>): ForumChannelStructure;
53
- ThreadChannel(client: import("../commands").UsingClient, data: import("../types").APIChannelBase<ChannelType>): ThreadChannelStructure;
41
+ Application(client: import("..").UsingClient, data: import("..").APIApplication): ApplicationStructure;
42
+ ApplicationEmoji(client: import("..").UsingClient, data: import("..").APIApplicationEmoji): ApplicationEmojiStructure;
43
+ AnonymousGuild(client: import("..").UsingClient, data: import("..").APIPartialGuild): AnonymousGuildStructure;
44
+ AutoModerationRule(client: import("..").UsingClient, data: import("..").APIAutoModerationRule): AutoModerationRuleStructure;
45
+ BaseChannel(client: import("..").UsingClient, data: import("..").APIChannelBase<ChannelType>): BaseChannelStructure;
46
+ BaseGuildChannel(client: import("..").UsingClient, data: import("..").APIGuildChannel<ChannelType>): BaseGuildChannelStructure;
47
+ TextGuildChannel(client: import("..").UsingClient, data: import("..").APIGuildChannel<ChannelType>): TextGuildChannelStructure;
48
+ DMChannel(client: import("..").UsingClient, data: import("..").APIChannelBase<ChannelType>): DMChannelStructure;
49
+ VoiceChannel(client: import("..").UsingClient, data: import("..").APIGuildChannel<ChannelType>): VoiceChannelStructure;
50
+ StageChannel(client: import("..").UsingClient, data: import("..").APIGuildChannel<ChannelType>): StageChannelStructure;
51
+ MediaChannel(client: import("..").UsingClient, data: import("..").APIGuildChannel<ChannelType>): MediaChannelStructure;
52
+ ForumChannel(client: import("..").UsingClient, data: import("..").APIGuildChannel<ChannelType>): ForumChannelStructure;
53
+ ThreadChannel(client: import("..").UsingClient, data: import("..").APIChannelBase<ChannelType>): ThreadChannelStructure;
54
54
  CategoryChannel(...args: ConstructorParameters<typeof CategoryChannel>): CategoryChannelStructure;
55
- NewsChannel(client: import("../commands").UsingClient, data: import("../types").APIGuildChannel<ChannelType>): NewsChannelStructure;
56
- DirectoryChannel(client: import("../commands").UsingClient, data: import("../types").APIChannelBase<ChannelType>): DirectoryChannelStructure;
57
- ClientUser(client: import("../commands").UsingClient, data: import("../types").APIUser, application: Pick<import("../types").APIApplication, "id" | "flags">): ClientUserStructure;
58
- Guild<State extends StructStates = "api">(client: import("../commands").UsingClient, data: import("../types").APIGuild | import("../types").GatewayGuildCreateDispatchData): GuildStructure<State>;
59
- GuildBan(client: import("../commands").UsingClient, data: import("../types").APIBan | import("../types").ActuallyBan, guildId: string): GuildBanStructure;
60
- Emoji(client: import("../commands").UsingClient, data: import("../types").APIEmoji): EmojiStructure;
61
- GuildEmoji(client: import("../commands").UsingClient, data: import("../types").APIEmoji, guildId: string): GuildEmojiStructure;
62
- GuildMember(client: import("../commands").UsingClient, data: import("../structures").GuildMemberData, user: import("../types").APIUser, guildId: string): GuildMemberStructure;
63
- InteractionGuildMember(client: import("../commands").UsingClient, data: import("../types").APIInteractionDataResolvedGuildMember, user: import("../types").APIUser, guildId: string): InteractionGuildMemberStructure;
64
- GuildRole(client: import("../commands").UsingClient, data: import("../types").APIRole, guildId: string): GuildRoleStructure;
65
- GuildTemplate(client: import("../commands").UsingClient, data: import("../types").APITemplate): GuildTemplateStructure;
66
- Message(client: import("../commands").UsingClient, data: import("../structures").MessageData): MessageStructure;
67
- WebhookMessage(client: import("../commands").UsingClient, data: import("../structures").MessageData, webhookId: string, webhookToken: string): WebhookMessageStructure;
68
- Poll(client: import("../commands").UsingClient, data: import("../types").APIPoll, channelId: string, messageId: string): PollStructure;
69
- Sticker(client: import("../commands").UsingClient, data: import("../types").APISticker): StickerStructure;
70
- User(client: import("../commands").UsingClient, data: import("../types").APIUser): UserStructure;
71
- VoiceState(client: import("../commands").UsingClient, data: import("../types").APIVoiceState): VoiceStateStructure;
72
- Webhook(client: import("../commands").UsingClient, data: import("../types").APIWebhook): WebhookStructure;
73
- OptionResolver(client: import("../commands").UsingClient, options: import("../types").APIApplicationCommandInteractionDataOption[], parent?: import("../commands").Command | undefined, guildId?: string | undefined, resolved?: import("../commands").ContextOptionsResolved | undefined): OptionResolverStructure;
74
- Entitlement(client: import("../commands").UsingClient, data: import("../types").APIEntitlement): EntitlementStructure;
55
+ NewsChannel(client: import("..").UsingClient, data: import("..").APIGuildChannel<ChannelType>): NewsChannelStructure;
56
+ DirectoryChannel(client: import("..").UsingClient, data: import("..").APIChannelBase<ChannelType>): DirectoryChannelStructure;
57
+ ClientUser(client: import("..").UsingClient, data: import("..").APIUser, application: Pick<import("..").APIApplication, "id" | "flags">): ClientUserStructure;
58
+ Guild<State extends StructStates = "api">(client: import("..").UsingClient, data: import("..").APIGuild | import("..").GatewayGuildCreateDispatchData): GuildStructure<State>;
59
+ GuildBan(client: import("..").UsingClient, data: import("..").APIBan | import("..").ActuallyBan, guildId: string): GuildBanStructure;
60
+ Emoji(client: import("..").UsingClient, data: import("..").APIEmoji): EmojiStructure;
61
+ GuildEmoji(client: import("..").UsingClient, data: import("..").APIEmoji, guildId: string): GuildEmojiStructure;
62
+ GuildMember(client: import("..").UsingClient, data: import("..").GuildMemberData, user: import("..").APIUser, guildId: string): GuildMemberStructure;
63
+ InteractionGuildMember(client: import("..").UsingClient, data: import("..").APIInteractionDataResolvedGuildMember, user: import("..").APIUser, guildId: string): InteractionGuildMemberStructure;
64
+ GuildRole(client: import("..").UsingClient, data: import("..").APIRole, guildId: string): GuildRoleStructure;
65
+ GuildTemplate(client: import("..").UsingClient, data: import("..").APITemplate): GuildTemplateStructure;
66
+ Message(client: import("..").UsingClient, data: import("..").MessageData): MessageStructure;
67
+ WebhookMessage(client: import("..").UsingClient, data: import("..").MessageData, webhookId: string, webhookToken: string): WebhookMessageStructure;
68
+ Poll(client: import("..").UsingClient, data: import("..").APIPoll, channelId: string, messageId: string): PollStructure;
69
+ Sticker(client: import("..").UsingClient, data: import("..").APISticker): StickerStructure;
70
+ User(client: import("..").UsingClient, data: import("..").APIUser): UserStructure;
71
+ VoiceState(client: import("..").UsingClient, data: import("..").APIVoiceState): VoiceStateStructure;
72
+ Webhook(client: import("..").UsingClient, data: import("..").APIWebhook): WebhookStructure;
73
+ OptionResolver(client: import("..").UsingClient, options: import("..").APIApplicationCommandInteractionDataOption[], parent?: import("..").Command | undefined, guildId?: string | undefined, resolved?: import("..").ContextOptionsResolved | undefined): OptionResolverStructure;
74
+ Entitlement(client: import("..").UsingClient, data: import("..").APIEntitlement): EntitlementStructure;
75
75
  };
76
76
  export type InferCustomStructure<T, N extends string> = CustomStructures extends Record<N, infer P> ? P : T;
@@ -1,6 +1,6 @@
1
1
  import { type Awaitable, type DeepPartial, type MakeRequired, type When } from '../common';
2
2
  import { EventHandler } from '../events';
3
- import type { GatewayDispatchPayload } from '../types';
3
+ import { type GatewayDispatchPayload } from '../types';
4
4
  import { Shard, type ShardManagerOptions, type WorkerData } from '../websocket';
5
5
  import { MemberUpdateHandler } from '../websocket/discord/events/memberUpdate';
6
6
  import { PresenceUpdateHandler } from '../websocket/discord/events/presenceUpdate';
@@ -12,6 +12,7 @@ import type { BaseClientOptions, ServicesOptions, StartOptions } from './base';
12
12
  import { BaseClient } from './base';
13
13
  import type { Client, ClientOptions } from './client';
14
14
  import { Collectors } from './collectors';
15
+ import { type RegisteredPluginExtension } from './plugins';
15
16
  import { type ClientUserStructure } from './transformers';
16
17
  export declare class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
17
18
  memberUpdateHandler: MemberUpdateHandler;
@@ -47,13 +48,21 @@ export declare class WorkerClient<Ready extends boolean = boolean> extends BaseC
47
48
  tellWorkers<R, V extends Record<string, unknown>>(func: (_: this, vars: V) => R, vars: V): Promise<Awaited<R>[]>;
48
49
  createShard(id: number, data: Pick<ManagerSpawnShards, 'info' | 'compress' | 'properties'>): Shard;
49
50
  resumeShard(shardId: number, shardData: MakeRequired<ShardData>): Promise<unknown>;
50
- protected onPacket(packet: GatewayDispatchPayload, shardId: number): Promise<void>;
51
+ protected onPacket(packet: GatewayDispatchPayload, shardId: number): Promise<GatewayDispatchPayload | null>;
52
+ }
53
+ export interface WorkerClient<Ready extends boolean = boolean> extends RegisteredPluginExtension {
51
54
  }
52
55
  export declare function generateShardInfo(shard: Shard): WorkerShardInfo;
53
56
  export interface WorkerClientOptions extends BaseClientOptions {
54
57
  commands?: NonNullable<Client['options']>['commands'];
55
58
  handlePayload?: ShardManagerOptions['handlePayload'];
59
+ /**
60
+ * @deprecated Use shard disconnect events instead. Injected ShardManager callbacks can double-fire.
61
+ */
56
62
  onShardDisconnect?: ShardManagerOptions['onShardDisconnect'];
63
+ /**
64
+ * @deprecated Use shard reconnect events instead. Injected ShardManager callbacks can double-fire.
65
+ */
57
66
  onShardReconnect?: ShardManagerOptions['onShardReconnect'];
58
67
  gateway?: ClientOptions['gateway'];
59
68
  postMessage?: (body: unknown) => Awaitable<unknown>;
@@ -7,11 +7,13 @@ const __1 = require("..");
7
7
  const cache_1 = require("../cache");
8
8
  const common_1 = require("../common");
9
9
  const events_1 = require("../events");
10
+ const types_1 = require("../types");
10
11
  const websocket_1 = require("../websocket");
11
12
  const memberUpdate_1 = require("../websocket/discord/events/memberUpdate");
12
13
  const presenceUpdate_1 = require("../websocket/discord/events/presenceUpdate");
13
14
  const base_1 = require("./base");
14
15
  const collectors_1 = require("./collectors");
16
+ const plugins_1 = require("./plugins");
15
17
  const transformers_1 = require("./transformers");
16
18
  let workerData;
17
19
  let manager;
@@ -61,6 +63,8 @@ class WorkerClient extends base_1.BaseClient {
61
63
  return workerData.workerId;
62
64
  }
63
65
  get latency() {
66
+ if (this.shards.size <= 0)
67
+ return 0;
64
68
  let acc = 0;
65
69
  this.shards.forEach(s => (acc += s.latency));
66
70
  return acc / this.shards.size;
@@ -98,9 +102,7 @@ class WorkerClient extends base_1.BaseClient {
98
102
  }
99
103
  if (workerData.mode !== 'custom')
100
104
  (manager ?? process).on('message', (data) => this.handleManagerMessages(data));
101
- this.logger = new __1.Logger({
102
- name: `[Worker #${workerData.workerId}]`,
103
- });
105
+ this.configureLogger({ name: `[Worker #${workerData.workerId}]` }, this.options.logger);
104
106
  if (workerData.debug) {
105
107
  this.debugger = new __1.Logger({
106
108
  name: `[Worker #${workerData.workerId}]`,
@@ -116,21 +118,24 @@ class WorkerClient extends base_1.BaseClient {
116
118
  }),
117
119
  });
118
120
  }
119
- this.cache.intents = workerData.intents;
121
+ this.resolvePluginGatewayIntents(workerData.intents);
120
122
  this.rest.workerData = workerData;
123
+ await super.start(options);
124
+ workerData.intents = this.resolvePluginGatewayIntents(workerData.intents);
121
125
  this.postMessage({
122
126
  type: workerData.resharding ? 'WORKER_START_RESHARDING' : 'WORKER_START',
123
127
  workerId: workerData.workerId,
124
128
  });
125
- await super.start(options);
126
129
  await this.loadEvents(options.eventsDir);
127
130
  }
128
131
  async loadEvents(dir) {
129
132
  dir ??= await this.getRC().then(x => x.locations.events);
133
+ await (0, plugins_1.runPluginHooks)(this, 'events:beforeLoad', this, dir);
130
134
  if (dir) {
131
135
  await this.events.load(dir);
132
136
  this.logger.info('EventHandler loaded');
133
137
  }
138
+ await (0, plugins_1.runPluginHooks)(this, 'events:afterLoad', this, dir);
134
139
  }
135
140
  postMessage(body) {
136
141
  if (manager)
@@ -157,12 +162,13 @@ class WorkerClient extends base_1.BaseClient {
157
162
  {
158
163
  const shard = this.shards.get(data.shardId);
159
164
  if (!shard) {
160
- this.logger.fatal('Worker trying send payload by non-existent shard');
165
+ this.logger.fatal(`Worker trying to send payload by non-existent shard (#${data.shardId})`);
161
166
  return;
162
167
  }
163
- await shard.send(true, {
164
- ...data,
165
- });
168
+ const { nonce: _nonce, shardId: _shardId, type: _type, ...payload } = data;
169
+ const pluginPayload = await (0, plugins_1.applyPluginGatewaySendPayloadWrappers)(this, data.shardId, payload);
170
+ if (pluginPayload !== null)
171
+ await shard.send(true, pluginPayload);
166
172
  this.postMessage({
167
173
  type: 'RESULT_PAYLOAD',
168
174
  nonce: data.nonce,
@@ -174,7 +180,7 @@ class WorkerClient extends base_1.BaseClient {
174
180
  {
175
181
  const shard = this.resharding.get(data.shardId);
176
182
  if (!shard) {
177
- this.logger.fatal('Worker trying reshard non-existent shard');
183
+ this.logger.fatal(`Worker trying to reshard non-existent shard (#${data.shardId})`);
178
184
  return;
179
185
  }
180
186
  shard.options.presence = data.presence;
@@ -185,7 +191,7 @@ class WorkerClient extends base_1.BaseClient {
185
191
  {
186
192
  const shard = this.shards.get(data.shardId);
187
193
  if (!shard) {
188
- this.logger.fatal('Worker trying connect non-existent shard');
194
+ this.logger.fatal(`Worker trying to connect non-existent shard (#${data.shardId})`);
189
195
  return;
190
196
  }
191
197
  shard.options.presence = data.presence;
@@ -215,7 +221,7 @@ class WorkerClient extends base_1.BaseClient {
215
221
  ...this.options.gateway?.properties,
216
222
  },
217
223
  handlePayload(_, payload) {
218
- if (payload.t !== 'GUILDS_READY')
224
+ if (payload.t !== types_1.GatewayDispatchEvents.GuildsReady)
219
225
  return;
220
226
  if (++shardsConnected === workerData.shards.length) {
221
227
  self.postMessage({
@@ -256,7 +262,7 @@ class WorkerClient extends base_1.BaseClient {
256
262
  {
257
263
  const shard = this.shards.get(data.shardId);
258
264
  if (!shard) {
259
- this.logger.fatal('Worker trying get non-existent shard');
265
+ this.logger.fatal(`Worker trying to get non-existent shard (#${data.shardId})`);
260
266
  return;
261
267
  }
262
268
  this.postMessage({
@@ -414,13 +420,13 @@ class WorkerClient extends base_1.BaseClient {
414
420
  },
415
421
  async handlePayload(shardId, payload) {
416
422
  await handlePayload?.(shardId, payload);
417
- await onPacket(payload, shardId);
418
- if (self.options.sendPayloadToParent)
423
+ const pluginPacket = await onPacket(payload, shardId);
424
+ if (self.options.sendPayloadToParent && pluginPacket !== null)
419
425
  self.postMessage({
420
426
  workerId: workerData.workerId,
421
427
  shardId,
422
428
  type: 'RECEIVE_PAYLOAD',
423
- payload,
429
+ payload: pluginPacket,
424
430
  });
425
431
  },
426
432
  });
@@ -447,6 +453,10 @@ class WorkerClient extends base_1.BaseClient {
447
453
  });
448
454
  }
449
455
  async onPacket(packet, shardId) {
456
+ const pluginPacket = await (0, plugins_1.applyPluginGatewayDispatchInterceptors)(this, shardId, packet);
457
+ if (pluginPacket === null)
458
+ return null;
459
+ packet = pluginPacket;
450
460
  Promise.allSettled([
451
461
  this.events.runEvent('RAW', this, packet, shardId, false),
452
462
  this.collectors.run('RAW', packet, this),
@@ -455,7 +465,7 @@ class WorkerClient extends base_1.BaseClient {
455
465
  case 'GUILD_MEMBER_UPDATE':
456
466
  {
457
467
  if (!this.memberUpdateHandler.check(packet.d)) {
458
- return;
468
+ return packet;
459
469
  }
460
470
  await this.events.execute(packet, this, shardId);
461
471
  }
@@ -463,26 +473,26 @@ class WorkerClient extends base_1.BaseClient {
463
473
  case 'PRESENCE_UPDATE':
464
474
  {
465
475
  if (!this.presenceUpdateHandler.check(packet.d)) {
466
- return;
476
+ return packet;
467
477
  }
468
478
  await this.events.execute(packet, this, shardId);
469
479
  }
470
480
  break;
471
481
  default: {
472
482
  switch (packet.t) {
473
- case 'INTERACTION_CREATE':
483
+ case types_1.GatewayDispatchEvents.InteractionCreate:
474
484
  {
475
485
  await this.events.execute(packet, this, shardId);
476
486
  await this.handleCommand.interaction(packet.d, shardId);
477
487
  }
478
488
  break;
479
- case 'MESSAGE_CREATE':
489
+ case types_1.GatewayDispatchEvents.MessageCreate:
480
490
  {
481
491
  await this.events.execute(packet, this, shardId);
482
492
  await this.handleCommand.message(packet.d, shardId);
483
493
  }
484
494
  break;
485
- case 'READY': {
495
+ case types_1.GatewayDispatchEvents.Ready: {
486
496
  this.botId = packet.d.user.id;
487
497
  this.applicationId = packet.d.application.id;
488
498
  this.me = transformers_1.Transformers.ClientUser(this, packet.d.user, packet.d.application);
@@ -497,7 +507,7 @@ class WorkerClient extends base_1.BaseClient {
497
507
  this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`);
498
508
  break;
499
509
  }
500
- case 'GUILDS_READY':
510
+ case types_1.GatewayDispatchEvents.GuildsReady:
501
511
  {
502
512
  if ([...this.shards.values()].every(shard => shard.isReady)) {
503
513
  this.postMessage({
@@ -516,6 +526,7 @@ class WorkerClient extends base_1.BaseClient {
516
526
  break;
517
527
  }
518
528
  }
529
+ return packet;
519
530
  }
520
531
  }
521
532
  exports.WorkerClient = WorkerClient;
@@ -46,7 +46,10 @@ export declare class Collection<K, V> extends Map<K, V> {
46
46
  * const filteredArray = collection.filter((value, key) => key % 2 === 0);
47
47
  * console.log(filteredArray); // Output: ['two']
48
48
  */
49
+ filter<S extends V>(fn: (value: V, key: K, collection: this) => value is S): S[];
49
50
  filter(fn: (value: V, key: K, collection: this) => boolean): V[];
51
+ filterCollection<S extends V>(fn: (value: V, key: K, collection: this) => value is S): Collection<K, S>;
52
+ filterCollection(fn: (value: V, key: K, collection: this) => boolean): Collection<K, V>;
50
53
  /**
51
54
  * Apply a function against an accumulator and each element in the collection (from left to right) to reduce it to a single value.
52
55
  * @param fn The function to execute on each element in the collection.
@@ -99,6 +102,7 @@ export declare class Collection<K, V> extends Map<K, V> {
99
102
  * const firstEvenValue = collection.find(value => value % 2 === 0);
100
103
  * console.log(firstEvenValue); // Output: 2
101
104
  */
105
+ find<S extends V>(fn: (value: V, key: K, collection: this) => value is S): S | undefined;
102
106
  find(fn: (value: V, key: K, collection: this) => boolean): V | undefined;
103
107
  /**
104
108
  * Returns the first key in the collection that satisfies the provided testing function.
@@ -114,7 +118,7 @@ export declare class Collection<K, V> extends Map<K, V> {
114
118
  */
115
119
  findKey(fn: (value: V, key: K, collection: this) => boolean): K | undefined;
116
120
  }
117
- type LimitedCollectionData<V> = {
121
+ export type LimitedCollectionData<V> = {
118
122
  expire: number;
119
123
  expireOn: number;
120
124
  value: V;
@@ -242,13 +246,11 @@ export declare class LimitedCollection<K, V> {
242
246
  private stopTimeout;
243
247
  private startTimeout;
244
248
  keys(): MapIterator<K>;
245
- values(): Generator<{
246
- value: V;
247
- expire: number;
248
- expireOn: number;
249
- }, void, unknown>;
250
- entries(): Generator<[K, LimitedCollectionData<V>], void, unknown>;
249
+ values(): IterableIterator<V>;
250
+ rawValues(): IterableIterator<LimitedCollectionData<V>>;
251
+ entries(): IterableIterator<[K, V]>;
252
+ rawEntries(): IterableIterator<[K, LimitedCollectionData<V>]>;
253
+ [Symbol.iterator](): IterableIterator<[K, V]>;
251
254
  clear(): void;
252
255
  private clearExpired;
253
256
  }
254
- export {};
package/lib/collection.js CHANGED
@@ -50,19 +50,6 @@ class Collection extends Map {
50
50
  }
51
51
  return result;
52
52
  }
53
- /**
54
- * Creates a new array with all elements that pass the test implemented by the provided function.
55
- * @param fn The function to test each element of the collection.
56
- * @param thisArg The value to use as `this` when executing the filter function.
57
- * @returns A new array with the elements that pass the test.
58
- * @example
59
- * const collection = new Collection<number, string>();
60
- * collection.set(1, 'one');
61
- * collection.set(2, 'two');
62
- * collection.set(3, 'three');
63
- * const filteredArray = collection.filter((value, key) => key % 2 === 0);
64
- * console.log(filteredArray); // Output: ['two']
65
- */
66
53
  filter(fn) {
67
54
  const result = [];
68
55
  for (const [key, value] of this.entries()) {
@@ -71,6 +58,14 @@ class Collection extends Map {
71
58
  }
72
59
  return result;
73
60
  }
61
+ filterCollection(fn) {
62
+ const result = new Collection();
63
+ for (const [key, value] of this.entries()) {
64
+ if (fn(value, key, this))
65
+ result.set(key, value);
66
+ }
67
+ return result;
68
+ }
74
69
  /**
75
70
  * Apply a function against an accumulator and each element in the collection (from left to right) to reduce it to a single value.
76
71
  * @param fn The function to execute on each element in the collection.
@@ -141,18 +136,6 @@ class Collection extends Map {
141
136
  }
142
137
  return false;
143
138
  }
144
- /**
145
- * Returns the value of the first element in the collection that satisfies the provided testing function.
146
- * @param fn The function to test each element of the collection.
147
- * @returns The value of the first element that passes the test. `undefined` if no element passes the test.
148
- * @example
149
- * const collection = new Collection<number, number>();
150
- * collection.set(1, 1);
151
- * collection.set(2, 2);
152
- * collection.set(3, 3);
153
- * const firstEvenValue = collection.find(value => value % 2 === 0);
154
- * console.log(firstEvenValue); // Output: 2
155
- */
156
139
  find(fn) {
157
140
  for (const [key, value] of this.entries()) {
158
141
  if (fn(value, key, this)) {
@@ -210,6 +193,8 @@ class LimitedCollection {
210
193
  _closerDirty = true;
211
194
  constructor(options = {}) {
212
195
  this.options = (0, common_1.MergeOptions)(LimitedCollection.default, options);
196
+ if (Number.isNaN(this.options.limit))
197
+ throw new TypeError('LimitedCollection limit cannot be NaN');
213
198
  }
214
199
  /**
215
200
  * Adds an element to the limited collection.
@@ -435,6 +420,9 @@ class LimitedCollection {
435
420
  return this.data.keys();
436
421
  }
437
422
  values() {
423
+ return this.data.values();
424
+ }
425
+ rawValues() {
438
426
  return (function* (self) {
439
427
  for (const key of self.data.keys()) {
440
428
  yield self.raw(key);
@@ -442,12 +430,18 @@ class LimitedCollection {
442
430
  })(this);
443
431
  }
444
432
  entries() {
433
+ return this.data.entries();
434
+ }
435
+ rawEntries() {
445
436
  return (function* (self) {
446
437
  for (const key of self.data.keys()) {
447
438
  yield [key, self.raw(key)];
448
439
  }
449
440
  })(this);
450
441
  }
442
+ [Symbol.iterator]() {
443
+ return this.entries();
444
+ }
451
445
  clear() {
452
446
  this.data.clear();
453
447
  this.expirations.clear();
@@ -1,27 +1,28 @@
1
1
  import type { PermissionStrings, SeyfertBaseChoiceableOption, SeyfertBasicOption, SeyfertChoice } from '../..';
2
2
  import type { Attachment } from '../../builders';
3
+ import type { PluginMiddlewareDenialMetadata } from '../../client/plugins/types';
3
4
  import type { GuildMemberStructure, GuildRoleStructure, InteractionGuildMemberStructure, UserStructure } from '../../client/transformers';
4
5
  import type { AllChannels, AutocompleteInteraction } from '../../structures';
5
6
  import { type APIApplicationCommandBasicOption, type APIApplicationCommandOption, ApplicationCommandOptionType, ApplicationCommandType, type ApplicationIntegrationType, type InteractionContextType, type LocaleString } from '../../types';
6
- import type { Groups, RegisteredMiddlewares } from '../decorators';
7
+ import type { Groups, ResolvedRegisteredMiddlewares } from '../decorators';
7
8
  import type { CommandOptionWithType } from '../handle';
8
9
  import type { CommandContext } from './chatcontext';
9
10
  import type { ExtraProps, IgnoreCommand, OnOptionsReturnObject, SeyfertChannelMap, UsingClient } from './shared';
10
11
  export interface ReturnOptionsTypes {
11
- 1: never;
12
- 2: never;
13
- 3: string;
14
- 4: number;
15
- 5: boolean;
16
- 6: InteractionGuildMemberStructure | UserStructure;
17
- 7: AllChannels;
18
- 8: GuildRoleStructure;
19
- 9: GuildRoleStructure | InteractionGuildMemberStructure | GuildMemberStructure | UserStructure;
20
- 10: number;
21
- 11: Attachment;
12
+ [ApplicationCommandOptionType.Subcommand]: never;
13
+ [ApplicationCommandOptionType.SubcommandGroup]: never;
14
+ [ApplicationCommandOptionType.String]: string;
15
+ [ApplicationCommandOptionType.Integer]: number;
16
+ [ApplicationCommandOptionType.Boolean]: boolean;
17
+ [ApplicationCommandOptionType.User]: InteractionGuildMemberStructure | UserStructure;
18
+ [ApplicationCommandOptionType.Channel]: AllChannels;
19
+ [ApplicationCommandOptionType.Role]: GuildRoleStructure;
20
+ [ApplicationCommandOptionType.Mentionable]: GuildRoleStructure | InteractionGuildMemberStructure | GuildMemberStructure | UserStructure;
21
+ [ApplicationCommandOptionType.Number]: number;
22
+ [ApplicationCommandOptionType.Attachment]: Attachment;
22
23
  }
23
- export type AutocompleteCallback = (interaction: AutocompleteInteraction) => any;
24
- export type OnAutocompleteErrorCallback = (interaction: AutocompleteInteraction, error: unknown) => any;
24
+ export type AutocompleteCallback<ValueType extends string | number = string | number> = (interaction: AutocompleteInteraction<boolean, ValueType>) => any;
25
+ export type OnAutocompleteErrorCallback<ValueType extends string | number = string | number> = (interaction: AutocompleteInteraction<boolean, ValueType>, error: unknown) => any;
25
26
  export type CommandBaseOption = SeyfertBaseChoiceableOption<ApplicationCommandOptionType> | SeyfertBasicOption<ApplicationCommandOptionType>;
26
27
  export type CommandBaseAutocompleteOption = (SeyfertBasicOption<ApplicationCommandOptionType> | SeyfertBaseChoiceableOption<ApplicationCommandOptionType>) & {
27
28
  autocomplete: AutocompleteCallback;
@@ -44,9 +45,9 @@ type ContextOptionsAuxInternal<T extends CommandBaseOption & {
44
45
  type: ApplicationCommandOptionType;
45
46
  }> = T['value'] extends (...args: any) => any ? Parameters<Parameters<T['value']>[1]>[0] : NonNullable<T['value']> extends (...args: any) => any ? Parameters<Parameters<NonNullable<T['value']>>[1]>[0] extends never ? T extends {
46
47
  channel_types?: infer C;
47
- } ? C extends any[] ? C[number] extends keyof SeyfertChannelMap ? SeyfertChannelMap[C[number]] : never : never : T extends {
48
+ } ? C extends readonly any[] ? C[number] extends keyof SeyfertChannelMap ? SeyfertChannelMap[C[number]] : never : never : T extends {
48
49
  choices?: infer C;
49
- } ? C extends SeyfertChoice<string | number>[] ? C[number]['value'] : never : never : Parameters<Parameters<NonNullable<T['value']>>[1]>[0] : ReturnOptionsTypes[T['type']];
50
+ } ? C extends readonly SeyfertChoice<string | number>[] ? C[number]['value'] : never : never : Parameters<Parameters<NonNullable<T['value']>>[1]>[0] : ReturnOptionsTypes[T['type']];
50
51
  type ContextOptionsAux<T extends OptionsRecord> = {
51
52
  [K in Exclude<keyof T, KeysWithoutRequired<T>>]: ContextOptionsAuxInternal<T[K]>;
52
53
  } & {
@@ -54,7 +55,7 @@ type ContextOptionsAux<T extends OptionsRecord> = {
54
55
  };
55
56
  export type ContextOptions<T extends OptionsRecord> = ContextOptionsAux<T>;
56
57
  export declare class BaseCommand {
57
- middlewares: (keyof RegisteredMiddlewares)[];
58
+ middlewares: readonly (keyof ResolvedRegisteredMiddlewares)[];
58
59
  __filePath?: string;
59
60
  __t?: {
60
61
  name: string | undefined;
@@ -76,6 +77,7 @@ export declare class BaseCommand {
76
77
  ignore?: IgnoreCommand;
77
78
  aliases?: string[];
78
79
  props: ExtraProps;
80
+ private static __getMiddlewareOwnerName;
79
81
  toJSON(): {
80
82
  name: BaseCommand["name"];
81
83
  type: BaseCommand["type"];
@@ -95,7 +97,7 @@ export declare class BaseCommand {
95
97
  onAfterRun?(context: CommandContext, error: unknown | undefined): any;
96
98
  onRunError?(context: CommandContext, error: unknown): any;
97
99
  onOptionsError?(context: CommandContext, metadata: OnOptionsReturnObject): any;
98
- onMiddlewaresError?(context: CommandContext, error: string): any;
100
+ onMiddlewaresError?(context: CommandContext, error: string, metadata: PluginMiddlewareDenialMetadata): any;
99
101
  onBotPermissionsFail?(context: CommandContext, permissions: PermissionStrings): any;
100
102
  onPermissionsFail?(context: CommandContext, permissions: PermissionStrings): any;
101
103
  onInternalError?(client: UsingClient, command: Command | SubCommand, error?: unknown): any;
@@ -79,39 +79,56 @@ class BaseCommand {
79
79
  if (!middlewares.length) {
80
80
  return Promise.resolve({});
81
81
  }
82
+ const missingMiddlewares = middlewares.filter(middleware => !context.client.middlewares?.[middleware]);
83
+ if (missingMiddlewares.length) {
84
+ const owner = BaseCommand.__getMiddlewareOwnerName(context);
85
+ const message = `${owner} has ${global ? 'global ' : ''}middleware${missingMiddlewares.length === 1 ? '' : 's'} ${missingMiddlewares
86
+ .map(middleware => `"${String(middleware)}"`)
87
+ .join(', ')} assigned, but ${missingMiddlewares.length === 1 ? 'it is' : 'they are'} not registered.`;
88
+ context.client.logger.warn(message);
89
+ }
90
+ const activeMiddlewares = middlewares.filter(middleware => context.client.middlewares?.[middleware]);
91
+ if (!activeMiddlewares.length)
92
+ return Promise.resolve({});
82
93
  let index = 0;
83
94
  return new Promise((res, rej) => {
84
95
  let running = true;
85
- const pass = () => {
86
- if (!running) {
87
- return;
88
- }
89
- running = false;
90
- return res({ pass: true });
91
- };
92
96
  function next(...args) {
93
97
  if (!running) {
94
98
  return;
95
99
  }
96
100
  if (args.length) {
97
- context[global ? 'globalMetadata' : 'metadata'][middlewares[index]] = args[0];
101
+ context[global ? 'globalMetadata' : 'metadata'][activeMiddlewares[index]] = args[0];
98
102
  }
99
- if (++index >= middlewares.length) {
103
+ if (++index >= activeMiddlewares.length) {
100
104
  running = false;
101
105
  return res({});
102
106
  }
103
- void invoke(middlewares[index]);
107
+ void invoke(activeMiddlewares[index]);
104
108
  }
105
- const stop = err => {
109
+ const deny = (err, middleware) => {
106
110
  if (!running) {
107
111
  return;
108
112
  }
109
113
  running = false;
110
- return res({ error: err });
114
+ return res({
115
+ error: err,
116
+ metadata: { middleware: String(middleware), scope: global ? 'global' : 'command' },
117
+ });
118
+ };
119
+ const stop = err => {
120
+ if (err == null) {
121
+ if (!running) {
122
+ return;
123
+ }
124
+ running = false;
125
+ return res({ pass: true });
126
+ }
127
+ return deny(err, activeMiddlewares[index]);
111
128
  };
112
129
  async function invoke(middleware) {
113
130
  try {
114
- await context.client.middlewares[middleware]({ context, next, stop, pass });
131
+ await context.client.middlewares[middleware]({ context, next, stop });
115
132
  }
116
133
  catch (err) {
117
134
  if (!running) {
@@ -121,9 +138,17 @@ class BaseCommand {
121
138
  rej(err);
122
139
  }
123
140
  }
124
- void invoke(middlewares[0]);
141
+ void invoke(activeMiddlewares[0]);
125
142
  });
126
143
  }
144
+ static __getMiddlewareOwnerName(context) {
145
+ const command = context.command;
146
+ if (command?.name)
147
+ return `Command "${command.name}"`;
148
+ if (typeof command?.customId === 'string')
149
+ return `Component "${command.customId}"`;
150
+ return 'Command';
151
+ }
127
152
  /** @internal */
128
153
  __runMiddlewares(context) {
129
154
  return BaseCommand.__runMiddlewares(context, this.middlewares, false);