lunibee 0.2.2 → 0.2.4

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 (70) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +225 -225
  3. package/dist/builders/attachment.d.ts +10 -2
  4. package/dist/builders/commands.d.ts +161 -101
  5. package/dist/builders/components.d.ts +54 -75
  6. package/dist/builders/embed.d.ts +68 -35
  7. package/dist/builders/index.d.ts +1 -1
  8. package/dist/builders/index.js +108 -133
  9. package/dist/builders/index.js.map +8 -8
  10. package/dist/collection/cache.d.ts +13 -6
  11. package/dist/collection/index.d.ts +90 -17
  12. package/dist/collection/index.js +442 -266
  13. package/dist/collection/index.js.map +4 -4
  14. package/dist/core/index.d.ts +9 -0
  15. package/dist/core/index.js +791 -436
  16. package/dist/core/index.js.map +47 -47
  17. package/dist/core/permissions.d.ts +9 -5
  18. package/dist/formatters/index.js +9 -5
  19. package/dist/formatters/index.js.map +3 -3
  20. package/dist/handlers/index.js +5 -10
  21. package/dist/handlers/index.js.map +3 -3
  22. package/dist/index.js +1010 -679
  23. package/dist/index.js.map +66 -65
  24. package/dist/managers/base.d.ts +26 -14
  25. package/dist/managers/emoji.d.ts +7 -1
  26. package/dist/managers/guild-resources.d.ts +11 -3
  27. package/dist/managers/guild.d.ts +13 -5
  28. package/dist/managers/index.d.ts +28 -14
  29. package/dist/managers/index.js +580 -340
  30. package/dist/managers/index.js.map +26 -26
  31. package/dist/managers/member.d.ts +5 -3
  32. package/dist/managers/message.d.ts +7 -3
  33. package/dist/managers/role.d.ts +13 -1
  34. package/dist/rest/error-codes.d.ts +48 -0
  35. package/dist/rest/errors.d.ts +14 -6
  36. package/dist/rest/index.d.ts +25 -12
  37. package/dist/rest/index.js +105 -18
  38. package/dist/rest/index.js.map +15 -14
  39. package/dist/rest/redis.d.ts +1 -1
  40. package/dist/rest/route.d.ts +8 -4
  41. package/dist/rest/routes.d.ts +102 -46
  42. package/dist/rest/transport.d.ts +10 -5
  43. package/dist/rest/webhook.d.ts +9 -5
  44. package/dist/sharding/bus.d.ts +34 -17
  45. package/dist/sharding/index.d.ts +34 -17
  46. package/dist/sharding/index.js +68 -36
  47. package/dist/sharding/index.js.map +17 -17
  48. package/dist/structures/base.d.ts +28 -10
  49. package/dist/structures/channels.d.ts +28 -14
  50. package/dist/structures/index.d.ts +6 -6
  51. package/dist/structures/index.js +81 -99
  52. package/dist/structures/index.js.map +19 -18
  53. package/dist/structures/interactions.d.ts +98 -50
  54. package/dist/structures/resources.d.ts +90 -46
  55. package/dist/types/gateway.d.ts +1 -1
  56. package/dist/types/index.d.ts +43 -18
  57. package/dist/types/index.js +20 -22
  58. package/dist/types/index.js.map +4 -4
  59. package/dist/utils/index.js.map +2 -2
  60. package/dist/voice/index.d.ts +12 -4
  61. package/dist/voice/index.js +17 -20
  62. package/dist/voice/index.js.map +3 -3
  63. package/dist/ws/decoder.d.ts +6 -2
  64. package/dist/ws/index.d.ts +25 -13
  65. package/dist/ws/index.js +63 -31
  66. package/dist/ws/index.js.map +14 -14
  67. package/dist/ws/protocol.d.ts +10 -2
  68. package/dist/ws/session.d.ts +14 -4
  69. package/dist/ws/state.d.ts +22 -11
  70. package/package.json +16 -15
@@ -1,10 +1,17 @@
1
1
  import { Collection } from "@lunibee/collection";
2
+ /** Splits the audit-log `reason` off an options object, so it becomes a header, not a body field. */
3
+ export declare function splitReason<T extends {
4
+ reason?: string;
5
+ }>(options: T): [Omit<T, "reason">, string | undefined];
2
6
  /** Generic cache manager. @typeParam K Cache key type. @typeParam V Cached value type. */
