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
@@ -0,0 +1,550 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPluginApi = createPluginApi;
4
+ const errors_1 = require("./errors");
5
+ const order_1 = require("./order");
6
+ const registry_1 = require("./registry");
7
+ const shared_1 = require("./shared");
8
+ const reservedCacheResourceNames = new Set([
9
+ '__logger__',
10
+ '__proto__',
11
+ 'adapter',
12
+ 'bans',
13
+ 'buildCache',
14
+ 'bulkGet',
15
+ 'bulkPatch',
16
+ 'bulkSet',
17
+ 'channels',
18
+ 'constructor',
19
+ 'emojis',
20
+ 'flush',
21
+ 'guilds',
22
+ 'hasChannelsIntent',
23
+ 'hasDirectMessages',
24
+ 'hasGuildExpressionsIntent',
25
+ 'hasGuildMembersIntent',
26
+ 'hasGuildsIntent',
27
+ 'hasIntent',
28
+ 'hasModerationIntent',
29
+ 'hasPresenceUpdates',
30
+ 'hasRolesIntent',
31
+ 'hasVoiceStates',
32
+ 'intents',
33
+ 'members',
34
+ 'messages',
35
+ 'onPacket',
36
+ 'onPacketDefault',
37
+ 'overwrites',
38
+ 'pluginResourceNames',
39
+ 'pluginResourcePacketHandlers',
40
+ 'presences',
41
+ 'prototype',
42
+ 'roles',
43
+ 'stageInstances',
44
+ 'stickers',
45
+ 'users',
46
+ 'voiceStates',
47
+ ]);
48
+ const noReservedPluginKeys = new Set();
49
+ const handlerKinds = new Set(['command', 'component', 'modal', 'event']);
50
+ function createPluginApi(record, registry, scope = 'register') {
51
+ const assertCanMutate = (phase) => {
52
+ if (scope !== 'teardown')
53
+ return;
54
+ throw (0, errors_1.createPluginConflictError)(record.plugin.name, phase, record.index, `Plugin "${record.plugin.name}" cannot mutate plugin contributions during teardown.`, record.plugin.instanceId);
55
+ };
56
+ const addEvent = (name, handler, opts) => {
57
+ assertCanMutate(`events.${String(name)}`);
58
+ const contribution = {
59
+ record,
60
+ name: String(name),
61
+ handler: handler,
62
+ scope,
63
+ active: true,
64
+ order: opts?.order,
65
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
66
+ once: opts?.once,
67
+ };
68
+ registry.events.push(contribution);
69
+ return once(() => (0, registry_1.removePluginEventContribution)(registry, contribution));
70
+ };
71
+ return {
72
+ has(req) {
73
+ return (0, registry_1.hasPluginRequirement)(registry, req);
74
+ },
75
+ events: {
76
+ on(name, handler, opts) {
77
+ return addEvent(name, handler, opts);
78
+ },
79
+ once(name, handler) {
80
+ return addEvent(name, handler, { once: true });
81
+ },
82
+ onAny(handler, opts) {
83
+ assertCanMutate('events.onAny');
84
+ const contribution = {
85
+ record,
86
+ handler,
87
+ scope,
88
+ active: true,
89
+ order: opts?.order,
90
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
91
+ };
92
+ registry.anyEvents.push(contribution);
93
+ return once(() => (0, registry_1.removePluginAnyEventContribution)(registry, contribution));
94
+ },
95
+ onError(handler, opts) {
96
+ assertCanMutate('events.onError');
97
+ const contribution = {
98
+ record,
99
+ handler,
100
+ scope,
101
+ active: true,
102
+ order: opts?.order,
103
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
104
+ };
105
+ registry.eventErrors.push(contribution);
106
+ return once(() => (0, registry_1.removePluginEventErrorContribution)(registry, contribution));
107
+ },
108
+ },
109
+ commands: {
110
+ add(...args) {
111
+ assertCanMutate('commands.add');
112
+ const [commands, opts] = splitContributionArgs(args, isCommandContributionOptions);
113
+ if (opts?.guilds?.length) {
114
+ (0, registry_1.addPluginDiagnostic)(registry, record, {
115
+ phase: 'commands.add',
116
+ severity: 'info',
117
+ code: 'command-guild-scope',
118
+ message: `Plugin "${record.plugin.name}" registered a guild-scoped command contribution.`,
119
+ data: { guilds: [...opts.guilds], commands: commands.length },
120
+ });
121
+ }
122
+ registry.commands.push({
123
+ record,
124
+ commands,
125
+ scope,
126
+ override: opts?.override === true,
127
+ guilds: opts?.guilds ? [...opts.guilds] : undefined,
128
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
129
+ });
130
+ },
131
+ remove(...names) {
132
+ assertCanMutate('commands.remove');
133
+ registry.commandRemovals.push({
134
+ record,
135
+ names,
136
+ scope,
137
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
138
+ });
139
+ },
140
+ observe(observer, opts) {
141
+ assertCanMutate('commands.observe');
142
+ const contribution = {
143
+ record,
144
+ observer,
145
+ scope,
146
+ active: true,
147
+ order: opts?.order,
148
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
149
+ };
150
+ registry.commandObservers.push(contribution);
151
+ return once(() => (0, registry_1.removePluginCommandObserverContribution)(registry, contribution));
152
+ },
153
+ defaults(hooks, opts) {
154
+ assertCanMutate('commands.defaults');
155
+ registry.pluginDefaults.push({
156
+ record,
157
+ kind: 'commands',
158
+ hooks: hooks,
159
+ suppressDefault: opts?.suppressDefault,
160
+ scope,
161
+ order: opts?.order,
162
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
163
+ });
164
+ },
165
+ },
166
+ rest: {
167
+ observe(observer, opts) {
168
+ assertCanMutate('rest.observe');
169
+ const contribution = {
170
+ record,
171
+ observer,
172
+ scope,
173
+ active: true,
174
+ order: opts?.order,
175
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
176
+ };
177
+ registry.restObservers.push(contribution);
178
+ return once(() => (0, registry_1.removePluginRestObserverContribution)(registry, contribution));
179
+ },
180
+ },
181
+ hooks: {
182
+ on(name, handler, opts) {
183
+ assertCanMutate(`hooks.${name}`);
184
+ const contribution = {
185
+ record,
186
+ name,
187
+ handler: handler,
188
+ scope,
189
+ active: true,
190
+ order: opts?.order,
191
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
192
+ };
193
+ registry.hooks.push(contribution);
194
+ return once(() => (0, registry_1.removePluginHookContribution)(registry, contribution));
195
+ },
196
+ },
197
+ handlers: {
198
+ construct(creator, opts) {
199
+ assertCanMutate('handlers.construct');
200
+ registry.handlerCreators.push({
201
+ record,
202
+ creator,
203
+ scope,
204
+ kinds: normalizeHandlerKinds(record, opts, false),
205
+ order: opts?.order,
206
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
207
+ });
208
+ },
209
+ transform(transformer, opts) {
210
+ assertCanMutate('handlers.transform');
211
+ registry.handlerTransformers.push({
212
+ record,
213
+ transformer,
214
+ scope,
215
+ kinds: normalizeHandlerKinds(record, opts),
216
+ order: opts?.order,
217
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
218
+ });
219
+ },
220
+ },
221
+ components: {
222
+ add(...args) {
223
+ assertCanMutate('components.add');
224
+ const [components, opts] = splitContributionArgs(args);
225
+ registry.components.push({
226
+ record,
227
+ components,
228
+ scope,
229
+ override: opts?.override === true,
230
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
231
+ });
232
+ },
233
+ remove(...customIds) {
234
+ assertCanMutate('components.remove');
235
+ registry.componentRemovals.push({
236
+ record,
237
+ customIds,
238
+ scope,
239
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
240
+ });
241
+ },
242
+ defaults(hooks, opts) {
243
+ assertCanMutate('components.defaults');
244
+ registry.pluginDefaults.push({
245
+ record,
246
+ kind: 'components',
247
+ hooks: hooks,
248
+ suppressDefault: opts?.suppressDefault,
249
+ scope,
250
+ order: opts?.order,
251
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
252
+ });
253
+ },
254
+ },
255
+ modals: {
256
+ add(...args) {
257
+ assertCanMutate('modals.add');
258
+ const [modals, opts] = splitContributionArgs(args);
259
+ registry.modals.push({
260
+ record,
261
+ modals,
262
+ scope,
263
+ override: opts?.override === true,
264
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
265
+ });
266
+ },
267
+ remove(...customIds) {
268
+ assertCanMutate('modals.remove');
269
+ registry.modalRemovals.push({
270
+ record,
271
+ customIds,
272
+ scope,
273
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
274
+ });
275
+ },
276
+ defaults(hooks, opts) {
277
+ assertCanMutate('modals.defaults');
278
+ registry.pluginDefaults.push({
279
+ record,
280
+ kind: 'modals',
281
+ hooks: hooks,
282
+ suppressDefault: opts?.suppressDefault,
283
+ scope,
284
+ order: opts?.order,
285
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
286
+ });
287
+ },
288
+ },
289
+ middlewares: {
290
+ add(name, middleware, opts) {
291
+ assertCanMutate(`middlewares.${name}`);
292
+ (0, registry_1.assertSafePluginResourceName)(record, `middlewares.${name}`, name, noReservedPluginKeys);
293
+ registry.middlewares.push({
294
+ record,
295
+ name,
296
+ middleware,
297
+ global: opts?.global === true,
298
+ override: opts?.override === true,
299
+ scope,
300
+ order: opts?.order,
301
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
302
+ });
303
+ if (opts?.global) {
304
+ (0, registry_1.addPluginOptionFragment)(registry, record, {
305
+ globalMiddlewares: [name],
306
+ }, scope);
307
+ }
308
+ },
309
+ remove(...names) {
310
+ assertCanMutate('middlewares.remove');
311
+ for (const name of names) {
312
+ (0, registry_1.assertSafePluginResourceName)(record, `middlewares.${name}`, name, noReservedPluginKeys);
313
+ }
314
+ registry.middlewareRemovals.push({
315
+ record,
316
+ names,
317
+ scope,
318
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
319
+ });
320
+ },
321
+ },
322
+ autocomplete: {
323
+ wrap(wrapper, opts) {
324
+ assertCanMutate('autocomplete.wrap');
325
+ registry.autocompleteWrappers.push({
326
+ record,
327
+ wrapper,
328
+ scope,
329
+ order: opts?.order,
330
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
331
+ });
332
+ },
333
+ },
334
+ gateway: {
335
+ addIntents(...intents) {
336
+ assertCanMutate('gateway.addIntents');
337
+ const resolvedIntents = [];
338
+ for (const intent of intents) {
339
+ const resolved = (0, registry_1.resolveGatewayIntent)(intent);
340
+ if (resolved === undefined) {
341
+ (0, registry_1.addPluginDiagnostic)(registry, record, {
342
+ phase: 'gateway.addIntents',
343
+ severity: 'warn',
344
+ code: 'unknown-intent-bits',
345
+ message: `Gateway intent "${String(intent)}" is unknown.`,
346
+ data: { intent },
347
+ });
348
+ continue;
349
+ }
350
+ const unknownBits = (0, registry_1.unknownGatewayIntentBits)(resolved);
351
+ if (unknownBits) {
352
+ (0, registry_1.addPluginDiagnostic)(registry, record, {
353
+ phase: 'gateway.addIntents',
354
+ severity: 'warn',
355
+ code: 'unknown-intent-bits',
356
+ message: `Gateway intent value "${resolved}" includes unknown bits "${unknownBits}".`,
357
+ data: { intent: resolved, unknownBits },
358
+ });
359
+ }
360
+ resolvedIntents.push(resolved);
361
+ }
362
+ if (resolvedIntents.length)
363
+ registry.gatewayIntents.push({ record, intents: resolvedIntents, scope });
364
+ },
365
+ wrapSendPayload(wrapper, opts) {
366
+ assertCanMutate('gateway.wrapSendPayload');
367
+ registry.gatewaySendPayloadWrappers.push({
368
+ record,
369
+ wrapper,
370
+ scope,
371
+ order: opts?.order,
372
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
373
+ });
374
+ },
375
+ onDispatch(interceptor, opts) {
376
+ assertCanMutate('gateway.onDispatch');
377
+ const contribution = {
378
+ record,
379
+ interceptor,
380
+ scope,
381
+ order: opts?.order,
382
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
383
+ };
384
+ registry.gatewayDispatchInterceptors.push(contribution);
385
+ return once(() => (0, registry_1.removePluginGatewayDispatchInterceptorContribution)(registry, contribution));
386
+ },
387
+ },
388
+ cache: {
389
+ resource(name, resource, opts) {
390
+ assertCanMutate('cache.resource');
391
+ (0, registry_1.assertSafePluginResourceName)(record, 'cache.resource', name, reservedCacheResourceNames);
392
+ const existing = registry.cacheResources.find(contribution => contribution.name === name);
393
+ if (existing) {
394
+ throw (0, errors_1.createPluginConflictError)(record.plugin.name, 'cache.resource', record.index, `Cache resource "${name}" is already registered by plugin "${existing.record.identity}".`, record.plugin.instanceId);
395
+ }
396
+ if (opts?.intents?.length) {
397
+ const resolvedIntents = [];
398
+ for (const intent of opts.intents) {
399
+ const resolved = (0, registry_1.resolveGatewayIntent)(intent);
400
+ if (resolved === undefined) {
401
+ (0, registry_1.addPluginDiagnostic)(registry, record, {
402
+ phase: 'cache.resource',
403
+ severity: 'warn',
404
+ code: 'unknown-intent-bits',
405
+ message: `Gateway intent "${String(intent)}" is unknown.`,
406
+ data: { intent },
407
+ });
408
+ continue;
409
+ }
410
+ const unknownBits = (0, registry_1.unknownGatewayIntentBits)(resolved);
411
+ if (unknownBits) {
412
+ (0, registry_1.addPluginDiagnostic)(registry, record, {
413
+ phase: 'cache.resource',
414
+ severity: 'warn',
415
+ code: 'unknown-intent-bits',
416
+ message: `Gateway intent value "${resolved}" includes unknown bits "${unknownBits}".`,
417
+ data: { intent: resolved, unknownBits },
418
+ });
419
+ }
420
+ resolvedIntents.push(resolved);
421
+ }
422
+ if (resolvedIntents.length)
423
+ registry.gatewayIntents.push({ record, intents: resolvedIntents, scope });
424
+ }
425
+ registry.cacheResources.push({
426
+ record,
427
+ name,
428
+ resource,
429
+ scope,
430
+ onPacket: opts?.onPacket,
431
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
432
+ });
433
+ },
434
+ },
435
+ shared: {
436
+ set(name, factory, opts) {
437
+ assertCanMutate(`shared.${(0, shared_1.sharedName)(name)}`);
438
+ const key = (0, shared_1.sharedName)(name);
439
+ (0, registry_1.assertSafePluginResourceName)(record, `shared.${key}`, key, noReservedPluginKeys);
440
+ (0, shared_1.addPluginShared)(registry, record, key, factory, scope, opts);
441
+ },
442
+ remove(...names) {
443
+ assertCanMutate('shared.remove');
444
+ const keys = names.map(shared_1.sharedName);
445
+ for (const key of keys)
446
+ (0, registry_1.assertSafePluginResourceName)(record, `shared.${key}`, key, noReservedPluginKeys);
447
+ (0, shared_1.removePluginShared)(registry, record, keys, scope);
448
+ },
449
+ has(name) {
450
+ return registry.shared.has((0, shared_1.sharedName)(name));
451
+ },
452
+ },
453
+ langs: {
454
+ contribute(locale, values, options) {
455
+ assertCanMutate('langs.contribute');
456
+ if (!isValidLangPrefix(options?.prefix)) {
457
+ throw (0, errors_1.createPluginConflictError)(record.plugin.name, 'langs.contribute', record.index, 'langs.contribute locale prefix must contain at least one non-empty path segment.', record.plugin.instanceId);
458
+ }
459
+ registry.langs.push({
460
+ record,
461
+ locale,
462
+ prefix: options.prefix,
463
+ values,
464
+ scope,
465
+ sequence: (0, order_1.nextPluginContributionSequence)(registry),
466
+ });
467
+ },
468
+ },
469
+ reload() {
470
+ assertCanMutate('reload');
471
+ const client = registry.client;
472
+ if (!client) {
473
+ throw (0, errors_1.createPluginConflictError)(record.plugin.name, 'reload', record.index, `Plugin "${record.plugin.name}" cannot reload before the client is available.`, record.plugin.instanceId);
474
+ }
475
+ return client.reloadPluginContributions();
476
+ },
477
+ diagnostics: {
478
+ warn(message, options) {
479
+ (0, registry_1.addPluginDiagnostic)(registry, record, {
480
+ phase: options?.phase ?? 'register',
481
+ severity: 'warn',
482
+ code: options?.code,
483
+ message,
484
+ data: options?.data,
485
+ });
486
+ },
487
+ },
488
+ options: {
489
+ set(fragment) {
490
+ assertCanMutate('options.set');
491
+ (0, registry_1.addPluginOptionFragment)(registry, record, fragment, scope);
492
+ },
493
+ },
494
+ };
495
+ }
496
+ function once(dispose) {
497
+ let disposed = false;
498
+ return () => {
499
+ if (disposed)
500
+ return;
501
+ disposed = true;
502
+ dispose();
503
+ };
504
+ }
505
+ function normalizeHandlerKinds(record, opts, allowEvent = true) {
506
+ if (!opts?.kinds)
507
+ return undefined;
508
+ for (const kind of opts.kinds) {
509
+ if (kind === 'event' && !allowEvent) {
510
+ throw (0, errors_1.createPluginConflictError)(record.plugin.name, 'handlers.kinds', record.index, 'Events have no construction step; use handlers.transform with kinds:["event"].', record.plugin.instanceId);
511
+ }
512
+ if (handlerKinds.has(kind))
513
+ continue;
514
+ throw (0, errors_1.createPluginConflictError)(record.plugin.name, 'handlers.kinds', record.index, `Handler kind "${String(kind)}" is invalid.`, record.plugin.instanceId);
515
+ }
516
+ return [...opts.kinds];
517
+ }
518
+ function isValidLangPrefix(prefix) {
519
+ if (!prefix)
520
+ return false;
521
+ return prefix.split('.').some(segment => segment.length > 0);
522
+ }
523
+ function splitContributionArgs(args, isOptions = isPlainContributionOptions) {
524
+ const last = args.at(-1);
525
+ if (isOptions(last))
526
+ return [args.slice(0, -1), last];
527
+ return [args, undefined];
528
+ }
529
+ function isPlainContributionOptions(value) {
530
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
531
+ return false;
532
+ const prototype = Object.getPrototypeOf(value);
533
+ if (prototype !== Object.prototype && prototype !== null)
534
+ return false;
535
+ return Object.keys(value).every(key => key === 'override');
536
+ }
537
+ function isCommandContributionOptions(value) {
538
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
539
+ return false;
540
+ const prototype = Object.getPrototypeOf(value);
541
+ if (prototype !== Object.prototype && prototype !== null)
542
+ return false;
543
+ return Object.entries(value).every(([key, option]) => {
544
+ if (key === 'override')
545
+ return typeof option === 'boolean';
546
+ if (key === 'guilds')
547
+ return Array.isArray(option) && option.every(guild => typeof guild === 'string');
548
+ return false;
549
+ });
550
+ }
@@ -0,0 +1,25 @@
1
+ import { SeyfertError, type SeyfertErrorCode } from '../../common/it/error';
2
+ export type SeyfertPluginErrorCode = 'PLUGIN_FAILED' | 'PLUGIN_TEARDOWN_FAILED';
3
+ export declare class SeyfertPluginError extends SeyfertError {
4
+ readonly plugin: string;
5
+ readonly instanceId?: string;
6
+ readonly phase: string;
7
+ readonly index: number;
8
+ constructor(plugin: string, phase: string, index: number, cause: unknown, code?: SeyfertPluginErrorCode, instanceId?: string);
9
+ }
10
+ export declare class SeyfertPluginAggregateError extends SeyfertError {
11
+ name: string;
12
+ readonly errors: unknown[];
13
+ cause: unknown;
14
+ constructor(code: SeyfertPluginErrorCode, plugin: string, phase: string, index: number, errors: Iterable<unknown>, message?: string, cause?: unknown, instanceId?: string);
15
+ toJSON(): {
16
+ name: string;
17
+ message: string;
18
+ code: SeyfertErrorCode;
19
+ metadata: Record<string, unknown> | undefined;
20
+ cause: unknown;
21
+ errors: unknown[];
22
+ };
23
+ }
24
+ export declare function wrapPluginError(plugin: string, phase: string, index: number, cause: unknown, code?: SeyfertPluginErrorCode, instanceId?: string): SeyfertPluginError | SeyfertPluginAggregateError;
25
+ export declare function createPluginConflictError(plugin: string, phase: string, index: number, detail: string, instanceId?: string): SeyfertPluginError | SeyfertPluginAggregateError;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SeyfertPluginAggregateError = exports.SeyfertPluginError = void 0;
4
+ exports.wrapPluginError = wrapPluginError;
5
+ exports.createPluginConflictError = createPluginConflictError;
6
+ const error_1 = require("../../common/it/error");
7
+ class SeyfertPluginError extends error_1.SeyfertError {
8
+ plugin;
9
+ instanceId;
10
+ phase;
11
+ index;
12
+ constructor(plugin, phase, index, cause, code = 'PLUGIN_FAILED', instanceId) {
13
+ super(code, { metadata: pluginMetadata(plugin, phase, index, instanceId), cause });
14
+ this.name = 'SeyfertPluginError';
15
+ this.plugin = plugin;
16
+ this.instanceId = instanceId;
17
+ this.phase = phase;
18
+ this.index = index;
19
+ this.message = `Seyfert plugin "${formatPluginIdentity(plugin, instanceId)}" failed during ${phase} at index ${index}: ${formatPluginCause(cause)}`;
20
+ Error.captureStackTrace?.(this, SeyfertPluginError);
21
+ }
22
+ }
23
+ exports.SeyfertPluginError = SeyfertPluginError;
24
+ class SeyfertPluginAggregateError extends error_1.SeyfertError {
25
+ name = 'SeyfertPluginAggregateError';
26
+ errors;
27
+ cause;
28
+ constructor(code, plugin, phase, index, errors, message, cause, instanceId) {
29
+ const collected = Array.from(errors);
30
+ const resolvedCause = cause ?? causeOf(collected[0]);
31
+ super(code, { metadata: pluginMetadata(plugin, phase, index, instanceId), cause: resolvedCause });
32
+ this.message = message ?? resolvePluginAggregateMessage(code);
33
+ this.errors = collected;
34
+ this.cause = resolvedCause;
35
+ Error.captureStackTrace?.(this, SeyfertPluginAggregateError);
36
+ }
37
+ toJSON() {
38
+ return {
39
+ name: this.name,
40
+ message: this.message,
41
+ code: this.code,
42
+ metadata: this.metadata,
43
+ cause: this.cause,
44
+ errors: this.errors,
45
+ };
46
+ }
47
+ }
48
+ exports.SeyfertPluginAggregateError = SeyfertPluginAggregateError;
49
+ function wrapPluginError(plugin, phase, index, cause, code, instanceId) {
50
+ if (cause instanceof SeyfertPluginError)
51
+ return cause;
52
+ if (cause instanceof SeyfertPluginAggregateError)
53
+ return cause;
54
+ return new SeyfertPluginError(plugin, phase, index, cause, code, instanceId);
55
+ }
56
+ function createPluginConflictError(plugin, phase, index, detail, instanceId) {
57
+ return wrapPluginError(plugin, phase, index, new Error(detail), undefined, instanceId);
58
+ }
59
+ function formatPluginCause(cause) {
60
+ if (cause instanceof Error)
61
+ return cause.message;
62
+ return String(cause);
63
+ }
64
+ function formatPluginIdentity(plugin, instanceId) {
65
+ return instanceId ? `${plugin}#${instanceId}` : plugin;
66
+ }
67
+ function pluginMetadata(plugin, phase, index, instanceId) {
68
+ if (instanceId)
69
+ return { plugin, instanceId, phase, index };
70
+ return { plugin, phase, index };
71
+ }
72
+ function causeOf(error) {
73
+ if (error && typeof error === 'object' && 'cause' in error)
74
+ return error.cause ?? error;
75
+ return error;
76
+ }
77
+ function resolvePluginAggregateMessage(code) {
78
+ return code === 'PLUGIN_TEARDOWN_FAILED' ? 'Seyfert plugin teardown failed.' : 'Seyfert plugin failed.';
79
+ }
@@ -0,0 +1,10 @@
1
+ import { type PluginOrderOpt } from './types';
2
+ export interface PluginOrderedContribution {
3
+ order?: PluginOrderOpt;
4
+ sequence: number;
5
+ }
6
+ export interface PluginOrderSequence {
7
+ nextContributionSequence: number;
8
+ }
9
+ export declare function nextPluginContributionSequence(sequence: PluginOrderSequence): number;
10
+ export declare function orderedPluginContributions<T extends PluginOrderedContribution>(contributions: readonly T[]): T[];