lunibee 0.1.8 → 0.2.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 (44) hide show
  1. package/README.md +2 -0
  2. package/dist/builders/components.d.ts +5 -0
  3. package/dist/builders/index.js +72 -12
  4. package/dist/builders/index.js.map +5 -5
  5. package/dist/collection/index.d.ts +68 -1
  6. package/dist/collection/index.js +334 -1
  7. package/dist/collection/index.js.map +3 -3
  8. package/dist/core/collector.d.ts +13 -0
  9. package/dist/core/events.d.ts +29 -3
  10. package/dist/core/index.d.ts +22 -8
  11. package/dist/core/index.js +1526 -124
  12. package/dist/core/index.js.map +26 -22
  13. package/dist/core/permissions.d.ts +48 -0
  14. package/dist/index.js +1578 -268
  15. package/dist/index.js.map +30 -29
  16. package/dist/managers/advanced.d.ts +116 -0
  17. package/dist/managers/base.d.ts +13 -2
  18. package/dist/managers/emoji.d.ts +1 -1
  19. package/dist/managers/guild.d.ts +28 -2
  20. package/dist/managers/index.d.ts +37 -5
  21. package/dist/managers/index.js +870 -152
  22. package/dist/managers/index.js.map +18 -16
  23. package/dist/managers/message.d.ts +10 -1
  24. package/dist/rest/errors.d.ts +33 -0
  25. package/dist/rest/index.d.ts +1 -1
  26. package/dist/rest/index.js +52 -6
  27. package/dist/rest/index.js.map +5 -5
  28. package/dist/rest/routes.d.ts +20 -0
  29. package/dist/sharding/index.d.ts +29 -0
  30. package/dist/sharding/index.js +99 -15
  31. package/dist/sharding/index.js.map +8 -8
  32. package/dist/structures/base.d.ts +2 -0
  33. package/dist/structures/index.js +96 -42
  34. package/dist/structures/index.js.map +10 -9
  35. package/dist/structures/interactions.d.ts +26 -0
  36. package/dist/types/gateway.d.ts +16 -0
  37. package/dist/types/index.d.ts +55 -1
  38. package/dist/types/index.js.map +2 -2
  39. package/dist/voice/index.d.ts +3 -0
  40. package/dist/voice/index.js +15 -1
  41. package/dist/voice/index.js.map +3 -3
  42. package/dist/ws/index.js +13 -5
  43. package/dist/ws/index.js.map +6 -6
  44. package/package.json +14 -14