3
7
  export declare class Manager<K, V> {
4
8
  #private;
5
- /** Authoritative resource state. Entries never expire: see {@link Manager.set}. */ readonly cache: Collection<K, V>;
6
- /** Gets a cached value. @param id Cache key. @returns Cached value. */ get(id: K): V | undefined;
7
- /** Checks whether a value is cached. @param id Cache key. @returns True when cached. */ has(id: K): boolean;
9
+ /** Authoritative resource state. Entries never expire: see {@link Manager.set}. */
10
+ readonly cache: Collection<K, V>;
11
+ /** Gets a cached value. @param id Cache key. @returns Cached value. */
12
+ get(id: K): V | undefined;
13
+ /** Checks whether a value is cached. @param id Cache key. @returns True when cached. */
14
+ has(id: K): boolean;
8
15
  /**
9
16
  * Runs a REST load for one key. Concurrent loads of that key share a
10
17
  * single request. If the key is written (e.g. by a Gateway update) or
@@ -14,17 +21,22 @@ export declare class Manager<K, V> {
14
21
  * @param store Stores a fresh result and returns the canonical instance.
15
22
  */
16
23
  protected fetchOnce(id: K, load: () => Promise<V>, store?: (value: V) => V): Promise<V>;
17
- /** Stores a resource with `setWithoutTTL()`, so it leaves only on an explicit delete (e.g. a Gateway `*_DELETE`), never through TTL. @param id Cache key. @param value Value. @returns This manager. */ set(id: K, value: V): this;
18
- /** Deletes a cached value. @param id Cache key. @returns True when deleted. */ delete(id: K): boolean;
19
- /** Clears the cache. @returns Nothing. */ clear(): void;
20
- /** Gets cache size. @returns Number of cached values. */ get size(): number;
21
- /** Gets the first cached value. @returns First value. */ first(): V | undefined;
22
- /** Returns cached values. @returns Array of values. */ values(): V[];
23
- /** Finds a cached value. @param predicate Predicate. @returns Matching value. */ find(predicate: (value: V, key: K) => boolean): V | undefined;
24
- /** Iterates cached entries. @returns Cache iterator. */ [Symbol.iterator](): IterableIterator<[
25
- K,
26
- V
27
- ]>;
24
+ /** Stores a resource with `setWithoutTTL()`, so it leaves only on an explicit delete (e.g. a Gateway `*_DELETE`), never through TTL. @param id Cache key. @param value Value. @returns This manager. */
25
+ set(id: K, value: V): this;
26
+ /** Deletes a cached value. @param id Cache key. @returns True when deleted. */
27
+ delete(id: K): boolean;
28
+ /** Clears the cache. @returns Nothing. */
29
+ clear(): void;
30
+ /** Gets cache size. @returns Number of cached values. */
31
+ get size(): number;
32
+ /** Gets the first cached value. @returns First value. */
33
+ first(): V | undefined;
34
+ /** Returns cached values. @returns Array of values. */
35
+ values(): V[];
36
+ /** Finds a cached value. @param predicate Predicate. @returns Matching value. */
37
+ find(predicate: (value: V, key: K) => boolean): V | undefined;
38
+ /** Iterates cached entries. @returns Cache iterator. */
39
+ [Symbol.iterator](): IterableIterator<[K, V]>;
28
40
  }
29
41
  /** Generic REST-backed resource manager. @typeParam K Resource key type. @typeParam V Resource type. */
