seyfert 4.5.0 → 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 (230) hide show
  1. package/lib/api/Routes/cdn.d.ts +2 -2
  2. package/lib/api/Routes/guilds.d.ts +2 -2
  3. package/lib/api/Routes/invites.d.ts +2 -2
  4. package/lib/api/api.d.ts +20 -8
  5. package/lib/api/api.js +198 -44
  6. package/lib/api/shared.d.ts +30 -1
  7. package/lib/api/utils/constants.d.ts +1 -1
  8. package/lib/api/utils/constants.js +1 -1
  9. package/lib/api/utils/utils.d.ts +2 -1
  10. package/lib/api/utils/utils.js +1 -1
  11. package/lib/builders/Attachment.d.ts +1 -1
  12. package/lib/builders/Attachment.js +30 -8
  13. package/lib/builders/MediaGallery.d.ts +2 -2
  14. package/lib/builders/MediaGallery.js +10 -0
  15. package/lib/builders/Modal.d.ts +18 -8
  16. package/lib/builders/Modal.js +36 -7
  17. package/lib/builders/Poll.js +18 -0
  18. package/lib/builders/RadioGroup.d.ts +4 -3
  19. package/lib/builders/RadioGroup.js +24 -3
  20. package/lib/builders/SelectMenu.d.ts +8 -6
  21. package/lib/builders/SelectMenu.js +24 -3
  22. package/lib/builders/types.d.ts +3 -2
  23. package/lib/cache/adapters/default.d.ts +1 -1
  24. package/lib/cache/adapters/default.js +23 -26
  25. package/lib/cache/adapters/limited.d.ts +1 -0
  26. package/lib/cache/adapters/limited.js +47 -33
  27. package/lib/cache/index.d.ts +19 -25
  28. package/lib/cache/index.js +58 -6
  29. package/lib/cache/resources/bans.d.ts +1 -1
  30. package/lib/cache/resources/bans.js +4 -4
  31. package/lib/cache/resources/channels.d.ts +1 -1
  32. package/lib/cache/resources/channels.js +4 -4
  33. package/lib/cache/resources/default/base.d.ts +1 -1
  34. package/lib/cache/resources/default/base.js +8 -8
  35. package/lib/cache/resources/default/guild-based.d.ts +5 -5
  36. package/lib/cache/resources/default/guild-based.js +29 -16
  37. package/lib/cache/resources/default/guild-related.d.ts +5 -5
  38. package/lib/cache/resources/default/guild-related.js +14 -14
  39. package/lib/cache/resources/emojis.d.ts +1 -1
  40. package/lib/cache/resources/emojis.js +4 -4
  41. package/lib/cache/resources/guilds.js +28 -15
  42. package/lib/cache/resources/members.d.ts +1 -1
  43. package/lib/cache/resources/members.js +6 -6
  44. package/lib/cache/resources/messages.d.ts +7 -2
  45. package/lib/cache/resources/messages.js +43 -20
  46. package/lib/cache/resources/overwrites.d.ts +1 -1
  47. package/lib/cache/resources/overwrites.js +5 -8
  48. package/lib/cache/resources/roles.d.ts +1 -1
  49. package/lib/cache/resources/roles.js +4 -4
  50. package/lib/cache/resources/stickers.d.ts +1 -1
  51. package/lib/cache/resources/stickers.js +4 -4
  52. package/lib/cache/resources/users.js +4 -4
  53. package/lib/cache/resources/voice-states.d.ts +1 -1
  54. package/lib/cache/resources/voice-states.js +4 -4
  55. package/lib/client/base.d.ts +83 -24
  56. package/lib/client/base.js +594 -39
  57. package/lib/client/client.d.ts +28 -3
  58. package/lib/client/client.js +33 -9
  59. package/lib/client/collectors.d.ts +9 -8
  60. package/lib/client/collectors.js +19 -52
  61. package/lib/client/httpclient.d.ts +3 -0
  62. package/lib/client/index.d.ts +3 -1
  63. package/lib/client/index.js +4 -0
  64. package/lib/client/intents.d.ts +3 -0
  65. package/lib/client/intents.js +9 -0
  66. package/lib/client/plugins/api.d.ts +4 -0
  67. package/lib/client/plugins/api.js +550 -0
  68. package/lib/client/plugins/errors.d.ts +25 -0
  69. package/lib/client/plugins/errors.js +79 -0
  70. package/lib/client/plugins/order.d.ts +10 -0
  71. package/lib/client/plugins/order.js +32 -0
  72. package/lib/client/plugins/registry.d.ts +273 -0
  73. package/lib/client/plugins/registry.js +868 -0
  74. package/lib/client/plugins/shared.d.ts +23 -0
  75. package/lib/client/plugins/shared.js +193 -0
  76. package/lib/client/plugins/types.d.ts +398 -0
  77. package/lib/client/plugins/types.js +8 -0
  78. package/lib/client/plugins.d.ts +78 -0
  79. package/lib/client/plugins.js +558 -0
  80. package/lib/client/transformers.d.ts +33 -33
  81. package/lib/client/workerclient.d.ts +10 -1
  82. package/lib/client/workerclient.js +27 -17
  83. package/lib/collection.d.ts +10 -8
  84. package/lib/collection.js +19 -25
  85. package/lib/commands/applications/chat.d.ts +20 -18
  86. package/lib/commands/applications/chat.js +39 -14
  87. package/lib/commands/applications/chatcontext.d.ts +23 -15
  88. package/lib/commands/applications/chatcontext.js +23 -2
  89. package/lib/commands/applications/entryPoint.d.ts +4 -3
  90. package/lib/commands/applications/entryPoint.js +1 -1
  91. package/lib/commands/applications/entrycontext.d.ts +7 -9
  92. package/lib/commands/applications/entrycontext.js +3 -1
  93. package/lib/commands/applications/menu.d.ts +4 -3
  94. package/lib/commands/applications/menucontext.d.ts +7 -9
  95. package/lib/commands/applications/menucontext.js +3 -1
  96. package/lib/commands/applications/options.d.ts +23 -23
  97. package/lib/commands/applications/shared.d.ts +39 -17
  98. package/lib/commands/decorators.d.ts +50 -38
  99. package/lib/commands/decorators.js +15 -5
  100. package/lib/commands/handle.d.ts +19 -8
  101. package/lib/commands/handle.js +224 -143
  102. package/lib/commands/handler.d.ts +21 -8
  103. package/lib/commands/handler.js +157 -69
  104. package/lib/commands/index.d.ts +1 -0
  105. package/lib/commands/optionresolver.d.ts +2 -2
  106. package/lib/common/it/colors.js +12 -2
  107. package/lib/common/it/error.d.ts +9 -0
  108. package/lib/common/it/error.js +8 -0
  109. package/lib/common/it/fake-promise.d.ts +4 -0
  110. package/lib/common/it/fake-promise.js +10 -0
  111. package/lib/common/it/formatter.d.ts +14 -11
  112. package/lib/common/it/formatter.js +4 -3
  113. package/lib/common/it/logger.d.ts +7 -1
  114. package/lib/common/it/logger.js +24 -6
  115. package/lib/common/it/utils.d.ts +6 -8
  116. package/lib/common/it/utils.js +44 -42
  117. package/lib/common/shorters/application.d.ts +3 -3
  118. package/lib/common/shorters/application.js +3 -2
  119. package/lib/common/shorters/bans.d.ts +8 -4
  120. package/lib/common/shorters/bans.js +13 -5
  121. package/lib/common/shorters/channels.d.ts +4 -4
  122. package/lib/common/shorters/channels.js +4 -4
  123. package/lib/common/shorters/emojis.js +1 -0
  124. package/lib/common/shorters/guilds.d.ts +8 -8
  125. package/lib/common/shorters/guilds.js +14 -31
  126. package/lib/common/shorters/interaction.d.ts +1 -1
  127. package/lib/common/shorters/invites.d.ts +201 -201
  128. package/lib/common/shorters/members.d.ts +7 -7
  129. package/lib/common/shorters/members.js +13 -14
  130. package/lib/common/shorters/messages.d.ts +2 -2
  131. package/lib/common/shorters/soundboard.d.ts +5 -5
  132. package/lib/common/shorters/users.d.ts +1 -1
  133. package/lib/common/shorters/webhook.d.ts +3 -2
  134. package/lib/common/shorters/webhook.js +0 -7
  135. package/lib/common/types/options.d.ts +4 -0
  136. package/lib/common/types/util.d.ts +8 -0
  137. package/lib/common/types/write.d.ts +2 -1
  138. package/lib/components/BaseSelectMenuComponent.d.ts +1 -1
  139. package/lib/components/BaseSelectMenuComponent.js +1 -1
  140. package/lib/components/ButtonComponent.d.ts +3 -3
  141. package/lib/components/ChannelSelectMenuComponent.d.ts +2 -2
  142. package/lib/components/File.d.ts +1 -1
  143. package/lib/components/MediaGallery.d.ts +1 -1
  144. package/lib/components/MentionableSelectMenuComponent.d.ts +1 -1
  145. package/lib/components/RoleSelectMenuComponent.d.ts +1 -1
  146. package/lib/components/Separator.d.ts +1 -1
  147. package/lib/components/StringSelectMenuComponent.d.ts +1 -1
  148. package/lib/components/TextInputComponent.d.ts +1 -1
  149. package/lib/components/Thumbnail.d.ts +1 -1
  150. package/lib/components/UserSelectMenuComponent.d.ts +1 -1
  151. package/lib/components/componentcommand.d.ts +8 -7
  152. package/lib/components/componentcontext.d.ts +24 -36
  153. package/lib/components/componentcontext.js +7 -17
  154. package/lib/components/handler.d.ts +17 -7
  155. package/lib/components/handler.js +108 -49
  156. package/lib/components/index.d.ts +1 -0
  157. package/lib/components/index.js +1 -0
  158. package/lib/components/interactioncontext.d.ts +45 -0
  159. package/lib/components/interactioncontext.js +93 -0
  160. package/lib/components/modalcommand.d.ts +5 -4
  161. package/lib/components/modalcontext.d.ts +39 -20
  162. package/lib/components/modalcontext.js +59 -6
  163. package/lib/events/event.d.ts +9 -3
  164. package/lib/events/handler.d.ts +51 -6
  165. package/lib/events/handler.js +165 -36
  166. package/lib/events/hooks/application_command.d.ts +1 -1
  167. package/lib/events/hooks/auto_moderation.d.ts +2 -2
  168. package/lib/events/hooks/guild.d.ts +150 -150
  169. package/lib/events/hooks/interactions.d.ts +1 -1
  170. package/lib/events/hooks/invite.d.ts +20 -20
  171. package/lib/events/hooks/message.d.ts +27 -27
  172. package/lib/events/hooks/presence.d.ts +11 -11
  173. package/lib/events/hooks/soundboard.d.ts +6 -6
  174. package/lib/events/hooks/stage.d.ts +2 -2
  175. package/lib/events/hooks/subscriptions.d.ts +3 -3
  176. package/lib/events/hooks/thread.d.ts +30 -30
  177. package/lib/events/hooks/voice.d.ts +3 -4
  178. package/lib/events/hooks/voice.js +2 -1
  179. package/lib/events/utils.d.ts +4 -0
  180. package/lib/events/utils.js +59 -0
  181. package/lib/index.d.ts +9 -4
  182. package/lib/index.js +13 -8
  183. package/lib/langs/handler.d.ts +14 -11
  184. package/lib/langs/handler.js +46 -9
  185. package/lib/langs/router.d.ts +10 -3
  186. package/lib/structures/Application.d.ts +1 -1
  187. package/lib/structures/Emoji.d.ts +3 -3
  188. package/lib/structures/Emoji.js +2 -2
  189. package/lib/structures/Guild.d.ts +154 -154
  190. package/lib/structures/GuildBan.d.ts +4 -4
  191. package/lib/structures/GuildBan.js +3 -3
  192. package/lib/structures/GuildMember.d.ts +7 -7
  193. package/lib/structures/GuildMember.js +28 -7
  194. package/lib/structures/GuildRole.d.ts +1 -1
  195. package/lib/structures/GuildRole.js +2 -2
  196. package/lib/structures/Interaction.d.ts +11 -9
  197. package/lib/structures/Interaction.js +33 -12
  198. package/lib/structures/Message.d.ts +21 -14
  199. package/lib/structures/Message.js +29 -14
  200. package/lib/structures/User.d.ts +1 -1
  201. package/lib/structures/VoiceState.d.ts +4 -0
  202. package/lib/structures/VoiceState.js +13 -1
  203. package/lib/structures/Webhook.d.ts +9 -1
  204. package/lib/structures/Webhook.js +4 -1
  205. package/lib/structures/channels.d.ts +148 -134
  206. package/lib/structures/channels.js +27 -26
  207. package/lib/structures/extra/BitField.d.ts +4 -4
  208. package/lib/structures/extra/BitField.js +20 -4
  209. package/lib/structures/extra/DiscordBase.js +1 -1
  210. package/lib/structures/extra/Permissions.d.ts +2 -4
  211. package/lib/structures/extra/Permissions.js +1 -17
  212. package/lib/types/payloads/_interactions/responses.d.ts +2 -2
  213. package/lib/types/payloads/components.d.ts +4 -4
  214. package/lib/websocket/SharedTypes.d.ts +4 -4
  215. package/lib/websocket/constants/index.d.ts +1 -1
  216. package/lib/websocket/constants/index.js +3 -2
  217. package/lib/websocket/discord/events/memberUpdate.js +2 -2
  218. package/lib/websocket/discord/heartbeater.d.ts +1 -0
  219. package/lib/websocket/discord/heartbeater.js +7 -0
  220. package/lib/websocket/discord/shard.d.ts +2 -2
  221. package/lib/websocket/discord/shard.js +15 -13
  222. package/lib/websocket/discord/sharder.d.ts +8 -7
  223. package/lib/websocket/discord/sharder.js +25 -5
  224. package/lib/websocket/discord/shared.d.ts +19 -6
  225. package/lib/websocket/discord/socket/custom.js +5 -0
  226. package/lib/websocket/discord/worker.d.ts +1 -0
  227. package/lib/websocket/discord/worker.js +2 -0
  228. package/lib/websocket/discord/workermanager.d.ts +25 -11
  229. package/lib/websocket/discord/workermanager.js +41 -10
  230. package/package.json +12 -16