@@ -0,0 +1,116 @@
1
+ import { Manager } from "./base.js";
2
+ import { type REST } from "@lunibee/rest";
3
+ import type { APIEntitlement, APISKU, APISoundboardSound, APISticker, APISubscription } from "@lunibee/types";
4
+ export type { APIEntitlement, APISKU, APISoundboardSound, APISubscription, } from "@lunibee/types";
5
+ /** Fields for {@link GuildStickerManager.create}. */
6
+ export interface GuildStickerCreateOptions {
7
+ name: string;
8
+ description: string;
9
+ /** Autocomplete/suggestion tags (e.g. an emoji name). */
10
+ tags: string;
11
+ /** PNG, APNG, GIF or Lottie JSON file, max 512 KiB. */
12
+ file: Blob;
13
+ reason?: string;
14
+ }
15
+ /** Manages a guild's custom stickers, cached by sticker ID. */
16
+ export declare class GuildStickerManager extends Manager<string, APISticker> {
17
+ #private;
18
+ readonly guildId: string;
19
+ constructor(rest: REST, guildId: string);
20
+ /** Fetches every sticker in the guild, replacing the cache. */
21
+ fetchAll(): Promise<APISticker[]>;
22
+ /** Fetches one sticker. */
23
+ fetch(stickerId: string): Promise<APISticker>;
24
+ /** Uploads a sticker (multipart form, as Discord requires). */
25
+ create(options: GuildStickerCreateOptions): Promise<APISticker>;
26
+ /** Edits a sticker's name, description or tags. */
27
+ edit(stickerId: string, options: {
28
+ name?: string;
29
+ description?: string | null;
30
+ tags?: string;
31
+ reason?: string;
32
+ }): Promise<APISticker>;
33
+ /** Deletes a sticker. */
34
+ remove(stickerId: string, reason?: string): Promise<void>;
35
+ /** Replaces the cache with the full list from a `GUILD_STICKERS_UPDATE` event. */
36
+ sync(stickers: readonly APISticker[]): void;
37
+ }
38
+ /** Fields for {@link GuildSoundboardManager.create}. */
39
+ export interface SoundboardSoundCreateOptions {
40
+ name: string;
41
+ /** Data URI of an MP3 or OGG file (max 512 KiB, 5.2 s). */
42
+ sound: string;
43
+ /** 0 to 1; defaults to 1. */
44
+ volume?: number;
45
+ emojiId?: string;
46
+ emojiName?: string;
47
+ reason?: string;
48
+ }
49
+ /** Manages a guild's soundboard sounds, cached by sound ID. */
50
+ export declare class GuildSoundboardManager extends Manager<string, APISoundboardSound> {
51
+ #private;
52
+ readonly guildId: string;
53
+ constructor(rest: REST, guildId: string);
54
+ /** Fetches every soundboard sound in the guild, replacing the cache. */
55
+ fetchAll(): Promise<APISoundboardSound[]>;
56
+ /** Fetches one sound. */
57
+ fetch(soundId: string): Promise<APISoundboardSound>;
58
+ /** Creates a sound. */
59
+ create(options: SoundboardSoundCreateOptions): Promise<APISoundboardSound>;
60
+ /** Edits a sound's name, volume or emoji. */
61
+ edit(soundId: string, options: {
62
+ name?: string;
63
+ volume?: number | null;
64
+ emojiId?: string | null;
65
+ emojiName?: string | null;
66
+ reason?: string;
67
+ }): Promise<APISoundboardSound>;
68
+ /** Deletes a sound. */
69
+ remove(soundId: string, reason?: string): Promise<void>;
70
+ }
71
+ /** Filters for {@link MonetizationManager.fetchEntitlements}. */
72
+ export interface EntitlementQuery {
73
+ userId?: string;
74
+ skuIds?: string[];
75
+ guildId?: string;
76
+ before?: string;
77
+ after?: string;
78
+ /** 1-100, default 100. */
79
+ limit?: number;
80
+ excludeEnded?: boolean;
81
+ excludeDeleted?: boolean;
82
+ }
83
+ /**
84
+ * SKUs, entitlements and subscriptions for one application. Entitlements are
85
+ * cached by ID and kept current by the client's `ENTITLEMENT_*` events.
86
+ */
87
+ export declare class MonetizationManager extends Manager<string, APIEntitlement> {
88
+ #private;
89
+ readonly applicationId: string;
90
+ constructor(rest: REST, applicationId: string);
91
+ /** Fetches the application's SKUs. */
92
+ fetchSkus(): Promise<APISKU[]>;
93
+ /** Fetches entitlements matching the filters and caches them. */
94
+ fetchEntitlements(query?: EntitlementQuery): Promise<APIEntitlement[]>;
95
+ /** Fetches one entitlement. */
96
+ fetch(entitlementId: string): Promise<APIEntitlement>;
97
+ /** Marks a one-time-purchase entitlement as consumed. */
98
+ consume(entitlementId: string): Promise<void>;
99
+ /** Creates a test entitlement for a user or guild (owner type 1 = guild, 2 = user). */
100
+ createTestEntitlement(options: {
101
+ skuId: string;
102
+ ownerId: string;
103
+ ownerType: 1 | 2;
104
+ }): Promise<APIEntitlement>;
105
+ /** Deletes a test entitlement. */
106
+ deleteTestEntitlement(entitlementId: string): Promise<void>;
107
+ /** Fetches a SKU's subscriptions for a user, or one subscription. */
108
+ fetchSubscriptions(skuId: string, query?: {
109
+ userId?: string;
110
+ before?: string;
111
+ after?: string;
112
+ limit?: number;
113
+ }): Promise<APISubscription[]>;
114
+ /** Fetches one subscription. */
115
+ fetchSubscription(skuId: string, subscriptionId: string): Promise<APISubscription>;
116
+ }
@@ -1,10 +1,20 @@
1
1
  import { Collection } from "@lunibee/collection";
