lunibee 0.1.8 → 0.2.1

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 (55) hide show
  1. package/README.md +2 -0
  2. package/dist/builders/components.d.ts +30 -2
  3. package/dist/builders/embed.d.ts +7 -7
  4. package/dist/builders/index.d.ts +1 -1
  5. package/dist/builders/index.js +110 -18
  6. package/dist/builders/index.js.map +6 -6
  7. package/dist/collection/index.d.ts +68 -1
  8. package/dist/collection/index.js +334 -1
  9. package/dist/collection/index.js.map +3 -3
  10. package/dist/core/collector.d.ts +13 -0
  11. package/dist/core/events.d.ts +29 -3
  12. package/dist/core/index.d.ts +25 -9
  13. package/dist/core/index.js +1745 -134
  14. package/dist/core/index.js.map +30 -26
  15. package/dist/core/permissions.d.ts +48 -0
  16. package/dist/index.js +2102 -362
  17. package/dist/index.js.map +36 -34
  18. package/dist/managers/advanced.d.ts +116 -0
  19. package/dist/managers/base.d.ts +13 -2
  20. package/dist/managers/emoji.d.ts +1 -1
  21. package/dist/managers/guild-resources.d.ts +22 -2
  22. package/dist/managers/guild.d.ts +31 -3
  23. package/dist/managers/index.d.ts +38 -6
  24. package/dist/managers/index.js +996 -160
  25. package/dist/managers/index.js.map +20 -18
  26. package/dist/managers/member.d.ts +13 -12
  27. package/dist/managers/message.d.ts +21 -4
  28. package/dist/rest/errors.d.ts +33 -0
  29. package/dist/rest/index.d.ts +1 -1
  30. package/dist/rest/index.js +52 -6
  31. package/dist/rest/index.js.map +5 -5
  32. package/dist/rest/routes.d.ts +20 -0
  33. package/dist/sharding/index.d.ts +29 -0
  34. package/dist/sharding/index.js +99 -15
  35. package/dist/sharding/index.js.map +8 -8
  36. package/dist/structures/base.d.ts +38 -0
  37. package/dist/structures/index.d.ts +29 -0
  38. package/dist/structures/index.js +208 -46
  39. package/dist/structures/index.js.map +13 -12
  40. package/dist/structures/interactions.d.ts +51 -1
  41. package/dist/structures/options.d.ts +2 -0
  42. package/dist/structures/resources.d.ts +29 -3
  43. package/dist/types/gateway.d.ts +16 -0
  44. package/dist/types/index.d.ts +67 -1
  45. package/dist/types/index.js.map +3 -3
  46. package/dist/utils/args.d.ts +79 -0
  47. package/dist/utils/index.d.ts +1 -0
  48. package/dist/utils/index.js +190 -2
  49. package/dist/utils/index.js.map +5 -4
  50. package/dist/voice/index.d.ts +3 -0
  51. package/dist/voice/index.js +15 -1
  52. package/dist/voice/index.js.map +3 -3
  53. package/dist/ws/index.js +13 -5
  54. package/dist/ws/index.js.map +6 -6
  55. package/package.json +14 -14
package/README.md CHANGED
@@ -130,6 +130,8 @@ Resource managers maintain canonical instances by Discord resource ID. Re-resolv
130
130
 
131
131
  REST-created and Gateway-updated resources are routed through manager cache mutation APIs so the same resource is not represented by unrelated structure instances.
132
132
 
