lunibee 0.2.3 → 0.3.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.
- package/README.md +3 -3
- package/dist/builders/attachment.d.ts +8 -4
- package/dist/builders/commands.d.ts +122 -149
- package/dist/builders/components.d.ts +10 -150
- package/dist/builders/embed.d.ts +66 -37
- package/dist/builders/index.d.ts +0 -4
- package/dist/builders/index.js +112 -221
- package/dist/builders/index.js.map +10 -9
- package/dist/collection/cache.d.ts +15 -6
- package/dist/collection/index.d.ts +92 -17
- package/dist/collection/index.js +471 -279
- package/dist/collection/index.js.map +4 -4
- package/dist/core/api.d.ts +130 -0
- package/dist/core/channel-create.d.ts +72 -0
- package/dist/core/commands.d.ts +232 -0
- package/dist/core/events.d.ts +24 -7
- package/dist/core/handles.d.ts +157 -0
- package/dist/core/index.d.ts +68 -4
- package/dist/core/index.js +2639 -493
- package/dist/core/index.js.map +47 -37
- package/dist/core/permissions.d.ts +7 -7
- package/dist/formatters/index.js +9 -5
- package/dist/formatters/index.js.map +3 -3
- package/dist/handlers/index.js +5 -10
- package/dist/handlers/index.js.map +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +9527 -7809
- package/dist/index.js.map +63 -53
- package/dist/managers/advanced.d.ts +29 -1
- package/dist/managers/base.d.ts +22 -14
- package/dist/managers/emoji.d.ts +0 -2
- package/dist/managers/guild-resources.d.ts +13 -5
- package/dist/managers/guild.d.ts +40 -4
- package/dist/managers/index.d.ts +21 -13
- package/dist/managers/index.js +969 -386
- package/dist/managers/index.js.map +30 -25
- package/dist/managers/member.d.ts +9 -2
- package/dist/managers/message.d.ts +10 -15
- package/dist/managers/role.d.ts +18 -10
- package/dist/managers/thread.d.ts +68 -0
- package/dist/managers/user.d.ts +18 -0
- package/dist/rest/errors.d.ts +14 -7
- package/dist/rest/index.d.ts +24 -12
- package/dist/rest/index.js +70 -20
- package/dist/rest/index.js.map +9 -9
- package/dist/rest/redis.d.ts +1 -1
- package/dist/rest/route.d.ts +8 -4
- package/dist/rest/routes.d.ts +122 -48
- package/dist/rest/transport.d.ts +10 -5
- package/dist/rest/webhook.d.ts +9 -5
- package/dist/sharding/bus.d.ts +47 -19
- package/dist/sharding/cluster.d.ts +11 -0
- package/dist/sharding/gateway-bot.d.ts +18 -0
- package/dist/sharding/index.d.ts +64 -25
- package/dist/sharding/index.js +439 -124
- package/dist/sharding/index.js.map +19 -14
- package/dist/sharding/supervisor.d.ts +32 -0
- package/dist/sharding/transport.d.ts +45 -0
- package/dist/structures/audit-log.d.ts +99 -2
- package/dist/structures/base.d.ts +40 -23
- package/dist/structures/channels.d.ts +45 -14
- package/dist/structures/index.d.ts +8 -12
- package/dist/structures/index.js +280 -132
- package/dist/structures/index.js.map +21 -15
- package/dist/structures/interactions.d.ts +91 -63
- package/dist/structures/resources.d.ts +99 -52
- package/dist/structures/sticker.d.ts +33 -0
- package/dist/types/channel-kind.d.ts +26 -0
- package/dist/types/gateway.d.ts +24 -12
- package/dist/types/index.d.ts +115 -113
- package/dist/types/index.js +53 -48
- package/dist/types/index.js.map +6 -5
- package/dist/voice/index.d.ts +12 -4
- package/dist/voice/index.js +14 -18
- package/dist/voice/index.js.map +3 -3
- package/dist/ws/decoder.d.ts +6 -2
- package/dist/ws/dispatcher.d.ts +19 -0
- package/dist/ws/index.d.ts +61 -15
- package/dist/ws/index.js +194 -77
- package/dist/ws/index.js.map +13 -11
- package/dist/ws/protocol.d.ts +10 -2
- package/dist/ws/reconnect.d.ts +10 -0
- package/dist/ws/send-budget.d.ts +6 -2
- package/dist/ws/session.d.ts +14 -4
- package/dist/ws/state.d.ts +22 -11
- package/package.json +20 -16
package/dist/rest/redis.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { type RateLimitStore, type BucketState, type Reservation } from "./store
|
|
|
6
6
|
export interface MinimalRedisClient {
|
|
7
7
|
get(key: string): Promise<string | null>;
|
|
8
8
|
mget(keys: string[]): Promise<Array<string | null>>;
|
|
9
|
-
set(key: string, value: string | number, mode?: string, duration?: number): Promise<
|
|
9
|
+
set(key: string, value: string | number, mode?: string, duration?: number): Promise<string | null>;
|
|
10
10
|
del(...keys: string[]): Promise<number>;
|
|
11
11
|
/**
|
|
12
12
|
* Optional Lua evaluation (ioredis/node-redis compatible). When present,
|
package/dist/rest/route.d.ts
CHANGED
|
@@ -9,10 +9,14 @@ export type RESTQuery = URLSearchParams | Record<string, string | number | boole
|
|
|
9
9
|
* make two channels share one counter.
|
|
10
10
|
*/
|
|
11
11
|
export interface RouteKey {
|
|
12
|
-
/** Uppercased HTTP method. */
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
|
|
12
|
+
/** Uppercased HTTP method. */
|
|
13
|
+
method: string;
|
|
14
|
+
/** Raw request path, without query string. */
|
|
15
|
+
path: string;
|
|
16
|
+
/** Normalized `METHOD:/path/:id` route used for bucket-hash lookup. */
|
|
17
|
+
route: string;
|
|
18
|
+
/** Major parameter scoping the limit (channel, guild, webhook id[:token]). */
|
|
19
|
+
major: string;
|
|
16
20
|
}
|
|
17
21
|
/** Normalizes Discord routes for stable bucket discovery. */
|
|
18
22
|
export declare function normalizeRoutePath(path: string): string;
|
package/dist/rest/routes.d.ts
CHANGED
|
@@ -1,57 +1,131 @@
|
|
|
1
1
|
/** Discord REST API route definitions. */
|
|
2
2
|
export declare const Routes: {
|
|
3
|
-
/** Returns the current bot user. @returns User route. */
|
|
4
|
-
|
|
5
|
-
/** Returns
|
|
6
|
-
|
|
7
|
-
/** Returns
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
/** Returns a
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
/** Returns guild
|
|
16
|
-
|
|
17
|
-
/** Returns a
|
|
18
|
-
|
|
19
|
-
/** Returns
|
|
20
|
-
|
|
21
|
-
/** Returns
|
|
22
|
-
|
|
23
|
-
/** Returns
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
/** Returns
|
|
30
|
-
|
|
31
|
-
/** Returns a
|
|
32
|
-
|
|
33
|
-
/** Returns
|
|
34
|
-
|
|
35
|
-
/** Returns
|
|
36
|
-
|
|
37
|
-
/** Returns
|
|
38
|
-
|
|
39
|
-
/** Returns
|
|
40
|
-
|
|
41
|
-
/** Returns a
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
/** Returns a
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
|
|
3
|
+
/** Returns the current bot user. @returns User route. */
|
|
4
|
+
readonly user: () => string;
|
|
5
|
+
/** Returns one user. @param userId User identifier. @returns User route. */
|
|
6
|
+
readonly userById: (userId: string) => string;
|
|
7
|
+
/** Returns a guild. @param guildId Guild identifier. @returns Guild route. */
|
|
8
|
+
readonly guild: (guildId: string) => string;
|
|
9
|
+
/** Leaves a guild as the current user (DELETE). @param guildId Guild identifier. @returns Current-user guild route. */
|
|
10
|
+
readonly currentUserGuild: (guildId: string) => string;
|
|
11
|
+
/** Returns a sticker. @param stickerId Sticker identifier. @returns Sticker route. */
|
|
12
|
+
readonly sticker: (stickerId: string) => string;
|
|
13
|
+
/** Removes one user's reaction (DELETE). @param channelId Channel identifier. @param messageId Message identifier. @param emoji Emoji name or ID. @param userId User identifier. @returns Reaction-user route. */
|
|
14
|
+
readonly messageReactionUser: (channelId: string, messageId: string, emoji: string, userId: string) => string;
|
|
15
|
+
/** Returns a guild preview. @param guildId Guild identifier. */
|
|
16
|
+
readonly guildPreview: (guildId: string) => string;
|
|
17
|
+
/** Returns active threads for a guild. @param guildId Guild identifier. */
|
|
18
|
+
readonly guildActiveThreads: (guildId: string) => string;
|
|
19
|
+
/** Returns webhooks for a guild. @param guildId Guild identifier. */
|
|
20
|
+
readonly guildWebhooks: (guildId: string) => string;
|
|
21
|
+
/** Returns invites for a guild. @param guildId Guild identifier. */
|
|
22
|
+
readonly guildInvites: (guildId: string) => string;
|
|
23
|
+
/** Returns channels in a guild. @param guildId Guild identifier. @returns Channel collection route. */
|
|
24
|
+
readonly guildChannels: (guildId: string) => string;
|
|
25
|
+
/** Returns a guild member. @param guildId Guild identifier. @param userId User identifier. @returns Guild-member route. */
|
|
26
|
+
readonly guildMember: (guildId: string, userId: string) => string;
|
|
27
|
+
/** Returns all guild roles. @param guildId Guild identifier. @returns Guild-role route. */
|
|
28
|
+
readonly guildRoles: (guildId: string) => string;
|
|
29
|
+
/** Returns an individual guild role. */
|
|
30
|
+
readonly guildRole: (guildId: string, roleId: string) => string;
|
|
31
|
+
/** Returns a member role route. */
|
|
32
|
+
readonly guildMemberRole: (guildId: string, userId: string, roleId: string) => string;
|
|
33
|
+
/** Returns guild bans collection. */
|
|
34
|
+
readonly guildBans: (guildId: string) => string;
|
|
35
|
+
/** Returns an individual guild ban. */
|
|
36
|
+
readonly guildBan: (guildId: string, userId: string) => string;
|
|
37
|
+
/** Returns a channel. @param channelId Channel identifier. @returns Channel route. */
|
|
38
|
+
readonly channel: (channelId: string) => string;
|
|
39
|
+
/** Returns messages in a channel. @param channelId Channel identifier. @returns Message collection route. */
|
|
40
|
+
readonly channelMessages: (channelId: string) => string;
|
|
41
|
+
/** Returns a message. @param channelId Channel identifier. @param messageId Message identifier. @returns Message route. */
|
|
42
|
+
readonly message: (channelId: string, messageId: string) => string;
|
|
43
|
+
/** Crossposts a message. @param channelId Channel identifier. @param messageId Message identifier. @returns Crosspost route. */
|
|
44
|
+
readonly crosspostMessage: (channelId: string, messageId: string) => string;
|
|
45
|
+
/** Returns reactions for a message and emoji. @param channelId Channel identifier. @param messageId Message identifier. @param emoji Emoji name or ID. @returns Reaction route. */
|
|
46
|
+
readonly messageReactions: (channelId: string, messageId: string, emoji: string) => string;
|
|
47
|
+
/** The bot's own reaction: PUT adds it, DELETE removes it. @param channelId Channel identifier. @param messageId Message identifier. @param emoji Emoji name or ID. */
|
|
48
|
+
readonly messageReactionMe: (channelId: string, messageId: string, emoji: string) => string;
|
|
49
|
+
/** Removes all reactions from a message. @param channelId Channel identifier. @param messageId Message identifier. @returns Reaction collection route. */
|
|
50
|
+
readonly messageReactionsAll: (channelId: string, messageId: string) => string;
|
|
51
|
+
/** Returns pinned messages, newest first, in pages of up to 50 (`before`, `limit`). @param channelId Channel identifier. @returns Pins route. */
|
|
52
|
+
readonly channelMessagesPins: (channelId: string) => string;
|
|
53
|
+
/** Pins (PUT) or unpins (DELETE) a message. @param channelId Channel identifier. @param messageId Message identifier. @returns Pin route. */
|
|
54
|
+
readonly channelMessagesPin: (channelId: string, messageId: string) => string;
|
|
55
|
+
/** Creates a thread from a message. @param channelId Channel identifier. @param messageId Message identifier. @returns Message-thread route. */
|
|
56
|
+
readonly messageThread: (channelId: string, messageId: string) => string;
|
|
57
|
+
/** Bulk deletes messages. @param channelId Channel identifier. @returns Bulk-delete route. */
|
|
58
|
+
readonly channelBulkDelete: (channelId: string) => string;
|
|
59
|
+
/** Returns channel webhooks. @param channelId Channel identifier. @returns Webhook collection route. */
|
|
60
|
+
readonly channelWebhooks: (channelId: string) => string;
|
|
61
|
+
/** Returns channel invites. @param channelId Channel identifier. @returns Invite collection route. */
|
|
62
|
+
readonly channelInvites: (channelId: string) => string;
|
|
63
|
+
/** Returns a webhook. @param webhookId Webhook identifier. @param token Optional webhook token. @returns Webhook route. */
|
|
64
|
+
readonly webhook: (webhookId: string, token?: string) => string;
|
|
65
|
+
/** Returns a webhook message. */
|
|
66
|
+
readonly webhookMessage: (webhookId: string, token: string, messageId: string) => string;
|
|
67
|
+
/** Returns application commands for an application. @param applicationId Application identifier. @returns Global command route. */
|
|
68
|
+
readonly applicationCommands: (applicationId: string) => string;
|
|
69
|
+
/** Returns one application command. @param applicationId Application identifier. @param commandId Command identifier. @returns Command route. */
|
|
70
|
+
readonly applicationCommand: (applicationId: string, commandId: string) => string;
|
|
71
|
+
/** Returns guild application commands. @param applicationId Application identifier. @param guildId Guild identifier. @returns Guild command route. */
|
|
72
|
+
readonly guildApplicationCommands: (applicationId: string, guildId: string) => string;
|
|
73
|
+
/** Returns a single guild application command. @param applicationId Application identifier. @param guildId Guild identifier. @param commandId Command identifier. @returns Guild command route. */
|
|
74
|
+
readonly guildApplicationCommand: (applicationId: string, guildId: string, commandId: string) => string;
|
|
75
|
+
/** Returns an interaction callback endpoint. @param interactionId Interaction identifier. @param token Interaction token. @returns Interaction callback route. */
|
|
76
|
+
readonly interactionCallback: (interactionId: string, token: string) => string;
|
|
77
|
+
/** Returns the original interaction response endpoint. @param applicationId Application identifier. @param token Interaction token. @returns Original-response route. */
|
|
78
|
+
readonly interactionOriginalResponse: (applicationId: string, token: string) => string;
|
|
79
|
+
/** Returns public archived threads for a channel. @param channelId Channel identifier. @returns Public-archive route. */
|
|
80
|
+
readonly channelPublicArchivedThreads: (channelId: string) => string;
|
|
81
|
+
/** Returns private archived threads for a channel. @param channelId Channel identifier. @returns Private-archive route. */
|
|
82
|
+
readonly channelPrivateArchivedThreads: (channelId: string) => string;
|
|
83
|
+
/** Returns the private archived threads the current user joined. @param channelId Channel identifier. */
|
|
84
|
+
readonly channelJoinedPrivateArchivedThreads: (channelId: string) => string;
|
|
85
|
+
/** Returns one member of a thread; `"@me"` is the current user (PUT joins, DELETE leaves). @param threadId Thread identifier. @param userId User identifier or `"@me"`. */
|
|
86
|
+
readonly threadMember: (threadId: string, userId: string) => string;
|
|
87
|
+
/** Starts a typing indicator (POST). @param channelId Channel identifier. */
|
|
88
|
+
readonly channelTyping: (channelId: string) => string;
|
|
89
|
+
/** Creates a thread that is not tied to a message, or a forum or media post (POST). @param channelId Channel identifier. */
|
|
90
|
+
readonly channelThreads: (channelId: string) => string;
|
|
91
|
+
/** Returns a thread's members. @param threadId Thread identifier. @returns Thread-member route. */
|
|
92
|
+
readonly threadMembers: (threadId: string) => string;
|
|
93
|
+
/** Returns guild scheduled events. @param guildId Guild identifier. @returns Scheduled-event collection route. */
|
|
94
|
+
readonly guildScheduledEvents: (guildId: string) => string;
|
|
95
|
+
/** Returns one guild scheduled event. @param guildId Guild identifier. @param eventId Event identifier. @returns Scheduled-event route. */
|
|
96
|
+
readonly guildScheduledEvent: (guildId: string, eventId: string) => string;
|
|
97
|
+
/** Returns users subscribed to a scheduled event. @param guildId Guild identifier. @param eventId Event identifier. @returns Scheduled-event users route. */
|
|
98
|
+
readonly guildScheduledEventUsers: (guildId: string, eventId: string) => string;
|
|
99
|
+
/** Returns a channel permission overwrite. @param channelId Channel identifier. @param overwriteId Role or user identifier. @returns Permission overwrite route. */
|
|
100
|
+
readonly channelPermission: (channelId: string, overwriteId: string) => string;
|
|
101
|
+
/** Returns guild automod rules. @param guildId Guild identifier. @returns Automod-rule collection route. */
|
|
102
|
+
readonly guildAutoModerationRules: (guildId: string) => string;
|
|
103
|
+
/** Returns one automod rule. @param guildId Guild identifier. @param ruleId Rule identifier. @returns Automod-rule route. */
|
|
104
|
+
readonly guildAutoModerationRule: (guildId: string, ruleId: string) => string;
|
|
105
|
+
/** Returns current voice regions. @returns Voice-region route. */
|
|
106
|
+
readonly voiceRegions: () => string;
|
|
107
|
+
/** Returns the generic Gateway endpoint. @returns Gateway route. */
|
|
108
|
+
readonly gateway: () => string;
|
|
109
|
+
/** Returns the Gateway endpoint and recommended shard count for bots. @returns Gateway bot route. */
|
|
110
|
+
readonly gatewayBot: () => string;
|
|
51
111
|
/** Returns audit log entries for a guild. @param guildId Guild identifier. @returns Audit log route. */
|
|
52
112
|
readonly guildAuditLog: (guildId: string) => string;
|
|
53
113
|
/** Returns members in a guild (paginated). @param guildId Guild identifier. @returns Members collection route. */
|
|
54
114
|
readonly guildMembers: (guildId: string) => string;
|
|
115
|
+
/** Searches members by nickname or username. @param guildId Guild identifier. */
|
|
116
|
+
readonly guildMembersSearch: (guildId: string) => string;
|
|
117
|
+
/** Edits the bot's own member, e.g. its nickname (PATCH). @param guildId Guild identifier. */
|
|
118
|
+
readonly guildMemberMe: (guildId: string) => string;
|
|
119
|
+
/** Bans up to 200 users at once (POST). @param guildId Guild identifier. */
|
|
120
|
+
readonly guildBulkBan: (guildId: string) => string;
|
|
121
|
+
/** Edits a voice state in a stage channel (PATCH); `"@me"` is the bot. @param guildId Guild identifier. @param userId User identifier or `"@me"`. */
|
|
122
|
+
readonly guildVoiceState: (guildId: string, userId: string) => string;
|
|
123
|
+
/** Removes an integration from a guild (DELETE). @param guildId Guild identifier. @param integrationId Integration identifier. */
|
|
124
|
+
readonly guildIntegration: (guildId: string, integrationId: string) => string;
|
|
125
|
+
/** Returns the guilds the bot is in (paged with `before`, `after`, `limit`). */
|
|
126
|
+
readonly userGuilds: () => string;
|
|
127
|
+
/** Returns the sticker packs Nitro users can use, or one pack. @param packId Optional pack identifier. */
|
|
128
|
+
readonly stickerPacks: (packId?: string) => string;
|
|
55
129
|
/** Returns the welcome screen for a guild. @param guildId Guild identifier. */
|
|
56
130
|
readonly guildWelcomeScreen: (guildId: string) => string;
|
|
57
131
|
/** Returns the onboarding configuration for a guild. @param guildId Guild identifier. */
|
package/dist/rest/transport.d.ts
CHANGED
|
@@ -2,11 +2,16 @@
|
|
|
2
2
|
export type FetchLike = (input: string, init: RequestInit) => Promise<Response>;
|
|
3
3
|
/** One HTTP attempt, fully resolved: no routing, retry or rate-limit concerns. */
|
|
4
4
|
export interface TransportRequest {
|
|
5
|
-
/** Uppercased HTTP method. */
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
/**
|
|
5
|
+
/** Uppercased HTTP method. */
|
|
6
|
+
method: string;
|
|
7
|
+
/** Path with query string, relative to the transport's base URL. */
|
|
8
|
+
path: string;
|
|
9
|
+
/** Request headers, already including authorization. */
|
|
10
|
+
headers: Record<string, string>;
|
|
11
|
+
/** Encoded body, or undefined for a bodyless request. */
|
|
12
|
+
body?: BodyInit;
|
|
13
|
+
/** Caller cancellation signal. */
|
|
14
|
+
signal?: AbortSignal;
|
|
10
15
|
}
|
|
11
16
|
/** Thrown by {@link HttpTransport} when the attempt never produced a response. */
|
|
12
17
|
export declare class TransportError extends Error {
|
package/dist/rest/webhook.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type RESTFileAttachment } from "./index.js";
|
|
2
|
+
import type { APIEmbed, APIMessage, APIMessageComponent } from "@lunibee/types";
|
|
2
3
|
export interface WebhookClientOptions {
|
|
3
4
|
id?: string;
|
|
4
5
|
token?: string;
|
|
@@ -12,8 +13,11 @@ export interface WebhookMessageOptions {
|
|
|
12
13
|
embeds?: (APIEmbed | {
|
|
13
14
|
toJSON(): APIEmbed;
|
|
14
15
|
})[];
|
|
15
|
-
components?:
|
|
16
|
-
|
|
16
|
+
components?: (APIMessageComponent | {
|
|
17
|
+
toJSON(): APIMessageComponent;
|
|
18
|
+
})[];
|
|
19
|
+
/** Uploaded as multipart form data. */
|
|
20
|
+
files?: RESTFileAttachment[];
|
|
17
21
|
flags?: number;
|
|
18
22
|
thread_id?: string;
|
|
19
23
|
}
|
|
@@ -33,8 +37,8 @@ export declare class WebhookClient {
|
|
|
33
37
|
/** Edits a previously sent webhook message. */
|
|
34
38
|
editMessage(messageId: string, options: string | {
|
|
35
39
|
content?: string;
|
|
36
|
-
embeds?:
|
|
37
|
-
}): Promise<
|
|
40
|
+
embeds?: APIEmbed[];
|
|
41
|
+
}): Promise<APIMessage>;
|
|
38
42
|
/** Deletes a previously sent webhook message. */
|
|
39
43
|
deleteMessage(messageId: string): Promise<void>;
|
|
40
44
|
}
|
package/dist/sharding/bus.d.ts
CHANGED
|
@@ -1,34 +1,61 @@
|
|
|
1
|
+
import { type ShardBusTransport } from "./transport.js";
|
|
1
2
|
/** Message envelope exchanged between Lunibee shards. */
|
|
2
3
|
export interface ShardMessage<T = unknown> {
|
|
3
|
-
/** Sending shard ID. */
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
|
|
4
|
+
/** Sending shard ID. */
|
|
5
|
+
source: number;
|
|
6
|
+
/** Target shard ID, or null for broadcast. */
|
|
7
|
+
target: number | null;
|
|
8
|
+
/** Application message type. */
|
|
9
|
+
type: string;
|
|
10
|
+
/** Message payload. */
|
|
11
|
+
data: T;
|
|
12
|
+
/** Unique message ID. */
|
|
13
|
+
id: string;
|
|
14
|
+
/** Set on requests that expect a reply (see {@link ShardBus.request}). */
|
|
15
|
+
expectsReply?: boolean;
|
|
9
16
|
}
|
|
10
17
|
/** A reply collected by {@link ShardBus.broadcastRequest}. */
|
|
11
18
|
export interface ShardReply<R = unknown> {
|
|
12
|
-
/** Replying shard ID. */
|
|
13
|
-
|
|
14
|
-
/** Handler
|
|
19
|
+
/** Replying shard ID. */
|
|
20
|
+
shardId: number;
|
|
21
|
+
/** Handler result, when it succeeded. */
|
|
22
|
+
result?: R;
|
|
23
|
+
/** Handler error message, when it failed. */
|
|
24
|
+
error?: string;
|
|
15
25
|
}
|
|
16
26
|
/** Handler invoked for shard messages. @typeParam T Message payload type. */
|
|
17
27
|
export type ShardMessageHandler<T = unknown> = (message: ShardMessage<T>) => unknown;
|
|
18
28
|
/** Listener for errors thrown or rejected by shard message handlers. */
|
|
19
29
|
export type ShardBusErrorHandler = (error: unknown, message: ShardMessage) => void;
|
|
20
|
-
/**
|
|
30
|
+
/** Options for a {@link ShardBus}. */
|
|
31
|
+
export interface ShardBusOptions {
|
|
32
|
+
/**
|
|
33
|
+
* How messages travel. Defaults to IPC inside a cluster forked by
|
|
34
|
+
* `ClusterManager`, and to a `BroadcastChannel` otherwise.
|
|
35
|
+
*/
|
|
36
|
+
transport?: ShardBusTransport;
|
|
37
|
+
/** Most requests waiting for a reply at once (default 10,000); more are rejected. */
|
|
38
|
+
maxPending?: number;
|
|
39
|
+
}
|
|
40
|
+
/** Cross-shard messaging: send, broadcast, and request/reply over a {@link ShardBusTransport}. */
|
|
21
41
|
export declare class ShardBus {
|
|
22
42
|
#private;
|
|
23
|
-
/** BroadcastChannel name used by this bus. */
|
|
43
|
+
/** BroadcastChannel name used by this bus. */
|
|
44
|
+
readonly channelName: string;
|
|
24
45
|
/** Creates a shard bus. @param shardId Shard ID. @param channelName Application-specific channel name. @throws {RangeError} If shard ID is invalid. @throws {TypeError} If channel name is empty. */
|
|
25
|
-
constructor(shardId: number, channelName: string);
|
|
26
|
-
/** Registers a message handler. @param type Message type. @param handler Handler callback. @returns This bus. @throws {TypeError} If type or handler is invalid. */
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
|
|
46
|
+
constructor(shardId: number, channelName: string, options?: ShardBusOptions);
|
|
47
|
+
/** Registers a message handler. @param type Message type. @param handler Handler callback. @returns This bus. @throws {TypeError} If type or handler is invalid. */
|
|
48
|
+
on<T>(type: string, handler: ShardMessageHandler<T>): this;
|
|
49
|
+
/** Removes a message handler. @param type Message type. @param handler Handler callback. @returns This bus. */
|
|
50
|
+
off<T>(type: string, handler: ShardMessageHandler<T>): this;
|
|
51
|
+
/** Registers a listener for errors thrown or rejected by message handlers. Without one, handler errors are isolated and dropped. @param handler Error listener. @returns This bus. @throws {TypeError} If handler is invalid. */
|
|
52
|
+
onError(handler: ShardBusErrorHandler): this;
|
|
53
|
+
/** Removes a handler error listener. @param handler Error listener. @returns This bus. */
|
|
54
|
+
offError(handler: ShardBusErrorHandler): this;
|
|
55
|
+
/** Sends a targeted shard message. @param target Target shard ID. @param type Message type. @param data Payload. @returns Unique message ID. */
|
|
56
|
+
send<T>(target: number, type: string, data: T): string;
|
|
57
|
+
/** Broadcasts to all other shards. @param type Message type. @param data Payload. @returns Unique message ID. */
|
|
58
|
+
broadcast<T>(type: string, data: T): string;
|
|
32
59
|
/**
|
|
33
60
|
* Registers a handler that answers requests of `type`. Its return value (or
|
|
34
61
|
* thrown error) is sent back to the requesting shard. Discord.js-familiar
|
|
@@ -49,5 +76,6 @@ export declare class ShardBus {
|
|
|
49
76
|
timeoutMs?: number;
|
|
50
77
|
expected?: number;
|
|
51
78
|
}): Promise<ShardReply<R>[]>;
|
|
52
|
-
/** Closes the transport. @returns Nothing. */
|
|
79
|
+
/** Closes the transport. @returns Nothing. */
|
|
80
|
+
close(): void;
|
|
53
81
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ChildProcess } from "node:child_process";
|
|
2
|
+
import { type SupervisorOptions } from "./supervisor.js";
|
|
2
3
|
/** Configuration for managing multiple shard clusters. */
|
|
3
4
|
export interface ClusterManagerOptions {
|
|
4
5
|
/** Discord bot token. */
|
|
@@ -23,6 +24,16 @@ export interface ClusterManagerOptions {
|
|
|
23
24
|
restartOnExit?: boolean;
|
|
24
25
|
/** Delay in milliseconds before re-forking a crashed cluster. Defaults to 5000. */
|
|
25
26
|
restartDelay?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Backoff, jitter and a give-up limit for restarts. `restartDelay` is its
|
|
29
|
+
* first delay unless it sets its own. The default restarts every crash
|
|
30
|
+
* after a fixed delay, as before.
|
|
31
|
+
*/
|
|
32
|
+
supervisor?: Omit<SupervisorOptions, "restartDelay"> & {
|
|
33
|
+
restartDelay?: number;
|
|
34
|
+
};
|
|
35
|
+
/** Called when a cluster crashed more often than `supervisor.maxRestarts` allows and will not be restarted. */
|
|
36
|
+
onGiveUp?(cluster: ClusterInfo): void;
|
|
26
37
|
/** Called whenever a cluster process exits, before any restart. */
|
|
27
38
|
onClusterExit?(cluster: ClusterInfo, code: number | null, signal: NodeJS.Signals | null): void;
|
|
28
39
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** `/gateway/bot` information used to pace shard startup. */
|
|
2
|
+
export interface GatewayBotInfo {
|
|
3
|
+
/** Recommended shard count. */
|
|
4
|
+
shards: number;
|
|
5
|
+
/** IDENTIFY budget, when Discord reported it. */
|
|
6
|
+
sessionStartLimit?: {
|
|
7
|
+
total: number;
|
|
8
|
+
remaining: number;
|
|
9
|
+
/** Milliseconds until `remaining` resets. */
|
|
10
|
+
resetAfter: number;
|
|
11
|
+
maxConcurrency: number;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Asks Discord for the recommended shard count and the IDENTIFY budget.
|
|
16
|
+
* @throws {Error} If the request fails or the answer is not usable.
|
|
17
|
+
*/
|
|
18
|
+
export declare function fetchGatewayBot(token: string): Promise<GatewayBotInfo>;
|
package/dist/sharding/index.d.ts
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
+
import { type GatewayBotInfo } from "./gateway-bot.js";
|
|
1
2
|
import { Gateway } from "@lunibee/ws";
|
|
3
|
+
export { fetchGatewayBot, type GatewayBotInfo } from "./gateway-bot.js";
|
|
2
4
|
export { ShardBus } from "./bus.js";
|
|
3
|
-
export
|
|
5
|
+
export { BroadcastChannelTransport, IpcTransport, type IpcEndpoint, type ShardBusTransport, } from "./transport.js";
|
|
6
|
+
export { ShardSupervisor, type SupervisorOptions } from "./supervisor.js";
|
|
7
|
+
export type { ShardBusErrorHandler, ShardBusOptions, ShardMessage, ShardMessageHandler, ShardReply, } from "./bus.js";
|
|
4
8
|
export { ClusterManager } from "./cluster.js";
|
|
5
9
|
export type { ClusterManagerOptions, ClusterInfo } from "./cluster.js";
|
|
6
10
|
/** Configuration for a sharded Gateway client. */
|
|
7
11
|
export interface ShardManagerOptions {
|
|
8
|
-
/** Bot token. */
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
+
/** Bot token. */
|
|
13
|
+
token: string;
|
|
14
|
+
/** Gateway intents as an array, e.g. `[GatewayIntentBits.Guilds]`. */
|
|
15
|
+
intents: ConstructorParameters<typeof Gateway>[0]["intents"];
|
|
16
|
+
/** Number of shards. Use `"auto"` to request Discord's recommended count. */
|
|
17
|
+
shardCount?: number | "auto";
|
|
18
|
+
/** Gateway reconnect behavior. */
|
|
19
|
+
reconnect?: boolean;
|
|
12
20
|
/**
|
|
13
21
|
* Delay between shard starts in milliseconds. Defaults to 5000 to respect
|
|
14
22
|
* Discord's IDENTIFY rate limit (one per 5s per rate-limit key); set 0 to
|
|
@@ -23,37 +31,57 @@ export interface ShardManagerOptions {
|
|
|
23
31
|
* How long a startup round waits for its shards to send IDENTIFY/RESUME
|
|
24
32
|
* before the next round's `spawnDelay` starts. Defaults to 15000 ms.
|
|
25
33
|
*/ handshakeTimeout?: number;
|
|
26
|
-
/** Interval in milliseconds to automatically check for recommended shard count and re-scale if needed. Must be an integer >= 1000. */
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export interface GatewayBotInfo {
|
|
31
|
-
/** Recommended shard count. */ shards: number;
|
|
32
|
-
/** IDENTIFY budget, when Discord reported it. */ sessionStartLimit?: {
|
|
33
|
-
total: number;
|
|
34
|
-
remaining: number;
|
|
35
|
-
/** Milliseconds until `remaining` resets. */ resetAfter: number;
|
|
36
|
-
maxConcurrency: number;
|
|
37
|
-
};
|
|
34
|
+
/** Interval in milliseconds to automatically check for recommended shard count and re-scale if needed. Must be an integer >= 1000. */
|
|
35
|
+
autoScaleInterval?: number;
|
|
36
|
+
/** Optional handler invoked when a background auto-scale check fails. Receives the thrown error. */
|
|
37
|
+
onAutoScaleError?: (error: unknown) => void;
|
|
38
38
|
}
|
|
39
39
|
/** Health snapshot for one shard. */
|
|
40
40
|
export interface ShardHealth {
|
|
41
41
|
id: number;
|
|
42
|
-
/** Gateway connection state. */
|
|
43
|
-
|
|
42
|
+
/** Gateway connection state. */
|
|
43
|
+
state: Gateway["state"];
|
|
44
|
+
/** Last heartbeat round-trip in ms, or -1 before the first ACK. */
|
|
45
|
+
ping: number;
|
|
46
|
+
}
|
|
47
|
+
/** What `ShardManager` emits about its shards. */
|
|
48
|
+
export interface ShardManagerEvents {
|
|
49
|
+
/** A shard finished its handshake and is receiving events. */
|
|
50
|
+
shardReady: [shardId: number];
|
|
51
|
+
/** A shard's connection closed (it may reconnect by itself). */
|
|
52
|
+
shardDisconnect: [shardId: number, close: {
|
|
53
|
+
code: number;
|
|
54
|
+
action: string;
|
|
55
|
+
}];
|
|
56
|
+
/** A shard resumed its session after a reconnect. */
|
|
57
|
+
shardResume: [shardId: number];
|
|
58
|
+
/** A shard reported an error. */
|
|
59
|
+
shardError: [shardId: number, error: Error];
|
|
60
|
+
/** A shard reconnected too often too fast and is backing off (see `Gateway` `unstable`). */
|
|
61
|
+
shardUnstable: [
|
|
62
|
+
shardId: number,
|
|
63
|
+
info: {
|
|
64
|
+
reconnects: number;
|
|
65
|
+
delay: number;
|
|
66
|
+
}
|
|
67
|
+
];
|
|
44
68
|
}
|
|
45
69
|
/** Runtime state for a managed shard. */
|
|
46
70
|
export interface ShardInfo {
|
|
47
|
-
/** Shard identifier. */
|
|
48
|
-
|
|
71
|
+
/** Shard identifier. */
|
|
72
|
+
id: number;
|
|
73
|
+
/** Gateway instance. */
|
|
74
|
+
gateway: Gateway;
|
|
49
75
|
}
|
|
50
76
|
/** Manages independent Discord Gateway shards with explicit destruction and reinitialization semantics. */
|
|
51
77
|
export declare class ShardManager {
|
|
52
78
|
#private;
|
|
53
79
|
/** Discord's minimum interval between IDENTIFY payloads, in milliseconds. */
|
|
54
80
|
static readonly IDENTIFY_INTERVAL = 5000;
|
|
55
|
-
/** Active Gateway shards indexed by shard identifier. */
|
|
56
|
-
|
|
81
|
+
/** Active Gateway shards indexed by shard identifier. */
|
|
82
|
+
readonly shards: Map<number, Gateway>;
|
|
83
|
+
/** Number of shards managed by this instance after initialization. */
|
|
84
|
+
get shardCount(): number;
|
|
57
85
|
/** Creates a shard manager. @param options Sharding configuration. @throws {TypeError} If token or intents are invalid. @throws {RangeError} If shard count is invalid. */
|
|
58
86
|
constructor(options: ShardManagerOptions);
|
|
59
87
|
/** Retrieves Discord's recommended shard count. @returns Recommended shard count. @throws {Error} If discovery fails or returns invalid data. */
|
|
@@ -68,12 +96,23 @@ export declare class ShardManager {
|
|
|
68
96
|
reshard(count: number): Promise<void>;
|
|
69
97
|
/** Permanently closes the current shard set and releases Gateway resources. The next connect recreates them. @returns Nothing. */
|
|
70
98
|
destroy(): void;
|
|
99
|
+
/** Listens for an aggregated shard event. @returns This manager. */
|
|
100
|
+
on<E extends keyof ShardManagerEvents>(event: E, listener: (...args: ShardManagerEvents[E]) => void): this;
|
|
101
|
+
/** Stops listening for a shard event. @returns This manager. */
|
|
102
|
+
off<E extends keyof ShardManagerEvents>(event: E, listener: (...args: ShardManagerEvents[E]) => void): this;
|
|
71
103
|
/** Calculates the target shard ID for a Discord guild snowflake. @param guildId Guild snowflake. @returns Shard identifier. */
|
|
72
104
|
getShardIdForGuild(guildId: string): number;
|
|
73
|
-
/**
|
|
105
|
+
/** Sends a voice state update (op 4) on the shard that owns the guild. @returns Whether it was sent; `false` if that shard is absent or disconnected. */
|
|
106
|
+
sendVoiceState(guildId: string, channelId: string | null, options?: {
|
|
107
|
+
selfMute?: boolean;
|
|
108
|
+
selfDeaf?: boolean;
|
|
109
|
+
}): boolean;
|
|
110
|
+
/** Gets a shard by ID. @param id Shard identifier. @returns Gateway instance or undefined. */
|
|
111
|
+
get(id: number): Gateway | undefined;
|
|
74
112
|
/** Returns each shard's connection state and heartbeat latency. */
|
|
75
113
|
health(): ShardHealth[];
|
|
76
|
-
/** Returns information for all managed shards. @returns Shard information snapshots. */
|
|
114
|
+
/** Returns information for all managed shards. @returns Shard information snapshots. */
|
|
115
|
+
values(): ShardInfo[];
|
|
77
116
|
}
|
|
78
117
|
/** Discord.js-familiar alias for {@link ShardManager}. */
|
|
79
118
|
export { ShardManager as ShardingManager };
|