2
2
  /** Generic cache manager. @typeParam K Cache key type. @typeParam V Cached value type. */
3
3
  export declare class Manager<K, V> {
4
- /** Cached resources. */ readonly cache: Collection<K, V>;
4
+ #private;
5
+ /** Authoritative resource state. Entries never expire: see {@link Manager.set}. */ readonly cache: Collection<K, V>;
5
6
  /** Gets a cached value. @param id Cache key. @returns Cached value. */ get(id: K): V | undefined;
6
7
  /** Checks whether a value is cached. @param id Cache key. @returns True when cached. */ has(id: K): boolean;
7
- /** Stores a value. @param id Cache key. @param value Value. @returns This manager. */ set(id: K, value: V): this;
8
+ /**
9
+ * Runs a REST load for one key. Concurrent loads of that key share a
10
+ * single request. If the key is written (e.g. by a Gateway update) or
11
+ * deleted while the request is in flight, the result is returned but not
12
+ * stored, so it cannot overwrite fresher state or resurrect a deleted
13
+ * resource.
14
+ * @param store Stores a fresh result and returns the canonical instance.
15
+ */
16
+ 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;
8
18
  /** Deletes a cached value. @param id Cache key. @returns True when deleted. */ delete(id: K): boolean;
9
19
  /** Clears the cache. @returns Nothing. */ clear(): void;
10
20
  /** Gets cache size. @returns Number of cached values. */ get size(): number;
@@ -23,6 +33,7 @@ export declare class ResourceManager<K, V> extends Manager<K, V> {
23
33
  resolve(id: K): Promise<V>;
24
34
  fetch(id: K): Promise<V>;
25
35
  fetchMany(ids: Iterable<K>): Promise<V[]>;
36
+ /** Stores a resource, merging into the cached instance when there is one so existing references stay current. @returns The canonical instance. */
26
37
  upsert(resource: V): V;
27
38
  update(resource: V): V;
28
39
  }
@@ -21,7 +21,7 @@ export interface EmojiEditOptions {
21
21
  export declare class EmojiManager extends Manager<string, Emoji> {
22
22
  #private;
23
23
  constructor(rest: REST, guildId: string);
24
- /** Fetches an emoji by ID from Discord. */
24
+ /** Fetches an emoji by ID; concurrent fetches share a request and a stale result never overwrites newer state. */
25
25
  fetch(emojiId: string): Promise<Emoji>;
26
26
  /** Fetches all emojis for this guild. */
27
27
  fetchAll(): Promise<Emoji[]>;
@@ -1,8 +1,13 @@
1
- import { ResourceManager } from "./base.js";
1
+ import { Manager, ResourceManager } from "./base.js";
2
+ import { EmojiManager } from "./emoji.js";
3
+ import { GuildSoundboardManager, GuildStickerManager } from "./advanced.js";
4
+ import { GuildMemberManager } from "./member.js";
5
+ import { RoleManager } from "./role.js";
2
6
  import { GuildBanManager, GuildScheduledEventManager } from "./guild-resources.js";
3
7
  import { Guild, AutoModerationRule } from "@lunibee/structures";
4
8
  import { type REST } from "@lunibee/rest";
5
- import { type APIChannel, type APIGuildPreview, type APIInvite, type APIWebhook } from "@lunibee/types";
9
+ import { type APIChannel, type APIGuildPreview, type APIInvite, type APIWebhook, type APIAutoModerationRule, type APIInviteCreate, type APIVoiceState } from "@lunibee/types";
10
+ type GuildData = ConstructorParameters<typeof Guild>[0];
6
11
  export interface GuildCreateOptions extends Record<string, unknown> {
7
12
  name: string;
8
13
  }
@@ -15,6 +20,26 @@ export declare class GuildManager extends ResourceManager<string, Guild> {
15
20
  bans(guildId: string): GuildBanManager;
16
21
  /** Scheduled-event manager for a guild (one instance per guild). */
17
22
  scheduledEvents(guildId: string): GuildScheduledEventManager;
23
+ /** Member manager for a guild (one instance per guild, kept in sync by the Gateway). */
24
+ members(guildId: string): GuildMemberManager;
25
+ /** Role manager for a guild (one instance per guild, kept in sync by the Gateway). */
26
+ roles(guildId: string): RoleManager;
27
+ /** Emoji manager for a guild (one instance per guild, kept in sync by the Gateway). */
28
+ emojis(guildId: string): EmojiManager;
29
+ /** Sticker manager for a guild (one instance per guild, kept in sync by the Gateway). */
30
+ stickers(guildId: string): GuildStickerManager;
31
+ /** Soundboard manager for a guild (one instance per guild, kept in sync by the Gateway). */
32
+ soundboard(guildId: string): GuildSoundboardManager;
33
+ /** Voice states by user ID for a guild, kept in sync by `GUILD_CREATE` and `VOICE_STATE_UPDATE`. */
34
+ voiceStates(guildId: string): Manager<string, APIVoiceState>;
35
+ /** Auto-moderation rules by ID for a guild, kept in sync by `AUTO_MODERATION_RULE_*` events. */
36
+ autoModerationRules(guildId: string): Manager<string, APIAutoModerationRule>;
37
+ /** Invites by code for a guild, kept in sync by `INVITE_CREATE` / `INVITE_DELETE`. */
38
+ invites(guildId: string): Manager<string, APIInviteCreate>;
39
+ /** Merges a guild payload into the cached instance, keeping object identity. */
40
+ patch(data: GuildData): Guild;
41
+ /** Removes a guild and every per-guild manager that belongs to it. */
42
+ delete(id: string): boolean;
18
43
  /** Creates a new guild. (Bot must be in fewer than 10 guilds). */
19
44
  create(options: GuildCreateOptions): Promise<Guild>;
20
45
  /** Modifies a guild's settings. */
@@ -144,3 +169,4 @@ export declare const AuditLogEvent: {
144
169
  readonly AutoModerationRuleDelete: 142;
145
170
  readonly AutoModerationBlockMessage: 143;
146
171
  };
172
+ export {};
@@ -4,7 +4,7 @@ export { Manager, ResourceManager } from "./base.js";
4
4
  export { ResourceManager as CachedManager } from "./base.js";
5
5
  import { REST } from "@lunibee/rest";
6
6
  import { Channel, Message, User } from "@lunibee/structures";
7
- import { MessageManager, type MessageCreateOptions as ManagerMessageCreateOptions } from "./message.js";
7
+ import { MessageManager, type MessageCacheOptions, type MessageCreateOptions as ManagerMessageCreateOptions } from "./message.js";
8
8
  import { ThreadManager } from "./thread.js";
9
9
  export { UserManager } from "./user.js";
10
10
  export { GuildManager } from "./guild.js";
@@ -42,15 +42,35 @@ export type ChannelEditOptions = Record<string, unknown>;
42
42
  import { PermissionOverwriteManager } from "./guild-resources.js";
43
43
  export declare class ChannelManager extends Manager<string, Channel> {
44
44
  #private;
45
- constructor(rest: REST);
45
+ /** @param options.messageCache Enables a bounded per-channel message cache; messages are not cached by default. */
46
+ constructor(rest: REST, options?: {
47
+ messageCache?: MessageCacheOptions;
48
+ });
46
49
  messages(channelId: string): MessageManager;
47
50
  /** Permission overwrite manager for a channel. */
48
51
  permissionOverwrites(channelId: string): PermissionOverwriteManager;
49
52
  threads(channelId: string): ThreadManager;
53
+ /** Fetches a channel; concurrent fetches share a request and a stale result never overwrites newer state. */
50
54
  fetch(channelId: string): Promise<Channel>;
51
55
  resolve(channelId: string): Promise<Channel>;
52
56
  upsert(data: ConstructorParameters<typeof Channel>[0]): Channel;
53
57
  update(channel: Channel): this;
58
+ /** Removes every cached channel that belongs to a guild. @returns Number removed. */
59
+ deleteGuildChannels(guildId: string): number;
60
+ /** Ends a poll now; returns the updated message. */
61
+ endPoll(channelId: string, messageId: string): Promise<Message>;
62
+ /** Fetches users who voted for one poll answer. @param options.limit 1-100 (default 25). */
63
+ fetchPollVoters(channelId: string, messageId: string, answerId: number, options?: {
64
+ after?: string;
65
+ limit?: number;
66
+ }): Promise<User[]>;
67
+ /** Plays a soundboard sound in a voice channel the bot is connected to. */
68
+ sendSoundboardSound(channelId: string, options: {
69
+ soundId: string;
70
+ sourceGuildId?: string;
71
+ }): Promise<void>;
72
+ /** Returns the message manager for a channel only if one already exists. */
73
+ cachedMessages(channelId: string): MessageManager | undefined;
54
74
  create(guildId: string, options: ChannelCreateOptions): Promise<Channel>;
55
75
  edit(channelId: string, options: ChannelEditOptions): Promise<Channel>;
56
76
  deleteChannel(channelId: string): Promise<void>;
@@ -69,9 +89,20 @@ export declare class ChannelManager extends Manager<string, Channel> {
69
89
  deleteMessage(channelId: string, messageId: string): Promise<void>;
70
90
  deleteCachedMessage(channelId: string, messageId: string): boolean;
71
91
  crosspostMessage(channelId: string, messageId: string): Promise<Message>;
72
- /** Bulk-deletes messages in a channel.
73
- * @throws {RangeError} If fewer than 2 or more than 100 message IDs are provided. */
92
+ /** Bulk-deletes messages in a channel. Duplicate IDs are ignored and a
93
+ * single ID falls back to a normal delete.
94
+ * @throws {RangeError} If no IDs or more than 100 are provided, or any
95
+ * message is older than 14 days (Discord refuses to bulk-delete those). */
74
96
  bulkDeleteMessages(channelId: string, messageIds: Iterable<string>): Promise<void>;
97
+ /**
98
+ * Iterates a channel's history newest-first, 100 messages per request,
99
+ * starting before `before` (or the latest message) and stopping after
100
+ * `limit` messages or at the start of the channel.
101
+ */
102
+ iterateMessages(channelId: string, options?: {
103
+ before?: string;
104
+ limit?: number;
105
+ }): AsyncGenerator<Message, void, undefined>;
75
106
  addReaction(channelId: string, messageId: string, emoji: string): Promise<void>;
76
107
  fetchReactions(channelId: string, messageId: string, emoji: string, options?: ReactionFetchOptions): Promise<User[]>;
77
108
  removeOwnReaction(channelId: string, messageId: string, emoji: string): Promise<void>;
@@ -104,10 +135,11 @@ export declare class ChannelManager extends Manager<string, Channel> {
104
135
  clear(): void;
105
136
  }
106
137
  export type CreateMessageOptions = MessageCreateOptions;
107
- export { MessageManager } from "./message.js";
138
+ export { MessageManager, type MessageCacheOptions } from "./message.js";
108
139
  export { ThreadManager } from "./thread.js";
109
140
  export { RoleManager, type RoleCreateOptions, type RoleEditOptions, } from "./role.js";
110
141
  export { GuildMemberManager, type MemberEditOptions, type BanOptions, } from "./member.js";
111
142
  export { ApplicationCommandManager } from "./application.js";
112
143
  export { GuildBanManager, GuildScheduledEventManager, StageInstanceManager, PermissionOverwriteManager, type APIBan, type GuildBanCreateOptions, type GuildScheduledEventOptions, type StageInstanceCreateOptions, type PermissionOverwriteOptions, type PermissionOverwriteTargetType, } from "./guild-resources.js";
113
144
  export { EmojiManager, type EmojiCreateOptions, type EmojiEditOptions, } from "./emoji.js";
145
+ export { GuildStickerManager, GuildSoundboardManager, MonetizationManager, type APIEntitlement, type APISKU, type APISoundboardSound, type APISubscription, type EntitlementQuery, type GuildStickerCreateOptions, type SoundboardSoundCreateOptions, } from "./advanced.js";