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
@@ -12,7 +12,6 @@ exports.resolveImage = resolveImage;
12
12
  const node_crypto_1 = require("node:crypto");
13
13
  const node_fs_1 = require("node:fs");
14
14
  const node_path_1 = __importDefault(require("node:path"));
15
- const utils_1 = require("../api/utils/utils");
16
15
  const common_1 = require("../common");
17
16
  const Base_1 = require("../structures/extra/Base");
18
17
  class Attachment extends Base_1.Base {
@@ -178,6 +177,14 @@ async function resolveAttachmentData(data, type) {
178
177
  },
179
178
  });
180
179
  const res = await fetch(data);
180
+ if (!res.ok) {
181
+ throw new common_1.SeyfertError('INVALID_ATTACHMENT_TYPE', {
182
+ metadata: {
183
+ ...(0, common_1.createValidationMetadata)('successful HTTP response', `${res.status} ${res.statusText}`),
184
+ detail: `Failed to fetch attachment from URL: ${res.status} ${res.statusText}`,
185
+ },
186
+ });
187
+ }
181
188
  return {
182
189
  data: Buffer.from(await res.arrayBuffer()),
183
190
  contentType: res.headers.get('content-type'),
@@ -196,8 +203,12 @@ async function resolveAttachmentData(data, type) {
196
203
  return { data: await node_fs_1.promises.readFile(file) };
197
204
  }
198
205
  case 'buffer': {
199
- if ((0, utils_1.isBufferLike)(data))
206
+ if (Buffer.isBuffer(data))
200
207
  return { data };
208
+ if (data instanceof ArrayBuffer)
209
+ return { data: Buffer.from(data) };
210
+ if (data instanceof Uint8Array || data instanceof Uint8ClampedArray)
211
+ return { data: Buffer.from(data) };
201
212
  if (typeof data[Symbol.asyncIterator] === 'function') {
202
213
  const buffers = [];
203
214
  for await (const resource of data)
@@ -226,9 +237,9 @@ async function resolveAttachmentData(data, type) {
226
237
  * @param data - The base64 data.
227
238
  * @returns The resolved data URL.
228
239
  */
229
- function resolveBase64(data) {
240
+ function resolveBase64(data, contentType = 'image/jpeg') {
230
241
  if (Buffer.isBuffer(data))
231
- return `data:image/jpg;base64,${data.toString('base64')}`;
242
+ return `data:${contentType};base64,${data.toString('base64')}`;
232
243
  return data;
233
244
  }
234
245
  /**
@@ -239,8 +250,10 @@ function resolveBase64(data) {
239
250
  async function resolveImage(image) {
240
251
  if (image instanceof AttachmentBuilder) {
241
252
  const { data: { type, resolvable }, } = image;
242
- if (type && resolvable)
243
- return resolveBase64((await resolveAttachmentData(resolvable, type)).data);
253
+ if (type && resolvable) {
254
+ const file = await resolveAttachmentData(resolvable, type);
255
+ return resolveBase64(file.data, file.contentType ?? undefined);
256
+ }
244
257
  throw new common_1.SeyfertError('INVALID_ATTACHMENT_TYPE', {
245
258
  metadata: {
246
259
  ...(0, common_1.createValidationMetadata)('AttachmentBuilder with type and resolvable data', {
@@ -253,8 +266,17 @@ async function resolveImage(image) {
253
266
  }
254
267
  if (image instanceof Attachment) {
255
268
  const response = await fetch(image.url);
256
- return resolveBase64((await resolveAttachmentData(await response.arrayBuffer(), 'buffer')).data);
269
+ if (!response.ok) {
270
+ throw new common_1.SeyfertError('INVALID_ATTACHMENT_TYPE', {
271
+ metadata: {
272
+ ...(0, common_1.createValidationMetadata)('successful HTTP response', `${response.status} ${response.statusText}`),
273
+ detail: `Failed to fetch attachment from URL: ${response.status} ${response.statusText}`,
274
+ },
275
+ });
276
+ }
277
+ const file = await resolveAttachmentData(await response.arrayBuffer(), 'buffer');
278
+ return resolveBase64(file.data, response.headers.get('content-type') ?? file.contentType ?? undefined);
257
279
  }
258
280
  const file = await resolveAttachmentData(image.data, image.type);
259
- return resolveBase64(file.data);
281
+ return resolveBase64(file.data, file.contentType ?? undefined);
260
282
  }
@@ -1,4 +1,4 @@
1
- import type { RestOrArray } from '../common';
1
+ import { type RestOrArray } from '../common';
2
2
  import { type APIMediaGalleryComponent, type APIMediaGalleryItems } from '../types';
3
3
  import { BaseComponentBuilder } from './Base';
4
4
  /**
@@ -73,7 +73,7 @@ export declare class MediaGalleryItem {
73
73
  * @returns The JSON representation of the item data.
74
74
  */
75
75
  toJSON(): {
76
- media?: import("../types").APIUnfurledMediaItem | undefined;
76
+ media?: import("..").APIUnfurledMediaItem | undefined;
77
77
  description?: string | undefined;
78
78
  spoiler?: boolean | undefined;
79
79
  };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MediaGalleryItem = exports.MediaGallery = void 0;
4
+ const common_1 = require("../common");
4
5
  const types_1 = require("../types");
5
6
  const Base_1 = require("./Base");
6
7
  /**
@@ -104,6 +105,15 @@ class MediaGalleryItem {
104
105
  * @returns The JSON representation of the item data.
105
106
  */
106
107
  toJSON() {
108
+ if (!this.data.media)
109
+ throw new common_1.SeyfertError('MISSING_MEDIA', {
110
+ metadata: {
111
+ ...(0, common_1.createValidationMetadata)('media to be set before calling toJSON()', this.data.media, {
112
+ component: 'MediaGalleryItem',
113
+ }),
114
+ detail: 'Cannot convert to JSON without media.',
115
+ },
116
+ });
107
117
  return { ...this.data };
108
118
  }
109
119
  }
@@ -1,4 +1,4 @@
1
- import type { RestOrArray } from '../common';
1
+ import { type RestOrArray } from '../common';
2
2
  import { type APIModalInteractionResponseCallbackData, type APITextInputComponent, type TextInputStyle } from '../types';
3
3
  import { BaseComponentBuilder, type OptionValuesLength } from './Base';
4
4
  import type { ModalBuilderComponents, ModalSubmitCallback } from './types';
@@ -8,10 +8,16 @@ import type { ModalBuilderComponents, ModalSubmitCallback } from './types';
8
8
  * @example
9
9
  * const modal = new Modal();
10
10
  * modal.setTitle("Sample Modal");
11
+ * modal.setCustomId("sample-modal");
11
12
  * modal.addComponents(
12
- * new ActionRow<TextInput>()
13
- * .addComponents(new TextInput().setLabel("Enter text"))
14
- * ));
13
+ * new Label()
14
+ * .setLabel("Enter text")
15
+ * .setComponent(
16
+ * new TextInput()
17
+ * .setCustomId("sample-input")
18
+ * .setStyle(TextInputStyle.Paragraph)
19
+ * )
20
+ * );
15
21
  * modal.run((interaction) => {
16
22
  * // Handle modal submission
17
23
  * });
@@ -64,10 +70,14 @@ export declare class Modal {
64
70
  /**
65
71
  * Represents a text input component builder.
66
72
  * @example
67
- * const textInput = new TextInput().setLabel("Enter text");
68
- * textInput.setStyle(TextInputStyle.Paragraph);
69
- * textInput.setPlaceholder("Type here");
70
- * const json = textInput.toJSON();
73
+ * const textInput = new TextInput()
74
+ * .setCustomId("feedback")
75
+ * .setStyle(TextInputStyle.Paragraph)
76
+ * .setPlaceholder("Type here");
77
+ * const label = new Label()
78
+ * .setLabel("Feedback")
79
+ * .setComponent(textInput);
80
+ * const json = label.toJSON();
71
81
  */
72
82
  export declare class TextInput extends BaseComponentBuilder<APITextInputComponent> {
73
83
  /**
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TextInput = exports.Modal = void 0;
4
+ const common_1 = require("../common");
4
5
  const types_1 = require("../types");
5
6
  const _1 = require(".");
6
7
  const Base_1 = require("./Base");
@@ -10,10 +11,16 @@ const Base_1 = require("./Base");
10
11
  * @example
11
12
  * const modal = new Modal();
12
13
  * modal.setTitle("Sample Modal");
14
+ * modal.setCustomId("sample-modal");
13
15
  * modal.addComponents(
14
- * new ActionRow<TextInput>()
15
- * .addComponents(new TextInput().setLabel("Enter text"))
16
- * ));
16
+ * new Label()
17
+ * .setLabel("Enter text")
18
+ * .setComponent(
19
+ * new TextInput()
20
+ * .setCustomId("sample-input")
21
+ * .setStyle(TextInputStyle.Paragraph)
22
+ * )
23
+ * );
17
24
  * modal.run((interaction) => {
18
25
  * // Handle modal submission
19
26
  * });
@@ -82,6 +89,24 @@ class Modal {
82
89
  * @returns The modal data in JSON format.
83
90
  */
84
91
  toJSON() {
92
+ if (!this.data.custom_id)
93
+ throw new common_1.SeyfertError('MISSING_MODAL_CUSTOM_ID', {
94
+ metadata: {
95
+ ...(0, common_1.createValidationMetadata)('custom_id to be set before calling toJSON()', this.data.custom_id, {
96
+ component: 'Modal',
97
+ }),
98
+ detail: 'Cannot convert to JSON without a custom_id.',
99
+ },
100
+ });
101
+ if (!this.data.title)
102
+ throw new common_1.SeyfertError('MISSING_MODAL_TITLE', {
103
+ metadata: {
104
+ ...(0, common_1.createValidationMetadata)('title to be set before calling toJSON()', this.data.title, {
105
+ component: 'Modal',
106
+ }),
107
+ detail: 'Cannot convert to JSON without a title.',
108
+ },
109
+ });
85
110
  return {
86
111
  custom_id: this.data.custom_id,
87
112
  title: this.data.title,
@@ -93,10 +118,14 @@ exports.Modal = Modal;
93
118
  /**
94
119
  * Represents a text input component builder.
95
120
  * @example
96
- * const textInput = new TextInput().setLabel("Enter text");
97
- * textInput.setStyle(TextInputStyle.Paragraph);
98
- * textInput.setPlaceholder("Type here");
99
- * const json = textInput.toJSON();
121
+ * const textInput = new TextInput()
122
+ * .setCustomId("feedback")
123
+ * .setStyle(TextInputStyle.Paragraph)
124
+ * .setPlaceholder("Type here");
125
+ * const label = new Label()
126
+ * .setLabel("Feedback")
127
+ * .setComponent(textInput);
128
+ * const json = label.toJSON();
100
129
  */
101
130
  class TextInput extends Base_1.BaseComponentBuilder {
102
131
  /**
@@ -33,6 +33,24 @@ class PollBuilder {
33
33
  return this;
34
34
  }
35
35
  toJSON() {
36
+ if (!this.data.question?.text && !this.data.question?.emoji)
37
+ throw new common_1.SeyfertError('MISSING_POLL_QUESTION', {
38
+ metadata: {
39
+ ...(0, common_1.createValidationMetadata)('question to be set before calling toJSON()', this.data.question, {
40
+ component: 'PollBuilder',
41
+ }),
42
+ detail: 'Cannot convert to JSON without a question.',
43
+ },
44
+ });
45
+ if (!this.data.answers?.length)
46
+ throw new common_1.SeyfertError('MISSING_POLL_ANSWERS', {
47
+ metadata: {
48
+ ...(0, common_1.createValidationMetadata)('at least one answer to be set before calling toJSON()', this.data.answers, {
49
+ component: 'PollBuilder',
50
+ }),
51
+ detail: 'Cannot convert to JSON without answers.',
52
+ },
53
+ });
36
54
  return { ...this.data };
37
55
  }
38
56
  resolvedPollMedia(data) {
@@ -16,7 +16,7 @@ export declare class RadioGroup extends BaseComponentBuilder<APIRadioGroupCompon
16
16
  * @returns The current RadioGroup instance.
17
17
  */
18
18
  setCustomId(customId: string): this;
19
- setOptions(options: RestOrArray<RadioGroupOption>): this;
19
+ setOptions(...options: RestOrArray<RadioGroupOption>): this;
20
20
  addOptions(...options: RestOrArray<RadioGroupOption>): this;
21
21
  /**
22
22
  * Sets whether the radio group is required.
@@ -27,8 +27,8 @@ export declare class RadioGroup extends BaseComponentBuilder<APIRadioGroupCompon
27
27
  toJSON(): APIRadioGroupComponent;
28
28
  }
29
29
  export declare class RadioGroupOption {
30
- data: Partial<APIRadioGroupOption>;
31
- constructor(data?: Partial<APIRadioGroupOption>);
30
+ data: APIRadioGroupOption;
31
+ constructor(data: APIRadioGroupOption);
32
32
  /**
33
33
  * Sets the label for the option.
34
34
  * label - The label for the option.
@@ -53,4 +53,5 @@ export declare class RadioGroupOption {
53
53
  * @returns The current RadioGroupOption instance.
54
54
  */
55
55
  setDefault(value?: boolean): this;
56
+ toJSON(): APIRadioGroupOption;
56
57
  }
@@ -27,7 +27,7 @@ class RadioGroup extends Base_1.BaseComponentBuilder {
27
27
  this.data.custom_id = customId;
28
28
  return this;
29
29
  }
30
- setOptions(options) {
30
+ setOptions(...options) {
31
31
  this.#options = options.flat();
32
32
  return this;
33
33
  }
@@ -45,7 +45,7 @@ class RadioGroup extends Base_1.BaseComponentBuilder {
45
45
  return this;
46
46
  }
47
47
  toJSON() {
48
- const options = [...this.#options.map(option => option.data), ...(this.data.options ?? [])];
48
+ const options = [...this.#options.map(option => option.toJSON()), ...(this.data.options ?? [])];
49
49
  const optionCount = options.length;
50
50
  if (optionCount < 2 || optionCount > 10) {
51
51
  throw new common_1.SeyfertError('INVALID_OPTIONS_LENGTH', {
@@ -66,7 +66,7 @@ class RadioGroup extends Base_1.BaseComponentBuilder {
66
66
  exports.RadioGroup = RadioGroup;
67
67
  class RadioGroupOption {
68
68
  data;
69
- constructor(data = {}) {
69
+ constructor(data) {
70
70
  this.data = data;
71
71
  }
72
72
  /**
@@ -105,5 +105,26 @@ class RadioGroupOption {
105
105
  this.data.default = value;
106
106
  return this;
107
107
  }
108
+ toJSON() {
109
+ if (!this.data.label)
110
+ throw new common_1.SeyfertError('MISSING_RADIO_GROUP_OPTION_LABEL', {
111
+ metadata: {
112
+ ...(0, common_1.createValidationMetadata)('label to be set before calling toJSON()', this.data.label, {
113
+ component: 'RadioGroupOption',
114
+ }),
115
+ detail: 'Cannot convert to JSON without a label.',
116
+ },
117
+ });
118
+ if (!this.data.value)
119
+ throw new common_1.SeyfertError('MISSING_RADIO_GROUP_OPTION_VALUE', {
120
+ metadata: {
121
+ ...(0, common_1.createValidationMetadata)('value to be set before calling toJSON()', this.data.value, {
122
+ component: 'RadioGroupOption',
123
+ }),
124
+ detail: 'Cannot convert to JSON without a value.',
125
+ },
126
+ });
127
+ return { ...this.data };
128
+ }
108
129
  }
109
130
  exports.RadioGroupOption = RadioGroupOption;
@@ -2,6 +2,7 @@ import { type EmojiResolvable, type RestOrArray } from '../common';
2
2
  import { type APIChannelSelectComponent, type APIMentionableSelectComponent, type APIRoleSelectComponent, type APISelectMenuComponent, type APISelectMenuOption, type APIStringSelectComponent, type APIUserSelectComponent, type ChannelType, SelectMenuDefaultValueType } from '../types';
3
3
  import { BaseComponentBuilder, type OptionValuesLength } from './Base';
4
4
  export type BuilderSelectMenus = RoleSelectMenu | UserSelectMenu | MentionableSelectMenu | ChannelSelectMenu | StringSelectMenu;
5
+ type StringSelectOptionResolvable<Value extends string = string> = StringSelectOption | APISelectMenuOption<Value>;
5
6
  /**
6
7
  * Represents a base class for building Select Menus.
7
8
  * @template Select - The type of APISelectMenuComponent.
@@ -153,30 +154,30 @@ export declare class ChannelSelectMenu extends SelectMenu<APIChannelSelectCompon
153
154
  * { label: "Option 3", value: "option_3" },
154
155
  * ]);
155
156
  */
156
- export declare class StringSelectMenu extends SelectMenu {
157
- data: Omit<APIStringSelectComponent, 'options'> & {
157
+ export declare class StringSelectMenu<Value extends string = string> extends SelectMenu<APIStringSelectComponent<Value>> {
158
+ data: Omit<Partial<APIStringSelectComponent<Value>>, 'options'> & {
158
159
  options: StringSelectOption[];
159
160
  };
160
- constructor(data?: Partial<APIStringSelectComponent>);
161
+ constructor(data?: Partial<APIStringSelectComponent<Value>>);
161
162
  /**
162
163
  * Adds options to the string select menu.
163
164
  * @param options - Options to be added.
164
165
  * @returns The current StringSelectMenu instance.
165
166
  */
166
- addOption(...options: RestOrArray<StringSelectOption>): this;
167
+ addOption(...options: RestOrArray<StringSelectOptionResolvable<Value>>): this;
167
168
  /**
168
169
  * Sets the options for the string select menu.
169
170
  * options - Options to be set.
170
171
  * @returns The current StringSelectMenu instance.
171
172
  */
172
- setOptions(options: StringSelectOption[]): this;
173
+ setOptions(...options: RestOrArray<StringSelectOptionResolvable<Value>>): this;
173
174
  /**
174
175
  * Sets whether the string select is required to answer in a modal.
175
176
  * @param required - Whether the string select is required to answer in a modal.
176
177
  * @returns The current StringSelectMenu instance.
177
178
  */
178
179
  setRequired(required?: boolean): this;
179
- toJSON(): APIStringSelectComponent;
180
+ toJSON(): APIStringSelectComponent<Value>;
180
181
  }
181
182
  /**
182
183
  * Represents an individual option for a string select menu.
@@ -222,3 +223,4 @@ export declare class StringSelectOption {
222
223
  */
223
224
  toJSON(): APISelectMenuOption;
224
225
  }
226
+ export {};
@@ -15,6 +15,9 @@ const Base_1 = require("./Base");
15
15
  function mappedDefault(ids, type) {
16
16
  return ids.flat().map(id => ({ id, type }));
17
17
  }
18
+ function resolveStringSelectOption(option) {
19
+ return option instanceof StringSelectOption ? option : new StringSelectOption(option);
20
+ }
18
21
  /**
19
22
  * Represents a base class for building Select Menus.
20
23
  * @template Select - The type of APISelectMenuComponent.
@@ -235,7 +238,7 @@ class StringSelectMenu extends SelectMenu {
235
238
  * @returns The current StringSelectMenu instance.
236
239
  */
237
240
  addOption(...options) {
238
- this.data.options = this.data.options.concat(options.flat());
241
+ this.data.options = this.data.options.concat(options.flat().map(resolveStringSelectOption));
239
242
  return this;
240
243
  }
241
244
  /**
@@ -243,8 +246,8 @@ class StringSelectMenu extends SelectMenu {
243
246
  * options - Options to be set.
244
247
  * @returns The current StringSelectMenu instance.
245
248
  */
246
- setOptions(options) {
247
- this.data.options = options;
249
+ setOptions(...options) {
250
+ this.data.options = options.flat().map(resolveStringSelectOption);
248
251
  return this;
249
252
  }
250
253
  /**
@@ -333,6 +336,24 @@ class StringSelectOption {
333
336
  * @returns The option data in JSON format.
334
337
  */
335
338
  toJSON() {
339
+ if (!this.data.label)
340
+ throw new common_1.SeyfertError('MISSING_STRING_SELECT_OPTION_LABEL', {
341
+ metadata: {
342
+ ...(0, common_1.createValidationMetadata)('label to be set before calling toJSON()', this.data.label, {
343
+ component: 'StringSelectOption',
344
+ }),
345
+ detail: 'Cannot convert to JSON without a label.',
346
+ },
347
+ });
348
+ if (!this.data.value)
349
+ throw new common_1.SeyfertError('MISSING_STRING_SELECT_OPTION_VALUE', {
350
+ metadata: {
351
+ ...(0, common_1.createValidationMetadata)('value to be set before calling toJSON()', this.data.value, {
352
+ component: 'StringSelectOption',
353
+ }),
354
+ detail: 'Cannot convert to JSON without a value.',
355
+ },
356
+ });
336
357
  return { ...this.data };
337
358
  }
338
359
  }
@@ -18,8 +18,9 @@ import type { Thumbnail } from './Thumbnail';
18
18
  export type ComponentCallback<T extends ComponentInteraction | StringSelectMenuInteraction = ComponentInteraction | StringSelectMenuInteraction> = (interaction: T, stop: ComponentStopCallback, refresh: ComponentRefreshCallback) => any;
19
19
  export type ComponentOnErrorCallback<T extends ComponentInteraction | StringSelectMenuInteraction = ComponentInteraction | StringSelectMenuInteraction> = (interaction: T, error: unknown, stop: ComponentStopCallback, refresh: ComponentRefreshCallback) => any;
20
20
  export type ComponentFilterCallback<T = ComponentInteraction> = (interaction: T) => any;
21
- export type ComponentOnStopCallback = (reason: 'messageDelete' | 'channelDelete' | 'guildDelete' | 'idle' | 'timeout' | (string & {}) | undefined, refresh: ComponentRefreshCallback) => any;
22
- export type ComponentStopCallback = (reason: 'messageDelete' | 'channelDelete' | 'guildDelete' | 'idle' | 'timeout' | (string & {}) | undefined) => any;
21
+ export type ComponentCollectorStopReason = 'messageDelete' | 'channelDelete' | 'guildDelete' | 'idle' | 'timeout' | (string & {}) | undefined;
22
+ export type ComponentOnStopCallback = (reason: ComponentCollectorStopReason, refresh: ComponentRefreshCallback) => any;
23
+ export type ComponentStopCallback = (reason: ComponentCollectorStopReason) => any;
23
24
  export type ComponentRefreshCallback = () => any;
24
25
  export type ModalSubmitCallback<T = ModalSubmitInteraction> = (interaction: T) => any;
25
26
  export type ButtonLink = Omit<Button, 'setCustomId'>;
@@ -7,7 +7,7 @@ export declare class MemoryAdapter<T> implements Adapter {
7
7
  options: MemoryAdapterOptions<T>;
8
8
  isAsync: boolean;
9
9
  readonly storage: Map<string, T>;
10
- readonly relationships: Map<string, string[]>;
10
+ readonly relationships: Map<string, Set<string>>;
11
11
  constructor(options?: MemoryAdapterOptions<T>);
12
12
  start(): void;
13
13
  scan(query: string, keys?: false): any[];
@@ -23,23 +23,27 @@ class MemoryAdapter {
23
23
  const values = [];
24
24
  const sq = query.split('.');
25
25
  for (const [key, value] of this.storage.entries()) {
26
- if (key.split('.').every((value, i) => (sq[i] === '*' ? !!value : sq[i] === value))) {
26
+ const keySplit = key.split('.');
27
+ if (keySplit.length === sq.length &&
28
+ keySplit.every((segment, i) => (sq[i] === '*' ? !!segment : sq[i] === segment))) {
27
29
  values.push(keys ? key : this.options.decode(value));
28
30
  }
29
31
  }
30
32
  return values;
31
33
  }
32
34
  bulkGet(keys) {
33
- return keys
34
- .map(x => {
35
- const data = this.storage.get(x);
36
- return data ? this.options.decode(data) : null;
37
- })
38
- .filter(x => x);
35
+ const result = [];
36
+ for (const key of keys) {
37
+ const data = this.storage.get(key);
38
+ if (data !== undefined)
39
+ result.push(this.options.decode(data));
40
+ }
41
+ return result;
39
42
  }
40
43
  get(keys) {
41
- const data = this.storage.get(keys);
42
- return data ? this.options.decode(data) : null;
44
+ if (!this.storage.has(keys))
45
+ return null;
46
+ return this.options.decode(this.storage.get(keys));
43
47
  }
44
48
  bulkSet(keys) {
45
49
  for (const [key, value] of keys) {
@@ -63,10 +67,8 @@ class MemoryAdapter {
63
67
  const array = [];
64
68
  const data = this.keys(to);
65
69
  for (const key of data) {
66
- const content = this.get(key);
67
- if (content) {
68
- array.push(content);
69
- }
70
+ if (this.storage.has(key))
71
+ array.push(this.options.decode(this.storage.get(key)));
70
72
  }
71
73
  return array;
72
74
  }
@@ -74,7 +76,7 @@ class MemoryAdapter {
74
76
  return this.getToRelationship(to).map(id => `${to}.${id}`);
75
77
  }
76
78
  count(to) {
77
- return this.getToRelationship(to).length;
79
+ return this.relationships.get(to)?.size ?? 0;
78
80
  }
79
81
  bulkRemove(keys) {
80
82
  for (const i of keys) {
@@ -89,10 +91,10 @@ class MemoryAdapter {
89
91
  this.relationships.clear();
90
92
  }
91
93
  contains(to, keys) {
92
- return this.getToRelationship(to).includes(keys);
94
+ return this.relationships.get(to)?.has(keys) ?? false;
93
95
  }
94
96
  getToRelationship(to) {
95
- return this.relationships.get(to) || [];
97
+ return [...(this.relationships.get(to) ?? [])];
96
98
  }
97
99
  bulkAddToRelationShip(data) {
98
100
  for (const i in data) {
@@ -101,23 +103,18 @@ class MemoryAdapter {
101
103
  }
102
104
  addToRelationship(to, keys) {
103
105
  if (!this.relationships.has(to)) {
104
- this.relationships.set(to, []);
106
+ this.relationships.set(to, new Set());
105
107
  }
106
- const data = this.getToRelationship(to);
108
+ const data = this.relationships.get(to);
107
109
  for (const key of Array.isArray(keys) ? keys : [keys]) {
108
- if (!data.includes(key)) {
109
- data.push(key);
110
- }
110
+ data.add(key);
111
111
  }
112
112
  }
113
113
  removeToRelationship(to, keys) {
114
- const data = this.getToRelationship(to);
114
+ const data = this.relationships.get(to);
115
115
  if (data) {
116
116
  for (const key of Array.isArray(keys) ? keys : [keys]) {
117
- const idx = data.indexOf(key);
118
- if (idx !== -1) {
119
- data.splice(idx, 1);
120
- }
117
+ data.delete(key);
121
118
  }
122
119
  }
123
120
  }
@@ -60,6 +60,7 @@ export declare class LimitedMemoryAdapter<T> implements Adapter {
60
60
  contains(to: string, keys: string): boolean;
61
61
  private _getRelationshipData;
62
62
  private _getRelationshipSet;
63
+ private _ensureRelationshipSet;
63
64
  getToRelationship(to: string): string[];
64
65
  bulkAddToRelationShip(data: Record<string, string[]>): void;
65
66
  addToRelationship(to: string, keys: string | string[]): void;