30
42
  export declare class ResourceManager<K, V> extends Manager<K, V> {
@@ -3,6 +3,8 @@ import { Emoji } from "@lunibee/structures";
3
3
  import { type REST } from "@lunibee/rest";
4
4
  /** Strict payload for creating a custom guild emoji. */
5
5
  export interface EmojiCreateOptions {
6
+ /** Audit-log reason. */
7
+ reason?: string;
6
8
  /** Emoji name (1-32 chars, alphanumeric + underscores). */
7
9
  name: string;
8
10
  /** Base64-encoded 128x128 image data URI. */
@@ -12,6 +14,8 @@ export interface EmojiCreateOptions {
12
14
  }
13
15
  /** Strict payload for editing a custom guild emoji. */
14
16
  export interface EmojiEditOptions {
17
+ /** Audit-log reason. */
18
+ reason?: string;
15
19
  /** New emoji name. */
16
20
  name?: string;
17
21
  /** Role IDs allowed to use the emoji. */
@@ -29,7 +33,9 @@ export declare class EmojiManager extends Manager<string, Emoji> {
29
33
  create(options: EmojiCreateOptions): Promise<Emoji>;
30
34
  /** Edits an existing custom emoji. */
31
35
  edit(emojiId: string, options: EmojiEditOptions): Promise<Emoji>;
32
- /** Deletes a custom emoji. */
36
+ /** Deletes a custom emoji. @param reason Audit-log reason. */
37
+ remove(emojiId: string, reason?: string): Promise<void>;
38
+ /** @deprecated Use {@link EmojiManager.remove}, which also takes an audit-log reason. Removed in 0.3.0. */
33
39
  deleteEmoji(emojiId: string): Promise<void>;
34
40
  /** Upserts an emoji into the manager cache. Custom emojis are keyed by their
35
41
  * snowflake ID; unicode emojis (no ID) are keyed by `unicode:${name}` so repeated
@@ -32,7 +32,10 @@ export declare class GuildBanManager extends Manager<string, APIBan> {
32
32
  remove(userId: string, reason?: string): Promise<void>;
33
33
  }
34
34
  /** Fields accepted when creating or editing a scheduled event. */
35
- export type GuildScheduledEventOptions = Partial<Omit<APIGuildScheduledEvent, "id" | "guild_id" | "creator" | "user_count">> & Record<string, unknown>;
35
+ export type GuildScheduledEventOptions = Partial<Omit<APIGuildScheduledEvent, "id" | "guild_id" | "creator" | "user_count">> & Record<string, unknown> & {
36
+ /** Audit-log reason. */
37
+ reason?: string;
38
+ };
36
39
  /** Manages a guild's scheduled events, cached by event ID. Discord.js-familiar. */
37
40
  export declare class GuildScheduledEventManager extends Manager<string, APIGuildScheduledEvent> {
38
41
  #private;
@@ -50,8 +53,8 @@ export declare class GuildScheduledEventManager extends Manager<string, APIGuild
50
53
  create(options: GuildScheduledEventOptions, reason?: string): Promise<APIGuildScheduledEvent>;
51
54
  /** Edits an event. */
52
55
  edit(eventId: string, options: GuildScheduledEventOptions, reason?: string): Promise<APIGuildScheduledEvent>;
53
- /** Deletes an event. */
54
- remove(eventId: string): Promise<void>;
56
+ /** Deletes an event. @param reason Audit-log reason. */
57
+ remove(eventId: string, reason?: string): Promise<void>;
55
58
  /** Fetches users subscribed to an event (`limit` 1-100). */
56
59
  fetchSubscribers(eventId: string, options?: {
57
60
  limit?: number;
@@ -65,6 +68,8 @@ export declare class GuildScheduledEventManager extends Manager<string, APIGuild
65
68
  }
66
69
  /** Options for creating a stage instance. */
67
70
  export interface StageInstanceCreateOptions {
71
+ /** Audit-log reason. */
72
+ reason?: string;
68
73
  topic: string;
69
74
  privacyLevel?: number;
70
75
  sendStartNotification?: boolean;
@@ -82,6 +87,7 @@ export declare class StageInstanceManager extends Manager<string, APIStageInstan
82
87
  edit(channelId: string, options: {
83
88
  topic?: string;
84
89
  privacyLevel?: number;
90
+ reason?: string;
85
91
  }, reason?: string): Promise<APIStageInstance>;
86
92
  /** Ends a stage instance. */
87
93
  remove(channelId: string, reason?: string): Promise<void>;
@@ -90,6 +96,8 @@ export declare class StageInstanceManager extends Manager<string, APIStageInstan
90
96
  export type PermissionOverwriteTargetType = 0 | 1;
91
97
  /** Permission values accepted by {@link PermissionOverwriteManager.edit}. */
92
98
  export interface PermissionOverwriteOptions {
99
+ /** Audit-log reason. */
100
+ reason?: string;
93
101
  /** Target type: 0 = role, 1 = member. */
94
102
  type: PermissionOverwriteTargetType;
95
103
  /** Allowed permission bits. */
@@ -12,6 +12,8 @@ export interface GuildCreateOptions extends Record<string, unknown> {
12
12
  name: string;
13
13
  }
14
14
  export interface GuildEditOptions extends Record<string, unknown> {
15
+ /** Audit-log reason. */
16
+ reason?: string;
15
17
  }
16
18
  export declare class GuildManager extends ResourceManager<string, Guild> {
17
19
  #private;
@@ -46,7 +48,9 @@ export declare class GuildManager extends ResourceManager<string, Guild> {
46
48
  create(options: GuildCreateOptions): Promise<Guild>;
47
49
  /** Modifies a guild's settings. */
48
50
  edit(id: string, options: GuildEditOptions): Promise<Guild>;
49
- /** Deletes a guild permanently. User must be the owner. */
51
+ /** Deletes a guild permanently. The bot must own it. */
52
+ remove(id: string): Promise<void>;
53
+ /** @deprecated Use {@link GuildManager.remove}. Removed in 0.3.0. */
50
54
  deleteGuild(id: string): Promise<void>;
51
55
  /** Fetches a guild's preview (even if the bot is not in the guild). */
52
56
  fetchPreview(id: string): Promise<APIGuildPreview>;
@@ -87,11 +91,15 @@ export declare class GuildManager extends ResourceManager<string, Guild> {
87
91
  /** Fetches a single auto moderation rule. */
88
92
  fetchAutoModerationRule(guildId: string, ruleId: string): Promise<AutoModerationRule>;
89
93
  /** Creates a new auto moderation rule. */
90
- createAutoModerationRule(guildId: string, options: Record<string, unknown>): Promise<AutoModerationRule>;
94
+ createAutoModerationRule(guildId: string, options: Record<string, unknown> & {
95
+ reason?: string;
96
+ }): Promise<AutoModerationRule>;
91
97
  /** Modifies an existing auto moderation rule. */
92
- editAutoModerationRule(guildId: string, ruleId: string, options: Record<string, unknown>): Promise<AutoModerationRule>;
93
- /** Deletes an auto moderation rule. */
94
- deleteAutoModerationRule(guildId: string, ruleId: string): Promise<void>;
98
+ editAutoModerationRule(guildId: string, ruleId: string, options: Record<string, unknown> & {
99
+ reason?: string;
100
+ }): Promise<AutoModerationRule>;
101
+ /** Deletes an auto moderation rule. @param reason Audit-log reason. */
102
+ deleteAutoModerationRule(guildId: string, ruleId: string, reason?: string): Promise<void>;
95
103
  }
96
104
  /** A single audit log entry as returned by the Discord API. */
97
105
  export interface AuditLogEntry {
@@ -3,6 +3,7 @@ export { Manager, ResourceManager } from "./base.js";
3
3
  /** Discord.js-familiar alias for {@link ResourceManager}. */
4
4
  export { ResourceManager as CachedManager } from "./base.js";
5
5
  import { REST } from "@lunibee/rest";
6
+ import type { AllowedMentions } from "@lunibee/types";
6
7
  import { Channel, Message, User } from "@lunibee/structures";
7
8
  import { MessageManager, type MessageCacheOptions, type MessageCreateOptions as ManagerMessageCreateOptions } from "./message.js";
8
9
  import { ThreadManager } from "./thread.js";
@@ -33,12 +34,17 @@ export interface ReactionFetchOptions {
33
34
  after?: string;
34
35
  }
35
36
  export interface ChannelCreateOptions extends Record<string, unknown> {
37
+ /** Audit-log reason. */
38
+ reason?: string;
36
39
  name: string;
37
40
  type: number;
38
41
  guild_id?: string;
39
42
  parent_id?: string | null;
40
43
  }
41
- export type ChannelEditOptions = Record<string, unknown>;
44
+ export type ChannelEditOptions = Record<string, unknown> & {
45
+ /** Audit-log reason. */
46
+ reason?: string;
47
+ };
42
48
  import { PermissionOverwriteManager } from "./guild-resources.js";
43
49
  export declare class ChannelManager extends Manager<string, Channel> {
44
50
  #private;
@@ -48,7 +54,7 @@ export declare class ChannelManager extends Manager<string, Channel> {
48
54
  */
49
55
  constructor(rest: REST, options?: {
50
56
  messageCache?: MessageCacheOptions;
51
- allowedMentions?: unknown;
57
+ allowedMentions?: AllowedMentions;
52
58
  });
53
59
  messages(channelId: string): MessageManager;
54
60
  /** Permission overwrite manager for a channel. */
@@ -77,27 +83,32 @@ export declare class ChannelManager extends Manager<string, Channel> {
77
83
  cachedMessages(channelId: string): MessageManager | undefined;
78
84
  create(guildId: string, options: ChannelCreateOptions): Promise<Channel>;
79
85
  edit(channelId: string, options: ChannelEditOptions): Promise<Channel>;
86
+ /** Deletes a channel (or closes a DM). @param reason Audit-log reason. */
87
+ remove(channelId: string, reason?: string): Promise<void>;
88
+ /** @deprecated Use {@link ChannelManager.remove}, which also takes an audit-log reason. Removed in 0.3.0. */
80
89
  deleteChannel(channelId: string): Promise<void>;
81
90
  /** Evicts a channel, dropping its per-channel message manager with it.
82
91
  * Overrides {@link Manager.delete} so cache eviction driven by a Gateway
83
92
  * `CHANNEL_DELETE`/`THREAD_DELETE` — which calls `delete` rather than
84
- * {@link deleteChannel} — releases the message manager and its cached
93
+ * {@link remove} — releases the message manager and its cached
85
94
  * messages too, instead of retaining them for the client's lifetime. */
86
95
  delete(channelId: string): boolean;
87
96
  send(channelId: string, options: MessageCreateOptions): Promise<Message>;
97
+ /** @deprecated Use {@link ChannelManager.send}. Removed in 0.3.0. */
88
98
  sendMessage(channelId: string, options: MessageCreateOptions): Promise<Message>;
89
99
  fetchMessage(channelId: string, messageId: string, options?: MessageFetchOptions): Promise<Message>;
90
100
  fetchMessages(channelId: string, query: MessageQueryOptions | Iterable<string>): Promise<Message[]>;
91
101
  upsertMessage(data: ConstructorParameters<typeof Message>[0]): Message;
92
102
  editMessage(channelId: string, messageId: string, options: MessageEditOptions): Promise<Message>;
93
- deleteMessage(channelId: string, messageId: string): Promise<void>;
103
+ /** Deletes a message. @param reason Audit-log reason (shown when deleting someone else's message). */
104
+ deleteMessage(channelId: string, messageId: string, reason?: string): Promise<void>;
94
105
  deleteCachedMessage(channelId: string, messageId: string): boolean;
95
106
  crosspostMessage(channelId: string, messageId: string): Promise<Message>;
96
107
  /** Bulk-deletes messages in a channel. Duplicate IDs are ignored and a
97
108
  * single ID falls back to a normal delete.
98
109
  * @throws {RangeError} If no IDs or more than 100 are provided, or any
99
110
  * message is older than 14 days (Discord refuses to bulk-delete those). */
100
- bulkDeleteMessages(channelId: string, messageIds: Iterable<string>): Promise<void>;
111
+ bulkDeleteMessages(channelId: string, messageIds: Iterable<string>, reason?: string): Promise<void>;
101
112
  /**
102
113
  * Iterates a channel's history newest-first, 100 messages per request,
103
114
  * starting before `before` (or the latest message) and stopping after
@@ -112,9 +123,18 @@ export declare class ChannelManager extends Manager<string, Channel> {
112
123
  removeOwnReaction(channelId: string, messageId: string, emoji: string): Promise<void>;
113
124
  removeReaction(channelId: string, messageId: string, emoji: string, userId: string): Promise<void>;
114
125
  removeAllReactions(channelId: string, messageId: string): Promise<void>;
126
+ /** Fetches the newest pinned messages (one page, up to 50, like the endpoint it replaces). */
115
127
  fetchPinnedMessages(channelId: string): Promise<Message[]>;
116
- pinMessage(channelId: string, messageId: string): Promise<void>;
117
- unpinMessage(channelId: string, messageId: string): Promise<void>;
128
+ /** Pins a message. @param reason Audit-log reason. */
129
+ pinMessage(channelId: string, messageId: string, reason?: string): Promise<void>;
130
+ /** Unpins a message. @param reason Audit-log reason. */
131
+ unpinMessage(channelId: string, messageId: string, reason?: string): Promise<void>;
132
+ /** Creates a webhook in a channel. @param options Name, optional avatar data URI, and audit-log `reason`. */
133
+ createWebhook(channelId: string, options: {
134
+ name: string;
135
+ avatar?: string | null;
136
+ reason?: string;
137
+ }): Promise<import("@lunibee/types").APIWebhook>;
118
138
  createThreadFromMessage(channelId: string, messageId: string, options: MessageThreadOptions): Promise<Channel>;
119
139
  /**
120
140
  * Fetches a page of messages with cursor metadata.
@@ -128,13 +148,7 @@ export declare class ChannelManager extends Manager<string, Channel> {
128
148
  after?: string;
129
149
  hasMore: boolean;
130
150
  }>;
131
- /**
132
- * Bulk-deletes 2–100 messages from a channel.
133
- * Only messages younger than 14 days are accepted by Discord.
134
- * @param channelId Channel to delete from.
135
- * @param messageIds Array of message IDs to delete.
136
- * @throws {RangeError} If fewer than 2 or more than 100 IDs are provided.
137
- */
151
+ /** @deprecated Use {@link ChannelManager.bulkDeleteMessages}, which also takes an audit-log reason. Removed in 0.3.0. */
138
152
  bulkDelete(channelId: string, messageIds: string[]): Promise<void>;
139
153
  clear(): void;
140
154
  }