133
+ Discord resources are stored with `Collection.setWithoutTTL()` and leave the cache only through Gateway delete events or an explicit `delete()`, never through expiry. Messages are cached only with the `messageCache: { maxSize?, ttl? }` client option, and `cache: { users, members, roles, emojis }` turns off per-resource caching on large bots. For your own data, `new Collection(null, { ttl, maxSize, onEvict })` is a TTL/LRU cache. See the [0.2.0 upgrade guide](https://lunibee.js.org/getting-started/upgrading/).
134
+
133
135
  ## Permissions
134
136
 
135
137
  `PermissionSet` provides named and raw permission checks:
@@ -23,6 +23,10 @@ export declare const TextInputStyle: {
23
23
  readonly Short: 1;
24
24
  readonly Paragraph: 2;
25
25
  };
26
+ /** One {@link TextInputStyle} value, usable as a type. */
27
+ export type TextInputStyle = (typeof TextInputStyle)[keyof typeof TextInputStyle];
28
+ /** One {@link ComponentType} value, usable as a type. */
29
+ export type ComponentType = (typeof ComponentType)[keyof typeof ComponentType];
26
30
  export interface APIComponentEmoji {
27
31
  id?: string | null;
28
32
  name?: string | null;
@@ -35,6 +39,8 @@ export interface APIButtonComponent {
35
39
  label?: string;
36
40
  emoji?: APIComponentEmoji;
37
41
  url?: string;
42
+ /** SKU for premium (style 6) buttons. */
43
+ sku_id?: string;
38
44
  disabled?: boolean;
39
45
  }
40
46
  export interface APISelectOption {
@@ -77,8 +83,8 @@ export interface APITextInputComponent {
77
83
  }
78
84
  export interface APIModalComponent {
79
85
  type: 9;
80
- custom_id?: string;
81
- title?: string;
86
+ custom_id: string;
87
+ title: string;
82
88
  components: APIActionRowComponent[];
83
89
  }
84
90
  export type APIActionRowChild = APIButtonComponent | APIStringSelectComponent | APIEntitySelectComponent | APITextInputComponent;
@@ -164,10 +170,13 @@ export declare class StringSelectBuilder {
164
170
  }
165
171
  export declare class ButtonBuilder {
166
172
  #private;
173
+ /** Sets the style and drops fields that style cannot carry. */
167
174
  setStyle(style: APIButtonComponent["style"]): this;
168
175
  setCustomId(value: string): this;
169
176
  setLabel(value: string): this;
170
177
  setURL(value: string): this;
178
+ /** Makes this a premium (purchase) button for a SKU. Premium buttons carry no label, emoji, custom ID or URL. */
179
+ setSKUId(skuId: string): this;
171
180
  setEmoji(emoji: APIComponentEmoji | string): this;
172
181
  setDisabled(value?: boolean): this;
173
182
  toJSON(): APIButtonComponent;
@@ -191,6 +200,8 @@ export declare class ModalBuilder {
191
200
  addComponents(...components: Array<{
192
201
  toJSON(): APIActionRowComponent;
193
202
  }>): this;
203
+ /** Adds text inputs, each in its own action row (Discord's modal layout). @param inputs Text inputs, at most 5 per modal. */
204
+ addTextInputs(...inputs: TextInputBuilder[]): this;
194
205
  toJSON(): APIModalComponent;
195
206
  }
196
207
  export declare class TextInputBuilder {
@@ -282,3 +293,20 @@ export declare class MentionableSelectMenuBuilder extends EntitySelectBuilder {
282
293
  export declare class ChannelSelectMenuBuilder extends EntitySelectBuilder {
283
294
  constructor();
284
295
  }
296
+ /**
297
+ * A message payload laid out with Components V2: the components, and the flag
298
+ * Discord requires for them. A V2 message cannot also carry `content` or `embeds`.
299
+ * @param components Top-level components (containers, sections, text displays, action rows...).
300
+ * @param options Extra message fields, such as `allowed_mentions` or `ephemeral`; `flags` are combined.
301
+ * @example channel.send(componentsV2Message(new ContainerBuilder().addComponents(new TextDisplayBuilder().setContent("Hi"))))
302
+ */
303
+ export declare function componentsV2Message<T extends Record<string, unknown> = Record<string, never>>(components: {
304
+ toJSON(): APIComponent;
305
+ } | Array<{
306
+ toJSON(): APIComponent;
307
+ }>, options?: T & {
308
+ flags?: number;
309
+ }): {
310
+ components: APIComponent[];
311
+ flags: number;
312
+ } & T;
@@ -35,19 +35,19 @@ export interface APIEmbed {
35
35
  /** Builds compile-time-safe rich embed payloads for Discord API requests. */
36
36
  export declare class EmbedBuilder {
37
37
  #private;
38
- /** Sets the embed title. @param value Title text. @returns This builder. @throws {RangeError} If title exceeds Discord's limit. */ setTitle(value: string): this;
39
- /** Sets the embed description. @param value Description text. @returns This builder. @throws {RangeError} If description exceeds Discord's limit. */ setDescription(value: string): this;
40
- /** Sets the embed URL. @param value Absolute URL. @returns This builder. @throws {TypeError} If URL is invalid. */ setURL(value: string): this;
38
+ /** Sets the embed title. @param value Title text, or null to clear. @returns This builder. @throws {RangeError} If title exceeds Discord's limit. */ setTitle(value: string | null): this;
39
+ /** Sets the embed description. @param value Description text, or null to clear. @returns This builder. @throws {RangeError} If description exceeds Discord's limit. */ setDescription(value: string | null): this;
40
+ /** Sets the embed URL. @param value Absolute URL, or null to clear. @returns This builder. @throws {TypeError} If URL is invalid. */ setURL(value: string | null): this;
41
41
  /** Sets the embed color. @param value RGB integer. @returns This builder. @throws {RangeError} If color is outside 24-bit RGB range. */ setColor(value: number): this;
42
42
  /** Sets the embed timestamp. @param value Date value. @returns This builder. @throws {RangeError} If date is invalid. */ setTimestamp(value?: Date): this;
43
43
  /** Sets the embed footer. @param value Footer payload. @returns This builder. @throws {RangeError} If footer text exceeds Discord's limit. */ setFooter(value: EmbedFooter): this;
44
44
  /** Sets the embed author. @param value Author payload. @returns This builder. @throws {RangeError} If author name exceeds Discord's limit. */ setAuthor(value: EmbedAuthor): this;
45
- /** Sets the thumbnail URL. @param value Thumbnail URL or payload. @returns This builder. @throws {TypeError} If URL is invalid. */ setThumbnail(value: {
45
+ /** Sets the thumbnail URL. @param value Thumbnail URL or payload, or null to clear. @returns This builder. @throws {TypeError} If URL is invalid. */ setThumbnail(value: {
46
46
  url: string;
47
- } | string): this;
48
- /** Sets the image URL. @param value Image URL or payload. @returns This builder. @throws {TypeError} If URL is invalid. */ setImage(value: {
47
+ } | string | null): this;
48
+ /** Sets the image URL. @param value Image URL or payload, or null to clear. @returns This builder. @throws {TypeError} If URL is invalid. */ setImage(value: {
49
49
  url: string;
50
- } | string): this;
50
+ } | string | null): this;
51
51
  /** Adds embed fields. Accepts both the spread form `addFields(a, b)` and the
52
52
  * single-array form `addFields([a, b])` for discord.js `RestOrArray` parity.
53
53
  * @param fields Field payloads, spread or as a single array. @returns This builder. @throws {RangeError} If the 25-field limit is exceeded. */ addFields(...fields: EmbedField[] | [EmbedField[]]): this;
@@ -1,5 +1,5 @@
1
1
  export { EmbedBuilder } from "./embed.js";
2
2
  export type { EmbedField } from "./embed.js";
3
- export { ButtonBuilder, ButtonStyle, ComponentType, ActionRowBuilder, StringSelectBuilder, StringSelectMenuBuilder, EntitySelectBuilder, UserSelectMenuBuilder, RoleSelectMenuBuilder, MentionableSelectMenuBuilder, ChannelSelectMenuBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, ContainerBuilder, SectionBuilder, TextDisplayBuilder, MediaGalleryBuilder, FileComponentBuilder, SeparatorBuilder, ThumbnailBuilder, ContentInventoryEntryBuilder, } from "./components.js";
3
+ export { ButtonBuilder, ButtonStyle, ComponentType, ActionRowBuilder, StringSelectBuilder, StringSelectMenuBuilder, EntitySelectBuilder, UserSelectMenuBuilder, RoleSelectMenuBuilder, MentionableSelectMenuBuilder, ChannelSelectMenuBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, ContainerBuilder, SectionBuilder, TextDisplayBuilder, MediaGalleryBuilder, FileComponentBuilder, SeparatorBuilder, ThumbnailBuilder, ContentInventoryEntryBuilder, componentsV2Message, } from "./components.js";
4
4
  export { SlashCommandBuilder, StringOptionBuilder, IntegerOptionBuilder, NumberOptionBuilder, BooleanOptionBuilder, UserOptionBuilder, ChannelOptionBuilder, RoleOptionBuilder, MentionableOptionBuilder, AttachmentOptionBuilder, SubcommandBuilder, SubcommandGroupBuilder, ApplicationCommandOptionType, UserCommandBuilder, MessageCommandBuilder, ContextMenuCommandBuilder, } from "./commands.js";
5
5
  export { AttachmentBuilder, type AttachmentData } from "./attachment.js";
@@ -3,15 +3,24 @@
3
3
  class EmbedBuilder {
4
4
  #data = {};
5
5
  setTitle(value) {
6
- this.#data.title = validate(value, 256, "Embed title");
6
+ if (value === null)
7
+ delete this.#data.title;
8
+ else
9
+ this.#data.title = validate(value, 256, "Embed title");
7
10
  return this;
8
11
  }
9
12
  setDescription(value) {
10
- this.#data.description = validate(value, 4096, "Embed description");
13
+ if (value === null)
14
+ delete this.#data.description;
15
+ else
16
+ this.#data.description = validate(value, 4096, "Embed description");
11
17
  return this;
12
18
  }
13
19
  setURL(value) {
14
- this.#data.url = url(value, "Embed URL");
20
+ if (value === null)
21
+ delete this.#data.url;
22
+ else
23
+ this.#data.url = url(value, "Embed URL");
15
24
  return this;
16
25
  }
17
26
  setColor(value) {
@@ -43,11 +52,19 @@ class EmbedBuilder {
43
52
  return this;
44
53
  }
45
54
  setThumbnail(value) {
55
+ if (value === null) {
56
+ delete this.#data.thumbnail;
57
+ return this;
58
+ }
46
59
  const valueURL = typeof value === "string" ? value : value.url;
47
60
  this.#data.thumbnail = { url: url(valueURL, "Thumbnail URL") };
48
61
  return this;
49
62
  }
50
63
  setImage(value) {
64
+ if (value === null) {
65
+ delete this.#data.image;
66
+ return this;
67
+ }
51
68
  const valueURL = typeof value === "string" ? value : value.url;
52
69
  this.#data.image = { url: url(valueURL, "Image URL") };
53
70
  return this;
@@ -212,10 +229,13 @@ class ActionRowBuilder {
212
229
  return this;
213
230
  }
214
231
  toJSON() {
215
- return {
216
- type: ComponentType.ActionRow,
217
- components: this.#components.map((component) => component.toJSON())
218
- };
232
+ const components = this.#components.map((component) => component.toJSON());
233
+ if (components.length === 0)
234
+ throw new RangeError("An action row needs at least one component.");
235
+ const types = components.map((component) => component.type);
236
+ if (types.some((type) => type !== ComponentType.Button) && components.length > 1)
237
+ throw new RangeError("A select menu or text input must be alone in its action row.");
238
+ return { type: ComponentType.ActionRow, components };
219
239
  }
220
240
  }
221
241
 
@@ -270,6 +290,12 @@ class StringSelectBuilder {
270
290
  return this;
271
291
  }
272
292
  toJSON() {
293
+ assertSelect(this.#data);
294
+ const count = this.#data.options?.length ?? 0;
295
+ if (count === 0)
296
+ throw new RangeError("A string select needs at least one option.");
297
+ if ((this.#data.max_values ?? 1) > count)
298
+ throw new RangeError("max_values cannot exceed the number of options.");
273
299
  return structuredClone(this.#data);
274
300
  }
275
301
  }
@@ -280,9 +306,20 @@ class ButtonBuilder {
280
306
  style: ButtonStyle.Secondary
281
307
  };
282
308
  setStyle(style) {
283
- this.#data.style = style;
284
- if (style === ButtonStyle.Link)
285
- delete this.#data.custom_id;
309
+ const data = this.#data;
310
+ data.style = style;
311
+ if (style === ButtonStyle.Link) {
312
+ delete data.custom_id;
313
+ delete data.sku_id;
314
+ } else if (style === ButtonStyle.Premium) {
315
+ delete data.custom_id;
316
+ delete data.url;
317
+ delete data.label;
318
+ delete data.emoji;
319
+ } else {
320
+ delete data.url;
321
+ delete data.sku_id;
322
+ }
286
323
  return this;
287
324
  }
288
325
  setCustomId(value) {
@@ -307,11 +344,16 @@ class ButtonBuilder {
307
344
  cause: error
308
345
  });
309
346
  }
310
- this.#data.style = ButtonStyle.Link;
311
- delete this.#data.custom_id;
347
+ this.setStyle(ButtonStyle.Link);
312
348
  this.#data.url = url.toString();
313
349
  return this;
314
350
  }
351
+ setSKUId(skuId) {
352
+ validateText(skuId, 20, "Button SKU ID");
353
+ this.setStyle(ButtonStyle.Premium);
354
+ this.#data.sku_id = skuId;
355
+ return this;
356
+ }
315
357
  setEmoji(emoji) {
316
358
  this.#data.emoji = typeof emoji === "string" ? { name: emoji } : { ...emoji };
317
359
  return this;
@@ -321,7 +363,26 @@ class ButtonBuilder {
321
363
  return this;
322
364
  }
323
365
  toJSON() {
324
- return structuredClone(this.#data);
366
+ const data = this.#data;
367
+ if (data.style === ButtonStyle.Link) {
368
+ if (!data.url)
369
+ throw new TypeError("Link buttons require a URL.");
370
+ if (data.custom_id || data.sku_id)
371
+ throw new TypeError("Link buttons cannot have a custom ID or SKU ID.");
372
+ } else if (data.style === ButtonStyle.Premium) {
373
+ if (!data.sku_id)
374
+ throw new TypeError("Premium buttons require a SKU ID.");
375
+ if (data.custom_id || data.url || data.label || data.emoji)
376
+ throw new TypeError("Premium buttons cannot have a custom ID, URL, label or emoji.");
377
+ } else {
378
+ if (!data.custom_id)
379
+ throw new TypeError("Non-link buttons require a custom ID.");
380
+ if (data.url || data.sku_id)
381
+ throw new TypeError("Only link buttons have a URL and only premium buttons have a SKU ID.");
382
+ }
383
+ if (data.style !== ButtonStyle.Premium && !data.label && !data.emoji)
384
+ throw new TypeError("Buttons require a label or an emoji.");
385
+ return structuredClone(data);
325
386
  }
326
387
  }
327
388
 
@@ -365,6 +426,7 @@ class EntitySelectBuilder {
365
426
  return this;
366
427
  }
367
428
  toJSON() {
429
+ assertSelect(this.#data);
368
430
  return structuredClone(this.#data);
369
431
  }
370
432
  }
@@ -391,11 +453,18 @@ class ModalBuilder {
391
453
  this.#components.push(...components);
392
454
  return this;
393
455
  }
456
+ addTextInputs(...inputs) {
457
+ return this.addComponents(...inputs.map((input) => new ActionRowBuilder().addComponents(input)));
458
+ }
394
459
  toJSON() {
460
+ if (!this.#custom_id || !this.#title)
461
+ throw new TypeError("Modals require a custom ID and a title.");
462
+ if (this.#components.length === 0)
463
+ throw new RangeError("Modals require at least one component.");
395
464
  return {
396
465
  type: 9,
397
- ...this.#custom_id ? { custom_id: this.#custom_id } : {},
398
- ...this.#title ? { title: this.#title } : {},
466
+ custom_id: this.#custom_id,
467
+ title: this.#title,
399
468
  components: this.#components.map((component) => component.toJSON())
400
469
  };
401
470
  }
@@ -445,7 +514,12 @@ class TextInputBuilder {
445
514
  return this;
446
515
  }
447
516
  toJSON() {
448
- return structuredClone(this.#data);
517
+ const data = this.#data;
518
+ if (!data.custom_id)
519
+ throw new TypeError("Text inputs require a custom ID.");
520
+ if (data.min_length !== undefined && data.max_length !== undefined && data.min_length > data.max_length)
521
+ throw new RangeError("min_length cannot exceed max_length.");
522
+ return structuredClone(data);
449
523
  }
450
524
  }
451
525
 
@@ -672,6 +746,23 @@ class ChannelSelectMenuBuilder extends EntitySelectBuilder {
672
746
  super(ComponentType.ChannelSelect);
673
747
  }
674
748
  }
749
+ function assertSelect(data) {
750
+ if (!data.custom_id)
751
+ throw new TypeError("Select menus require a custom ID.");
752
+ if ((data.min_values ?? 1) > (data.max_values ?? 1))
753
+ throw new RangeError("min_values cannot exceed max_values.");
754
+ }
755
+ var IS_COMPONENTS_V2 = 1 << 15;
756
+ function componentsV2Message(components, options) {
757
+ const list = Array.isArray(components) ? components : [components];
758
+ if (!list.length)
759
+ throw new TypeError("A Components V2 message needs at least one component.");
760
+ return {
761
+ ...options ?? {},
762
+ components: list.map((component) => component.toJSON()),
763
+ flags: (options?.flags ?? 0) | IS_COMPONENTS_V2
764
+ };
765
+ }
675
766
  // packages/builders/src/commands.ts
676
767
  var ApplicationCommandOptionType = {
677
768
  Subcommand: 1,
@@ -1161,7 +1252,8 @@ export {
1161
1252
  ThumbnailBuilder,
1162
1253
  UserCommandBuilder,
1163
1254
  UserOptionBuilder,
1164
- UserSelectMenuBuilder
1255
+ UserSelectMenuBuilder,
1256
+ componentsV2Message
1165
1257
  };
1166
1258
 
1167
- //# debugId=51C5BC8CB8846ABF64756E2164756E21
1259
+ //# debugId=8C8B25AA416C8B5064756E2164756E21