@@ -23,17 +23,64 @@ class ModalContext extends basecontext_1.BaseContext {
23
23
  command;
24
24
  metadata = {};
25
25
  globalMetadata = {};
26
- get customId() {
27
- return this.interaction.customId;
28
- }
29
26
  get components() {
30
27
  return this.interaction.components;
31
28
  }
29
+ get customId() {
30
+ return this.interaction.customId;
31
+ }
32
32
  /**
33
33
  * Gets the language object for the interaction's locale.
34
34
  */
35
35
  get t() {
36
- return this.client.t(this.interaction.locale ?? this.client.langs.defaultLang ?? 'en-US');
36
+ return this.client.t(this.client.langs.preferGuildLocale
37
+ ? (this.interaction.guildLocale ?? this.interaction.locale ?? this.client.langs.defaultLang ?? 'en-US')
38
+ : (this.interaction.locale ?? this.client.langs.defaultLang ?? 'en-US'));
39
+ }
40
+ getChannels(customId, required) {
41
+ if (required)
42
+ return this.interaction.getChannels(customId, true);
43
+ return this.interaction.getChannels(customId);
44
+ }
45
+ getRoles(customId, required) {
46
+ if (required)
47
+ return this.interaction.getRoles(customId, true);
48
+ return this.interaction.getRoles(customId);
49
+ }
50
+ getUsers(customId, required) {
51
+ if (required)
52
+ return this.interaction.getUsers(customId, true);
53
+ return this.interaction.getUsers(customId);
54
+ }
55
+ getMentionables(customId, required) {
56
+ if (required)
57
+ return this.interaction.getMentionables(customId, true);
58
+ return this.interaction.getMentionables(customId);
59
+ }
60
+ getRadioValues(customId, required) {
61
+ if (required)
62
+ return this.interaction.getRadioValues(customId, true);
63
+ return this.interaction.getRadioValues(customId);
64
+ }
65
+ getCheckboxValues(customId, required) {
66
+ if (required)
67
+ return this.interaction.getCheckboxValues(customId, true);
68
+ return this.interaction.getCheckboxValues(customId);
69
+ }
70
+ getCheckbox(customId, required) {
71
+ if (required)
72
+ return this.interaction.getCheckbox(customId, true);
73
+ return this.interaction.getCheckbox(customId);
74
+ }
75
+ getInputValue(customId, required) {
76
+ if (required)
77
+ return this.interaction.getInputValue(customId, true);
78
+ return this.interaction.getInputValue(customId);
79
+ }
80
+ getFiles(customId, required) {
81
+ if (required)
82
+ return this.interaction.getFiles(customId, true);
83
+ return this.interaction.getFiles(customId);
37
84
  }
38
85
  /**
39
86
  * Writes a response to the interaction.
@@ -50,6 +97,12 @@ class ModalContext extends basecontext_1.BaseContext {
50
97
  deferReply(ephemeral = false, fetchReply) {
51
98
  return this.interaction.deferReply(ephemeral ? types_1.MessageFlags.Ephemeral : undefined, fetchReply);
52
99
  }
100
+ update(body, withResponse) {
101
+ return this.interaction.update(body, withResponse);
102
+ }
103
+ deferUpdate() {
104
+ return this.interaction.deferUpdate();
105
+ }
53
106
  /**
54
107
  * Edits the response of the interaction.
55
108
  * @param body - The updated body of the response.
@@ -100,14 +153,14 @@ class ModalContext extends basecontext_1.BaseContext {
100
153
  return this.client.members.fetch(this.guildId, this.client.botId, mode === 'rest');
101
154
  }
102
155
  }
103
- guild(mode = 'flow') {
156
+ guild(mode = 'flow', query) {
104
157
  if (!this.guildId)
105
158
  return (mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve());
106
159
  switch (mode) {
107
160
  case 'cache':
108
161
  return this.client.cache.guilds?.get(this.guildId);
109
162
  default:
110
- return this.client.guilds.fetch(this.guildId, mode === 'rest');
163
+ return this.client.guilds.fetch(this.guildId, { force: mode === 'rest', query });
111
164
  }
112
165
  }
113
166
  /**
@@ -1,6 +1,12 @@
1
- import type { UsingClient } from '../commands';
1
+ import type { PluginLoadedMetadata, PluginUploadCommandsMetadata } from '../client/plugins';
2
+ import type { Command, ContextMenuCommand, EntryPointCommand, UsingClient } from '../commands';
3
+ import type { Awaitable } from '../common';
4
+ import type { ComponentCommands } from '../components/handler';
2
5
  import type { ClientEvents } from './hooks';
3
6
  export interface CustomEvents {
7
+ commandsLoaded: (metadata: PluginLoadedMetadata<'commands', Command | ContextMenuCommand | EntryPointCommand>) => void;
8
+ componentsLoaded: (metadata: PluginLoadedMetadata<'components', ComponentCommands>) => void;
9
+ uploadCommands: (metadata: PluginUploadCommandsMetadata) => void;
4
10
  }
5
11
  export type ClientNameEvents = Extract<keyof ClientEvents, string>;
6
12
  export type CustomEventsKeys = Extract<keyof CustomEvents, string>;
@@ -11,7 +17,7 @@ export interface ClientDataEvent {
11
17
  export type CallbackEventHandler = {
12
18
  [K in keyof ClientEvents]: (...data: [Awaited<ClientEvents[K]>, UsingClient, number]) => unknown;
13
19
  } & {
14
- [K in keyof CustomEvents]: (...data: [...Parameters<CustomEvents[K]>, UsingClient, number]) => unknown;
20
+ [K in keyof CustomEvents]: (...data: [...Parameters<CustomEvents[K]>, UsingClient]) => unknown;
15
21
  };
16
22
  export type EventContext<T extends {
17
23
  data: {
@@ -20,5 +26,5 @@ export type EventContext<T extends {
20
26
  }> = Parameters<CallbackEventHandler[T['data']['name']]>;
21
27
  export interface ClientEvent {
22
28
  data: ClientDataEvent;
23
- run(...args: EventContext<any>): any;
29
+ run(...args: EventContext<any>): Awaitable<unknown>;
24
30
  }
@@ -1,7 +1,9 @@
1
1
  import type { Client, WorkerClient } from '../client';
2
+ import type { BaseClient } from '../client/base';
3
+ import { type PluginOrderedContribution } from '../client/plugins/order';
2
4
  import type { UsingClient } from '../commands';
3
5
  import type { FileLoaded } from '../commands/handler';
4
- import { BaseHandler, type CamelCase, type MakeRequired, type SnakeCase } from '../common';
6
+ import { type Awaitable, BaseHandler, type CamelCase, type MakeRequired, type SnakeCase } from '../common';
5
7
  import type { ClientEvents } from '../events/hooks';
6
8
  import { type GatewayDispatchPayload } from '../types';
7
9
  import type { ClientEvent, ClientNameEvents, CustomEvents, CustomEventsKeys, EventContext } from './event';
@@ -29,23 +31,66 @@ export type ResolveEventRunParams<T extends ClientNameEvents | CustomEventsKeys
29
31
  }> : never;
30
32
  export type EventValues = {
31
33
  [K in CustomEventsKeys | GatewayEvents]: Omit<EventValue, 'run'> & {
32
- run(...args: ResolveEventRunParams<K>): any;
34
+ run(...args: ResolveEventRunParams<K>): Awaitable<unknown>;
33
35
  };
34
36
  };
35
- export declare class EventHandler extends BaseHandler {
37
+ export interface CustomEventRunner {
38
+ emit<T extends CustomEventsKeys>(name: T, ...args: ResolveEventRunParams<T>): Awaitable<void>;
39
+ runCustom<T extends CustomEventsKeys>(name: T, ...args: ResolveEventRunParams<T>): Awaitable<void>;
40
+ }
41
+ type PluginEventListener = PluginOrderedContribution & {
42
+ record: {
43
+ plugin: {
44
+ name: string;
45
+ instanceId?: string;
46
+ };
47
+ index: number;
48
+ };
49
+ name: string;
50
+ handler: (...args: unknown[]) => unknown;
51
+ active: boolean;
52
+ once?: boolean;
53
+ fired?: boolean;
54
+ };
55
+ type PluginAnyEventListener = PluginOrderedContribution & {
56
+ record: {
57
+ plugin: {
58
+ name: string;
59
+ instanceId?: string;
60
+ };
61
+ index: number;
62
+ };
63
+ handler: (name: string, ...args: unknown[]) => unknown;
64
+ active: boolean;
65
+ };
66
+ type ClientWithPluginRegistry = BaseClient;
67
+ export declare class CustomEventHandler extends BaseHandler implements CustomEventRunner {
68
+ protected client: ClientWithPluginRegistry;
69
+ constructor(client: ClientWithPluginRegistry);
70
+ onFail: (event: GatewayEvents | CustomEventsKeys | string, err: unknown) => void;
71
+ values: Partial<EventValues>;
72
+ emit<T extends CustomEventsKeys>(name: T, ...args: ResolveEventRunParams<T>): Promise<void>;
73
+ runCustom<T extends CustomEventsKeys>(name: T, ...args: ResolveEventRunParams<T>): Promise<void>;
74
+ protected getPluginListeners(name: string): import("../client/plugins/registry").PluginEventContribution[];
75
+ protected getPluginAnyListeners(): import("../client/plugins/registry").PluginAnyEventContribution[];
76
+ protected getPluginErrorListeners(): import("../client/plugins/registry").PluginEventErrorContribution[];
77
+ protected runCollectors(name: string, args: unknown): unknown;
78
+ protected createPluginListenerTask(name: string, listeners: readonly PluginEventListener[], anyListeners: readonly PluginAnyEventListener[], args: readonly unknown[]): Promise<void> | undefined;
79
+ protected settleEventTasks(name: GatewayEvents | CustomEventsKeys | string, tasks: readonly Promise<unknown>[]): Promise<void>;
80
+ protected reportEventFailure(name: GatewayEvents | CustomEventsKeys | string, error: unknown): Promise<void>;
81
+ }
82
+ export declare class EventHandler extends CustomEventHandler {
36
83
  protected client: Client | WorkerClient;
37
84
  constructor(client: Client | WorkerClient);
38
- onFail: (event: GatewayEvents | CustomEventsKeys, err: unknown) => void;
39
85
  filter: (path: string) => boolean;
40
- values: Partial<EventValues>;
41
86
  discordEvents: ClientNameEvents[];
42
87
  set(events: ClientEvent[]): void;
43
88
  load(eventsDir: string): Promise<void>;
44
89
  execute(raw: GatewayDispatchPayload, client: Client<true> | WorkerClient<true>, shardId: number): Promise<void>;
45
90
  runEvent(name: GatewayEvents, client: Client | WorkerClient, packet: unknown, shardId: number, runCache?: boolean): Promise<void>;
46
- runCustom<T extends CustomEventsKeys>(name: T, ...args: ResolveEventRunParams<T>): Promise<void>;
47
91
  reload(name: GatewayEvents | CustomEventsKeys): Promise<any>;
48
92
  reloadAll(stopIfFail?: boolean): Promise<void>;
49
93
  onFile(file: FileLoaded<ClientEvent>): ClientEvent[] | undefined;
50
94
  callback: (file: ClientEvent) => ClientEvent | false;
51
95
  }
96
+ export {};
@@ -33,19 +33,141 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.EventHandler = void 0;
36
+ exports.EventHandler = exports.CustomEventHandler = void 0;
37
+ const errors_1 = require("../client/plugins/errors");
38
+ const order_1 = require("../client/plugins/order");
37
39
  const common_1 = require("../common");
38
40
  const RawEvents = __importStar(require("../events/hooks"));
41
+ const utils_1 = require("../events/utils");
39
42
  const types_1 = require("../types");
40
- class EventHandler extends common_1.BaseHandler {
43
+ class CustomEventHandler extends common_1.BaseHandler {
41
44
  client;
42
45
  constructor(client) {
43
46
  super(client.logger);
44
47
  this.client = client;
45
48
  }
46
49
  onFail = (event, err) => this.logger.warn('<Client>.events.onFail', err, event);
47
- filter = (path) => path.endsWith('.js') || (!path.endsWith('.d.ts') && path.endsWith('.ts'));
48
50
  values = {};
51
+ emit(name, ...args) {
52
+ return this.runCustom(name, ...args);
53
+ }
54
+ async runCustom(name, ...args) {
55
+ const listeners = this.getPluginListeners(name);
56
+ const anyListeners = this.getPluginAnyListeners();
57
+ const Event = this.values[name];
58
+ try {
59
+ if ((!Event || (Event.data.once && Event.fired)) && !listeners.length && !anyListeners.length) {
60
+ await this.runCollectors(name, args);
61
+ return;
62
+ }
63
+ this.client.debugger?.debug(`executed a custom event [${name}]`, Event?.data.once ? 'once' : '');
64
+ const tasks = [];
65
+ const collectors = this.runCollectors(name, args);
66
+ if (collectors)
67
+ tasks.push(Promise.resolve(collectors));
68
+ if (Event && !(Event.data.once && Event.fired)) {
69
+ if (Event.data.once) {
70
+ Event.fired = true;
71
+ tasks.push(Promise.resolve()
72
+ .then(() => Event.run(...args, this.client))
73
+ .catch(error => {
74
+ Event.fired = false;
75
+ throw error;
76
+ }));
77
+ }
78
+ else {
79
+ tasks.push(Promise.resolve(Event.run(...args, this.client)));
80
+ }
81
+ }
82
+ const pluginTask = this.createPluginListenerTask(name, listeners, anyListeners, [...args, this.client]);
83
+ if (pluginTask)
84
+ tasks.push(pluginTask);
85
+ await this.settleEventTasks(name, tasks);
86
+ }
87
+ catch (e) {
88
+ await this.reportEventFailure(name, e);
89
+ }
90
+ }
91
+ getPluginListeners(name) {
92
+ const normalized = (0, utils_1.normalizeEventName)(name);
93
+ return ((0, order_1.orderedPluginContributions)((this.client.pluginRegistry?.events ?? []).filter(listener => listener.active && (0, utils_1.normalizeEventName)(listener.name) === normalized)) ?? []);
94
+ }
95
+ getPluginAnyListeners() {
96
+ return (0, order_1.orderedPluginContributions)((this.client.pluginRegistry?.anyEvents ?? []).filter(listener => listener.active));
97
+ }
98
+ getPluginErrorListeners() {
99
+ return (0, order_1.orderedPluginContributions)((this.client.pluginRegistry?.eventErrors ?? []).filter(listener => listener.active));
100
+ }
101
+ runCollectors(name, args) {
102
+ return this.client.collectors?.run(name, args, this.client);
103
+ }
104
+ // Plugin listeners are additive and ordered as one sequence across exact and onAny listeners.
105
+ createPluginListenerTask(name, listeners, anyListeners, args) {
106
+ const entries = [
107
+ ...listeners.map(listener => ({
108
+ listener,
109
+ listenerKind: 'event',
110
+ order: listener.order,
111
+ sequence: listener.sequence,
112
+ })),
113
+ ...anyListeners.map(listener => ({
114
+ listener,
115
+ listenerKind: 'any',
116
+ order: listener.order,
117
+ sequence: listener.sequence,
118
+ })),
119
+ ];
120
+ const ordered = (0, order_1.orderedPluginContributions)(entries);
121
+ if (!ordered.length)
122
+ return;
123
+ return Promise.resolve().then(async () => {
124
+ for (const entry of ordered) {
125
+ try {
126
+ if (entry.listenerKind === 'event') {
127
+ const listener = entry.listener;
128
+ if (listener.once && listener.fired)
129
+ continue;
130
+ listener.fired = true;
131
+ await listener.handler(...args);
132
+ }
133
+ else {
134
+ await entry.listener.handler(name, ...args);
135
+ }
136
+ }
137
+ catch (error) {
138
+ const listener = entry.listener;
139
+ await this.reportEventFailure(name, (0, errors_1.wrapPluginError)(listener.record.plugin.name, `event:${name}`, listener.record.index, error, undefined, listener.record.plugin.instanceId));
140
+ }
141
+ }
142
+ });
143
+ }
144
+ async settleEventTasks(name, tasks) {
145
+ const results = await Promise.allSettled(tasks);
146
+ await Promise.all(results.map(async (result) => {
147
+ if (result.status === 'rejected')
148
+ await this.reportEventFailure(name, result.reason);
149
+ }));
150
+ }
151
+ async reportEventFailure(name, error) {
152
+ await Promise.all(this.getPluginErrorListeners().map(async (listener) => {
153
+ try {
154
+ await listener.handler(error, String(name));
155
+ }
156
+ catch (observerError) {
157
+ this.logger.warn('<Client>.events.onError', observerError, name);
158
+ }
159
+ }));
160
+ await this.onFail(name, error);
161
+ }
162
+ }
163
+ exports.CustomEventHandler = CustomEventHandler;
164
+ class EventHandler extends CustomEventHandler {
165
+ client;
166
+ constructor(client) {
167
+ super(client);
168
+ this.client = client;
169
+ }
170
+ filter = (path) => path.endsWith('.js') || (!path.endsWith('.d.ts') && path.endsWith('.ts'));
49
171
  discordEvents = Object.keys(RawEvents).map(x => common_1.ReplaceRegex.camel(x.toLowerCase()));
50
172
  set(events) {
51
173
  for (const event of events) {
@@ -53,12 +175,10 @@ class EventHandler extends common_1.BaseHandler {
53
175
  if (!instance)
54
176
  continue;
55
177
  if (typeof instance?.run !== 'function') {
56
- this.logger.warn('Missing event run function');
178
+ this.logger.warn(`Event "${instance.data?.name ?? 'unknown'}" is missing a 'run' function, ignoring it.`);
57
179
  continue;
58
180
  }
59
- this.values[this.discordEvents.includes(instance.data.name)
60
- ? common_1.ReplaceRegex.snake(instance.data.name).toUpperCase()
61
- : instance.data.name] = instance;
181
+ this.values[(0, utils_1.normalizeEventName)(instance.data.name)] = instance;
62
182
  }
63
183
  }
64
184
  async load(eventsDir) {
@@ -70,7 +190,7 @@ class EventHandler extends common_1.BaseHandler {
70
190
  if (!events)
71
191
  continue;
72
192
  for (const i of events) {
73
- const instance = this.callback(i);
193
+ const instance = this.callback(this.client.runPluginHandlerTransformers('event', i));
74
194
  if (!instance)
75
195
  continue;
76
196
  if (typeof instance?.run !== 'function') {
@@ -78,9 +198,8 @@ class EventHandler extends common_1.BaseHandler {
78
198
  continue;
79
199
  }
80
200
  instance.__filePath = file.path;
81
- this.values[this.discordEvents.includes(instance.data.name)
82
- ? common_1.ReplaceRegex.snake(instance.data.name).toUpperCase()
83
- : instance.data.name] = instance;
201
+ this.values[(0, utils_1.normalizeEventName)(instance.data.name)] =
202
+ instance;
84
203
  }
85
204
  }
86
205
  }
@@ -166,9 +285,11 @@ class EventHandler extends common_1.BaseHandler {
166
285
  ]);
167
286
  }
168
287
  async runEvent(name, client, packet, shardId, runCache = true) {
288
+ const listeners = this.getPluginListeners(name);
289
+ const anyListeners = this.getPluginAnyListeners();
169
290
  const Event = this.values[name];
170
291
  try {
171
- if (!Event || (Event.data.once && Event.fired)) {
292
+ if ((!Event || (Event.data.once && Event.fired)) && !listeners.length && !anyListeners.length) {
172
293
  return runCache
173
294
  ? this.client.cache.onPacket({
174
295
  t: name,
@@ -176,40 +297,48 @@ class EventHandler extends common_1.BaseHandler {
176
297
  })
177
298
  : undefined;
178
299
  }
179
- Event.fired = true;
180
- const hook = await RawEvents[name]?.(client, packet);
300
+ let hook = packet;
301
+ let transformed = false;
302
+ try {
303
+ hook = await (0, utils_1.resolveRawEventData)(name, client, packet);
304
+ transformed = true;
305
+ }
306
+ catch (error) {
307
+ await this.reportEventFailure(name, error);
308
+ }
181
309
  if (runCache)
182
310
  await this.client.cache.onPacket({
183
311
  t: name,
184
312
  d: packet,
185
313
  });
186
- await Event.run(hook, client, shardId);
187
- }
188
- catch (e) {
189
- await this.onFail(name, e);
190
- }
191
- }
192
- async runCustom(name, ...args) {
193
- const Event = this.values[name];
194
- try {
195
- if (!Event || (Event.data.once && Event.fired)) {
196
- // @ts-expect-error
197
- return this.client.collectors.run(name, args, this.client);
314
+ const tasks = [];
315
+ if (transformed && Event && !(Event.data.once && Event.fired)) {
316
+ if (Event.data.once) {
317
+ Event.fired = true;
318
+ tasks.push(Promise.resolve()
319
+ .then(() => Event.run(hook, client, shardId))
320
+ .catch(error => {
321
+ Event.fired = false;
322
+ throw error;
323
+ }));
324
+ }
325
+ else {
326
+ tasks.push(Promise.resolve(Event.run(hook, client, shardId)));
327
+ }
328
+ }
329
+ if (transformed) {
330
+ const pluginTask = this.createPluginListenerTask(name, listeners, anyListeners, [hook, client, shardId]);
331
+ if (pluginTask)
332
+ tasks.push(pluginTask);
198
333
  }
199
- Event.fired = true;
200
- this.client.debugger?.debug(`executed a custom event [${name}]`, Event.data.once ? 'once' : '');
201
- await Promise.all([
202
- Event.run(...args, this.client),
203
- // @ts-expect-error
204
- this.client.collectors.run(name, args, this.client),
205
- ]);
334
+ await this.settleEventTasks(name, tasks);
206
335
  }
207
336
  catch (e) {
208
- await this.onFail(name, e);
337
+ await this.reportEventFailure(name, e);
209
338
  }
210
339
  }
211
340
  async reload(name) {
212
- if ((0, common_1.isCloudfareWorker)()) {
341
+ if ((0, common_1.isCloudflareWorker)()) {
213
342
  throw new common_1.SeyfertError('RELOAD_NOT_SUPPORTED', {
214
343
  metadata: { detail: 'Reload in Cloudflare worker is not supported' },
215
344
  });
@@ -218,7 +347,7 @@ class EventHandler extends common_1.BaseHandler {
218
347
  if (!event?.__filePath)
219
348
  return null;
220
349
  delete require.cache[event.__filePath];
221
- const imported = await (0, common_1.magicImport)(event.__filePath).then(x => x.default ?? x);
350
+ const imported = this.client.runPluginHandlerTransformers('event', await (0, common_1.magicImport)(event.__filePath).then(x => x.default ?? x));
222
351
  imported.__filePath = event.__filePath;
223
352
  this.values[name] = imported;
224
353
  return imported;
@@ -6,7 +6,7 @@ export declare const APPLICATION_COMMAND_PERMISSIONS_UPDATE: (_self: UsingClient
6
6
  guildId: string;
7
7
  permissions: {
8
8
  id: string;
9
- type: import("../../types").ApplicationCommandPermissionType;
9
+ type: import("../..").ApplicationCommandPermissionType;
10
10
  permission: boolean;
11
11
  }[];
12
12
  };
@@ -4,7 +4,7 @@ import type { GatewayAutoModerationActionExecutionDispatchData, GatewayAutoModer
4
4
  export declare const AUTO_MODERATION_ACTION_EXECUTION: (_self: UsingClient, data: GatewayAutoModerationActionExecutionDispatchData) => {
5
5
  guildId: string;
6
6
  action: {
7
- type: import("../../types").AutoModerationActionType;
7
+ type: import("../..").AutoModerationActionType;
8
8
  metadata?: {
9
9
  channelId?: string | undefined;
10
10
  durationSeconds?: number | undefined;
@@ -12,7 +12,7 @@ export declare const AUTO_MODERATION_ACTION_EXECUTION: (_self: UsingClient, data
12
12
  } | undefined;
13
13
  };
14
14
  ruleId: string;
15
- ruleTriggerType: import("../../types").AutoModerationRuleTriggerType;
15
+ ruleTriggerType: import("../..").AutoModerationRuleTriggerType;
16
16
  userId: string;
17
17
  channelId?: string | undefined;
18
18
  messageId?: string | undefined;