chapterjs 0.1.2 → 0.1.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.
- package/dist/assets/asset.d.ts +46 -0
- package/dist/assets/asset.js +86 -0
- package/dist/assets/public.d.ts +19 -0
- package/dist/assets/public.js +120 -0
- package/dist/cache/cache.d.ts +62 -0
- package/dist/cache/cache.js +80 -0
- package/dist/cache/store.d.ts +45 -0
- package/dist/cache/store.js +53 -0
- package/dist/cli/build.d.ts +41 -0
- package/dist/cli/build.js +206 -0
- package/dist/cli/cli.js +108 -25
- package/dist/cli/cluster.d.ts +70 -0
- package/dist/cli/cluster.js +213 -0
- package/dist/cli/dev.d.ts +18 -1
- package/dist/cli/dev.js +252 -198
- package/dist/cli/env.d.ts +31 -0
- package/dist/cli/env.js +93 -0
- package/dist/cli/log.d.ts +13 -0
- package/dist/cli/log.js +17 -0
- package/dist/cli/node-version.d.ts +8 -0
- package/dist/cli/node-version.js +13 -0
- package/dist/cli/preflight.d.ts +36 -0
- package/dist/cli/preflight.js +122 -0
- package/dist/cli/project.d.ts +122 -0
- package/dist/cli/project.js +452 -0
- package/dist/cli/start.d.ts +25 -0
- package/dist/cli/start.js +225 -0
- package/dist/commands/autocomplete.d.ts +13 -0
- package/dist/commands/autocomplete.js +159 -0
- package/dist/commands/command.d.ts +346 -0
- package/dist/commands/command.js +28 -0
- package/dist/commands/convention.d.ts +64 -0
- package/dist/commands/convention.js +464 -0
- package/dist/commands/register.d.ts +18 -0
- package/dist/commands/register.js +42 -0
- package/dist/commands/router.d.ts +20 -0
- package/dist/commands/router.js +228 -0
- package/dist/commands/tree.d.ts +43 -0
- package/dist/commands/tree.js +206 -0
- package/dist/commands/twins.d.ts +15 -0
- package/dist/commands/twins.js +78 -0
- package/dist/components/button.d.ts +79 -0
- package/dist/components/button.js +108 -0
- package/dist/components/component.d.ts +140 -0
- package/dist/components/component.js +39 -0
- package/dist/components/convention.d.ts +35 -0
- package/dist/components/convention.js +339 -0
- package/dist/components/custom-id.d.ts +72 -0
- package/dist/components/custom-id.js +128 -0
- package/dist/components/embed.d.ts +28 -0
- package/dist/components/embed.js +11 -0
- package/dist/components/file.d.ts +30 -0
- package/dist/components/file.js +52 -0
- package/dist/components/instance.d.ts +100 -0
- package/dist/components/instance.js +86 -0
- package/dist/components/layout.d.ts +103 -0
- package/dist/components/layout.js +279 -0
- package/dist/components/modal.d.ts +244 -0
- package/dist/components/modal.js +399 -0
- package/dist/components/options.d.ts +41 -0
- package/dist/components/options.js +101 -0
- package/dist/components/render.d.ts +12 -0
- package/dist/components/render.js +58 -0
- package/dist/components/router.d.ts +18 -0
- package/dist/components/router.js +256 -0
- package/dist/components/select.d.ts +144 -0
- package/dist/components/select.js +179 -0
- package/dist/core/bot.d.ts +99 -0
- package/dist/core/bot.js +174 -0
- package/dist/core/memory.d.ts +66 -0
- package/dist/core/memory.js +115 -0
- package/dist/discord/api.d.ts +112 -0
- package/dist/discord/api.js +115 -0
- package/dist/discord/cdn.d.ts +67 -0
- package/dist/discord/cdn.js +100 -0
- package/dist/discord/codes.d.ts +171 -0
- package/dist/discord/codes.js +421 -0
- package/dist/discord/endpoint.d.ts +56 -0
- package/dist/discord/endpoint.js +53 -0
- package/dist/discord/endpoints.d.ts +1529 -0
- package/dist/discord/endpoints.js +1139 -0
- package/dist/discord/formatting.d.ts +67 -0
- package/dist/discord/formatting.js +87 -0
- package/dist/discord/index.d.ts +10 -0
- package/dist/discord/index.js +13 -0
- package/dist/discord/intents.d.ts +48 -0
- package/dist/discord/intents.js +128 -0
- package/dist/discord/permissions.d.ts +94 -0
- package/dist/discord/permissions.js +185 -0
- package/dist/discord/snowflake.d.ts +21 -0
- package/dist/discord/snowflake.js +36 -0
- package/dist/discord/types/application-command.d.ts +332 -0
- package/dist/discord/types/application-command.js +48 -0
- package/dist/discord/types/application-role-connection-metadata.d.ts +42 -0
- package/dist/discord/types/application-role-connection-metadata.js +22 -0
- package/dist/discord/types/application.d.ts +208 -0
- package/dist/discord/types/application.js +48 -0
- package/dist/discord/types/audit-log.d.ts +255 -0
- package/dist/discord/types/audit-log.js +144 -0
- package/dist/discord/types/auto-moderation.d.ts +167 -0
- package/dist/discord/types/auto-moderation.js +52 -0
- package/dist/discord/types/channel.d.ts +557 -0
- package/dist/discord/types/channel.js +88 -0
- package/dist/discord/types/common.d.ts +54 -0
- package/dist/discord/types/common.js +38 -0
- package/dist/discord/types/component.d.ts +775 -0
- package/dist/discord/types/component.js +76 -0
- package/dist/discord/types/emoji.d.ts +74 -0
- package/dist/discord/types/emoji.js +1 -0
- package/dist/discord/types/entitlement.d.ts +84 -0
- package/dist/discord/types/entitlement.js +22 -0
- package/dist/discord/types/gateway-events.d.ts +1148 -0
- package/dist/discord/types/gateway-events.js +54 -0
- package/dist/discord/types/gateway.d.ts +38 -0
- package/dist/discord/types/gateway.js +1 -0
- package/dist/discord/types/guild-scheduled-event.d.ts +257 -0
- package/dist/discord/types/guild-scheduled-event.js +68 -0
- package/dist/discord/types/guild-template.d.ts +51 -0
- package/dist/discord/types/guild-template.js +1 -0
- package/dist/discord/types/guild.d.ts +910 -0
- package/dist/discord/types/guild.js +153 -0
- package/dist/discord/types/index.d.ts +31 -0
- package/dist/discord/types/index.js +31 -0
- package/dist/discord/types/interaction.d.ts +321 -0
- package/dist/discord/types/interaction.js +47 -0
- package/dist/discord/types/invite.d.ts +158 -0
- package/dist/discord/types/invite.js +39 -0
- package/dist/discord/types/message.d.ts +834 -0
- package/dist/discord/types/message.js +159 -0
- package/dist/discord/types/oauth2.d.ts +22 -0
- package/dist/discord/types/oauth2.js +1 -0
- package/dist/discord/types/permissions.d.ts +183 -0
- package/dist/discord/types/permissions.js +118 -0
- package/dist/discord/types/poll.d.ts +106 -0
- package/dist/discord/types/poll.js +8 -0
- package/dist/discord/types/sku.d.ts +47 -0
- package/dist/discord/types/sku.js +26 -0
- package/dist/discord/types/soundboard.d.ts +71 -0
- package/dist/discord/types/soundboard.js +1 -0
- package/dist/discord/types/stage-instance.d.ts +58 -0
- package/dist/discord/types/stage-instance.js +10 -0
- package/dist/discord/types/sticker.d.ts +115 -0
- package/dist/discord/types/sticker.js +20 -0
- package/dist/discord/types/subscription.d.ts +54 -0
- package/dist/discord/types/subscription.js +12 -0
- package/dist/discord/types/team.d.ts +55 -0
- package/dist/discord/types/team.js +21 -0
- package/dist/discord/types/user.d.ts +273 -0
- package/dist/discord/types/user.js +83 -0
- package/dist/discord/types/voice.d.ts +72 -0
- package/dist/discord/types/voice.js +1 -0
- package/dist/discord/types/webhook.d.ts +184 -0
- package/dist/discord/types/webhook.js +12 -0
- package/dist/events/convention.d.ts +25 -0
- package/dist/events/convention.js +97 -0
- package/dist/events/event.d.ts +8 -0
- package/dist/events/event.js +20 -0
- package/dist/events/registry.d.ts +706 -0
- package/dist/events/registry.js +839 -0
- package/dist/events/router.d.ts +45 -0
- package/dist/events/router.js +133 -0
- package/dist/events/types.d.ts +7 -0
- package/dist/events/types.js +48 -0
- package/dist/gateway/errors.d.ts +18 -0
- package/dist/gateway/errors.js +47 -0
- package/dist/gateway/gateway.d.ts +64 -0
- package/dist/gateway/gateway.js +117 -0
- package/dist/gateway/identify-queue.d.ts +25 -0
- package/dist/gateway/identify-queue.js +29 -0
- package/dist/gateway/shard.d.ts +94 -0
- package/dist/gateway/shard.js +414 -0
- package/dist/gateway/state.d.ts +11 -0
- package/dist/gateway/state.js +184 -0
- package/dist/index.d.ts +55 -18
- package/dist/index.js +38 -12
- package/dist/interactions/cooldown.d.ts +33 -0
- package/dist/interactions/cooldown.js +74 -0
- package/dist/interactions/dispatch.d.ts +91 -0
- package/dist/interactions/dispatch.js +110 -0
- package/dist/loader/generated.d.ts +37 -0
- package/dist/loader/generated.js +114 -0
- package/dist/loader/hot.d.ts +13 -0
- package/dist/loader/hot.js +85 -0
- package/dist/loader/loader.d.ts +72 -0
- package/dist/loader/loader.js +135 -0
- package/dist/loader/locate.d.ts +10 -0
- package/dist/loader/locate.js +36 -0
- package/dist/loader/watch.d.ts +17 -0
- package/dist/loader/watch.js +66 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.js +6 -0
- package/dist/messages/commands.d.ts +23 -0
- package/dist/messages/commands.js +123 -0
- package/dist/messages/convention.d.ts +89 -0
- package/dist/messages/convention.js +347 -0
- package/dist/messages/messages.d.ts +219 -0
- package/dist/messages/messages.js +30 -0
- package/dist/messages/phrases.d.ts +23 -0
- package/dist/messages/phrases.js +44 -0
- package/dist/messages/translate.d.ts +100 -0
- package/dist/messages/translate.js +249 -0
- package/dist/presence/convention.d.ts +26 -0
- package/dist/presence/convention.js +133 -0
- package/dist/presence/presence.d.ts +57 -0
- package/dist/presence/presence.js +27 -0
- package/dist/rest/errors.d.ts +55 -0
- package/dist/rest/errors.js +92 -0
- package/dist/rest/rate-limiter.d.ts +46 -0
- package/dist/rest/rate-limiter.js +153 -0
- package/dist/rest/rest.d.ts +63 -0
- package/dist/rest/rest.js +194 -0
- package/dist/structures/base.d.ts +48 -0
- package/dist/structures/base.js +84 -0
- package/dist/structures/channel.d.ts +380 -0
- package/dist/structures/channel.js +627 -0
- package/dist/structures/context.d.ts +30 -0
- package/dist/structures/context.js +7 -0
- package/dist/structures/emoji.d.ts +46 -0
- package/dist/structures/emoji.js +65 -0
- package/dist/structures/entities.d.ts +62 -0
- package/dist/structures/entities.js +226 -0
- package/dist/structures/guild.d.ts +348 -0
- package/dist/structures/guild.js +466 -0
- package/dist/structures/interaction.d.ts +197 -0
- package/dist/structures/interaction.js +396 -0
- package/dist/structures/invite.d.ts +38 -0
- package/dist/structures/invite.js +57 -0
- package/dist/structures/known.d.ts +28 -0
- package/dist/structures/known.js +58 -0
- package/dist/structures/member.d.ts +140 -0
- package/dist/structures/member.js +260 -0
- package/dist/structures/message.d.ts +197 -0
- package/dist/structures/message.js +268 -0
- package/dist/structures/payload.d.ts +91 -0
- package/dist/structures/payload.js +184 -0
- package/dist/structures/role.d.ts +69 -0
- package/dist/structures/role.js +112 -0
- package/dist/structures/user.d.ts +59 -0
- package/dist/structures/user.js +94 -0
- package/dist/structures/webhook.d.ts +46 -0
- package/dist/structures/webhook.js +79 -0
- package/dist/tasks/convention.d.ts +26 -0
- package/dist/tasks/convention.js +78 -0
- package/dist/tasks/schedule.d.ts +54 -0
- package/dist/tasks/schedule.js +236 -0
- package/dist/tasks/scheduler.d.ts +33 -0
- package/dist/tasks/scheduler.js +107 -0
- package/dist/tasks/task.d.ts +76 -0
- package/dist/tasks/task.js +28 -0
- package/dist/util/case.d.ts +13 -0
- package/dist/util/case.js +54 -0
- package/dist/util/duration.d.ts +8 -0
- package/dist/util/duration.js +29 -0
- package/dist/util/websocket.d.ts +9 -0
- package/dist/util/websocket.js +31 -0
- package/dist/voice/connection.d.ts +90 -0
- package/dist/voice/connection.js +494 -0
- package/dist/voice/dave.d.ts +109 -0
- package/dist/voice/dave.js +245 -0
- package/dist/voice/opus.d.ts +19 -0
- package/dist/voice/opus.js +273 -0
- package/dist/voice/session.d.ts +55 -0
- package/dist/voice/session.js +405 -0
- package/dist/voice/source.d.ts +22 -0
- package/dist/voice/source.js +195 -0
- package/dist/voice/transport.d.ts +43 -0
- package/dist/voice/transport.js +140 -0
- package/dist/voice/usage.d.ts +4 -0
- package/dist/voice/usage.js +33 -0
- package/package.json +26 -7
- package/vendor/dave/LICENSE +231 -0
- package/vendor/dave/libdave.d.mts +99 -0
- package/vendor/dave/libdave.mjs +2 -0
- package/vendor/dave/libdave.wasm +0 -0
- package/dist/components.d.ts +0 -97
- package/dist/components.js +0 -260
- package/dist/context.d.ts +0 -72
- package/dist/context.js +0 -273
- package/dist/discord/client.d.ts +0 -35
- package/dist/discord/client.js +0 -66
- package/dist/discord/constants.d.ts +0 -49
- package/dist/discord/constants.js +0 -61
- package/dist/discord/events.d.ts +0 -129
- package/dist/discord/events.js +0 -102
- package/dist/discord/gateway.d.ts +0 -61
- package/dist/discord/gateway.js +0 -320
- package/dist/discord/payloads.d.ts +0 -275
- package/dist/discord/payloads.js +0 -3
- package/dist/discord/presence.d.ts +0 -42
- package/dist/discord/presence.js +0 -51
- package/dist/discord/rest.d.ts +0 -49
- package/dist/discord/rest.js +0 -271
- package/dist/discord/types.d.ts +0 -334
- package/dist/discord/types.js +0 -4
- package/dist/events.d.ts +0 -94
- package/dist/events.js +0 -255
- package/dist/presence.d.ts +0 -92
- package/dist/presence.js +0 -250
- package/dist/structures/Channel.d.ts +0 -110
- package/dist/structures/Channel.js +0 -171
- package/dist/structures/Guild.d.ts +0 -70
- package/dist/structures/Guild.js +0 -105
- package/dist/structures/Interaction.d.ts +0 -113
- package/dist/structures/Interaction.js +0 -274
- package/dist/structures/Member.d.ts +0 -70
- package/dist/structures/Member.js +0 -124
- package/dist/structures/Message.d.ts +0 -87
- package/dist/structures/Message.js +0 -182
- package/dist/structures/Reaction.d.ts +0 -38
- package/dist/structures/Reaction.js +0 -64
- package/dist/structures/Role.d.ts +0 -43
- package/dist/structures/Role.js +0 -77
- package/dist/structures/User.d.ts +0 -41
- package/dist/structures/User.js +0 -79
- package/dist/structures/utils.d.ts +0 -72
- package/dist/structures/utils.js +0 -59
- package/dist/utils/errors.d.ts +0 -5
- package/dist/utils/errors.js +0 -28
- package/dist/utils/modules.d.ts +0 -39
- package/dist/utils/modules.js +0 -156
package/dist/core/bot.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// Assembles the core into a running bot: REST, cache, structures and the
|
|
2
|
+
// gateway, with events applied to the cache before anyone hears of them.
|
|
3
|
+
// Only the CLI creates one; user code never does.
|
|
4
|
+
import { Cache } from '../cache/cache.js';
|
|
5
|
+
import { Gateway, shardIdFor, } from '../gateway/gateway.js';
|
|
6
|
+
import { applyDispatch } from '../gateway/state.js';
|
|
7
|
+
import { RestClient } from '../rest/rest.js';
|
|
8
|
+
import { createContext } from '../structures/entities.js';
|
|
9
|
+
import { GatewayOpcode } from '../discord/codes.js';
|
|
10
|
+
import { GatewayIntent } from '../discord/intents.js';
|
|
11
|
+
import { VoiceManager } from '../voice/connection.js';
|
|
12
|
+
/** The server a gateway event belongs to, when it belongs to one. */
|
|
13
|
+
function guildIdOf(event, data) {
|
|
14
|
+
if (typeof data !== 'object' || data === null)
|
|
15
|
+
return undefined;
|
|
16
|
+
const fields = data;
|
|
17
|
+
// The events about a server itself carry its id as `id`.
|
|
18
|
+
const id = event === 'GUILD_CREATE' ||
|
|
19
|
+
event === 'GUILD_UPDATE' ||
|
|
20
|
+
event === 'GUILD_DELETE'
|
|
21
|
+
? fields.id
|
|
22
|
+
: fields.guild_id;
|
|
23
|
+
return typeof id === 'string' ? id : undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether an event that belongs to no server happened in a private
|
|
27
|
+
* conversation: it has a channel. What is about the bot itself (its user,
|
|
28
|
+
* its session) has none, and is always needed.
|
|
29
|
+
*/
|
|
30
|
+
function isPrivate(data) {
|
|
31
|
+
const fields = data;
|
|
32
|
+
return typeof fields.channel_id === 'string' || 'recipients' in fields;
|
|
33
|
+
}
|
|
34
|
+
export function createBot(options) {
|
|
35
|
+
const rest = new RestClient({
|
|
36
|
+
token: options.token,
|
|
37
|
+
version: options.version,
|
|
38
|
+
...options.rest,
|
|
39
|
+
});
|
|
40
|
+
const ctx = createContext({ rest, cache: new Cache(options.cache) });
|
|
41
|
+
/** Servers announced by Ready whose data has not come yet, per shard. */
|
|
42
|
+
const pending = new Map();
|
|
43
|
+
let guildsReady = null;
|
|
44
|
+
let guildsTimer = null;
|
|
45
|
+
// Until every shard is ready, a shard whose servers all came is not the
|
|
46
|
+
// whole bot: the others have not said which servers they have.
|
|
47
|
+
let shardsReady = false;
|
|
48
|
+
const checkGuilds = () => {
|
|
49
|
+
if (!guildsReady || !shardsReady)
|
|
50
|
+
return;
|
|
51
|
+
for (const ids of pending.values())
|
|
52
|
+
if (ids.size > 0)
|
|
53
|
+
return;
|
|
54
|
+
finishGuilds();
|
|
55
|
+
};
|
|
56
|
+
const finishGuilds = () => {
|
|
57
|
+
if (guildsTimer)
|
|
58
|
+
clearTimeout(guildsTimer);
|
|
59
|
+
guildsTimer = null;
|
|
60
|
+
const done = guildsReady;
|
|
61
|
+
guildsReady = null;
|
|
62
|
+
if (done) {
|
|
63
|
+
done();
|
|
64
|
+
options.onEvent?.({ type: 'guildsReady' });
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const gateway = new Gateway({
|
|
68
|
+
rest,
|
|
69
|
+
token: options.token,
|
|
70
|
+
intents: options.intents,
|
|
71
|
+
presence: options.presence,
|
|
72
|
+
shards: options.shards,
|
|
73
|
+
identifyGate: options.identifyGate,
|
|
74
|
+
...options.gateway,
|
|
75
|
+
onEvent: options.onEvent,
|
|
76
|
+
onDispatch(event, data, shardId) {
|
|
77
|
+
let joined = false;
|
|
78
|
+
let awaited = false;
|
|
79
|
+
const filter = options.guildFilter;
|
|
80
|
+
if (event === 'READY') {
|
|
81
|
+
const ready = data;
|
|
82
|
+
if (filter) {
|
|
83
|
+
// The cache and the wait for servers only know the allowed ones.
|
|
84
|
+
data = {
|
|
85
|
+
...ready,
|
|
86
|
+
guilds: ready.guilds.filter(guild => filter(guild.id)),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
pending.set(shardId, new Set(data.guilds.map(guild => guild.id)));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const guildId = guildIdOf(event, data);
|
|
93
|
+
if (guildId === undefined) {
|
|
94
|
+
if (options.privateEvents === false && isPrivate(data))
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
else if (filter && !filter(guildId)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (event === 'GUILD_CREATE' || event === 'GUILD_DELETE') {
|
|
102
|
+
const { id } = data;
|
|
103
|
+
awaited = pending.get(shardId)?.delete(id) ?? false;
|
|
104
|
+
joined =
|
|
105
|
+
event === 'GUILD_CREATE' && !awaited && !ctx.cache.guilds.has(id);
|
|
106
|
+
}
|
|
107
|
+
let before;
|
|
108
|
+
try {
|
|
109
|
+
before = options.beforeDispatch?.(event, data);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
options.onEvent?.({ type: 'stateError', event, error });
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
applyDispatch(ctx, event, data, {
|
|
116
|
+
shardId,
|
|
117
|
+
shardCount: gateway.shardCount,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
options.onEvent?.({ type: 'stateError', event, error });
|
|
122
|
+
}
|
|
123
|
+
// The bot's own voice: where it is, and the server to send audio to.
|
|
124
|
+
if (event === 'VOICE_STATE_UPDATE') {
|
|
125
|
+
const state = data;
|
|
126
|
+
if (state.user_id === ctx.self?.userId)
|
|
127
|
+
voice.onVoiceState(state);
|
|
128
|
+
}
|
|
129
|
+
else if (event === 'VOICE_SERVER_UPDATE') {
|
|
130
|
+
voice.onVoiceServer(data);
|
|
131
|
+
}
|
|
132
|
+
options.onDispatch?.(event, data, { shardId, joined, before });
|
|
133
|
+
if (awaited)
|
|
134
|
+
checkGuilds();
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
// Joining, moving and leaving voice go through the shard of the server.
|
|
138
|
+
const voice = new VoiceManager(ctx, {
|
|
139
|
+
updateVoiceState: data => gateway.send(shardIdFor(data.guild_id, gateway.shardCount), GatewayOpcode.VoiceStateUpdate, data),
|
|
140
|
+
hasVoiceStates: () => (options.intents & GatewayIntent.GuildVoiceStates) !== 0,
|
|
141
|
+
}, {
|
|
142
|
+
warn: message => options.onEvent?.({ type: 'voiceWarning', message }),
|
|
143
|
+
...(options.voice?.secure === undefined
|
|
144
|
+
? {}
|
|
145
|
+
: { secure: options.voice.secure }),
|
|
146
|
+
});
|
|
147
|
+
ctx.voice = voice;
|
|
148
|
+
return {
|
|
149
|
+
ctx,
|
|
150
|
+
gateway,
|
|
151
|
+
async connect() {
|
|
152
|
+
const allGuilds = new Promise(resolve => (guildsReady = resolve));
|
|
153
|
+
try {
|
|
154
|
+
await gateway.connect();
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
guildsReady = null;
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
shardsReady = true;
|
|
161
|
+
guildsTimer = setTimeout(finishGuilds, options.guildsTimeout ?? 15_000);
|
|
162
|
+
checkGuilds();
|
|
163
|
+
await allGuilds;
|
|
164
|
+
},
|
|
165
|
+
async close() {
|
|
166
|
+
if (guildsTimer)
|
|
167
|
+
clearTimeout(guildsTimer);
|
|
168
|
+
guildsTimer = null;
|
|
169
|
+
voice.closeAll();
|
|
170
|
+
await gateway.close();
|
|
171
|
+
},
|
|
172
|
+
setPresence: presence => gateway.setPresence(presence),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Cache, CacheLimits } from '../cache/cache.js';
|
|
2
|
+
/** How much memory the process uses, and how much it can use, in bytes. */
|
|
3
|
+
export interface MemoryReading {
|
|
4
|
+
used: number;
|
|
5
|
+
limit: number;
|
|
6
|
+
}
|
|
7
|
+
/** What Node says of its own memory. */
|
|
8
|
+
export declare const readMemory: () => MemoryReading;
|
|
9
|
+
/** What the bot remembers after its limits changed. */
|
|
10
|
+
export interface MemoryLimits {
|
|
11
|
+
/** Members remembered per server, at most. */
|
|
12
|
+
members: number;
|
|
13
|
+
/** Users remembered, at most. */
|
|
14
|
+
users: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Sets what the bot remembers when memory is not a concern, for the files
|
|
18
|
+
* of the project as they are now. What exists follows at once.
|
|
19
|
+
*/
|
|
20
|
+
export declare function configure(cache: Cache, limits: Partial<CacheLimits>): void;
|
|
21
|
+
/**
|
|
22
|
+
* Makes the bot remember half as much: half as many members per server,
|
|
23
|
+
* half as many users. The ones seen the longest ago leave. Servers,
|
|
24
|
+
* channels and roles stay: they are what keeps everything else true.
|
|
25
|
+
* Returns `null` when nothing is left to give up.
|
|
26
|
+
*/
|
|
27
|
+
export declare function tighten(cache: Cache): (MemoryLimits & {
|
|
28
|
+
forgotten: number;
|
|
29
|
+
}) | null;
|
|
30
|
+
/**
|
|
31
|
+
* Lets the bot remember more again, after memory was short: twice as many
|
|
32
|
+
* members per server, up to what was configured, and users as configured.
|
|
33
|
+
* Returns `null` when it already remembers all it may.
|
|
34
|
+
*/
|
|
35
|
+
export declare function relax(cache: Cache): MemoryLimits | null;
|
|
36
|
+
export interface MemoryWatchOptions {
|
|
37
|
+
/** The cache of the running bot, if there is one right now. */
|
|
38
|
+
cache: () => Cache | undefined;
|
|
39
|
+
/** The bot remembers less, to free memory. */
|
|
40
|
+
onTightened: (now: MemoryLimits & {
|
|
41
|
+
forgotten: number;
|
|
42
|
+
}, reading: MemoryReading) => void;
|
|
43
|
+
/** Memory is fine again and the bot remembers all it may again. */
|
|
44
|
+
onRestored: (now: MemoryLimits) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Memory is nearly full and nothing is left to give up. `freed` is what
|
|
47
|
+
* remembering less gave back, in bytes: little means the memory is not
|
|
48
|
+
* used by what the bot remembers.
|
|
49
|
+
*/
|
|
50
|
+
onFull: (reading: MemoryReading, freed: number) => void;
|
|
51
|
+
/** How full memory must be to remember less, from 0 to 1. */
|
|
52
|
+
high?: number;
|
|
53
|
+
/** How empty memory must be to remember more again, from 0 to 1. */
|
|
54
|
+
low?: number;
|
|
55
|
+
/** How often memory is looked at, in milliseconds. */
|
|
56
|
+
every?: number;
|
|
57
|
+
read?: () => MemoryReading;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Looks at the memory of the process from time to time. `check()` looks
|
|
61
|
+
* right now; `stop()` ends it.
|
|
62
|
+
*/
|
|
63
|
+
export declare function watchMemory(options: MemoryWatchOptions): {
|
|
64
|
+
check(): void;
|
|
65
|
+
stop(): void;
|
|
66
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Keeps the memory of the bot under control by itself. What the cache keeps
|
|
2
|
+
// is bounded per server, but not in total: a bot in many servers can still
|
|
3
|
+
// fill the memory of its process. Before that happens, the bot remembers
|
|
4
|
+
// less: it lowers its own limits, and raises them back when memory is fine
|
|
5
|
+
// again. It only asks for something when it has nothing left to give up.
|
|
6
|
+
import { getHeapStatistics } from 'node:v8';
|
|
7
|
+
import { storesOf } from '../structures/guild.js';
|
|
8
|
+
/** What Node says of its own memory. */
|
|
9
|
+
export const readMemory = () => ({
|
|
10
|
+
used: process.memoryUsage().heapUsed,
|
|
11
|
+
limit: getHeapStatistics().heap_size_limit,
|
|
12
|
+
});
|
|
13
|
+
/** Applies limits to what exists, and to what will. Returns what left. */
|
|
14
|
+
function apply(cache, limits) {
|
|
15
|
+
cache.setLimits(limits);
|
|
16
|
+
let forgotten = cache.users.resize(limits.users);
|
|
17
|
+
for (const guild of cache.guilds.values()) {
|
|
18
|
+
forgotten += storesOf(guild).members.resize(limits.members);
|
|
19
|
+
}
|
|
20
|
+
return forgotten;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Sets what the bot remembers when memory is not a concern, for the files
|
|
24
|
+
* of the project as they are now. What exists follows at once.
|
|
25
|
+
*/
|
|
26
|
+
export function configure(cache, limits) {
|
|
27
|
+
cache.configure(limits);
|
|
28
|
+
apply(cache, { members: cache.limits.members, users: cache.limits.users });
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Makes the bot remember half as much: half as many members per server,
|
|
32
|
+
* half as many users. The ones seen the longest ago leave. Servers,
|
|
33
|
+
* channels and roles stay: they are what keeps everything else true.
|
|
34
|
+
* Returns `null` when nothing is left to give up.
|
|
35
|
+
*/
|
|
36
|
+
export function tighten(cache) {
|
|
37
|
+
const { members, users } = cache.limits;
|
|
38
|
+
// Users have no limit of their own: half of the ones known today.
|
|
39
|
+
const limits = {
|
|
40
|
+
members: Math.floor(members / 2),
|
|
41
|
+
users: Math.floor(Math.min(users, cache.users.size) / 2),
|
|
42
|
+
};
|
|
43
|
+
if (limits.members === members && limits.users === users)
|
|
44
|
+
return null;
|
|
45
|
+
return { ...limits, forgotten: apply(cache, limits) };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Lets the bot remember more again, after memory was short: twice as many
|
|
49
|
+
* members per server, up to what was configured, and users as configured.
|
|
50
|
+
* Returns `null` when it already remembers all it may.
|
|
51
|
+
*/
|
|
52
|
+
export function relax(cache) {
|
|
53
|
+
const { members, users } = cache.limits;
|
|
54
|
+
const limits = {
|
|
55
|
+
members: Math.min(cache.configured.members, Math.max(1, members * 2)),
|
|
56
|
+
users: cache.configured.users,
|
|
57
|
+
};
|
|
58
|
+
if (limits.members === members && limits.users === users)
|
|
59
|
+
return null;
|
|
60
|
+
apply(cache, limits);
|
|
61
|
+
return limits;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Looks at the memory of the process from time to time. `check()` looks
|
|
65
|
+
* right now; `stop()` ends it.
|
|
66
|
+
*/
|
|
67
|
+
export function watchMemory(options) {
|
|
68
|
+
const { high = 0.8, low = 0.5, every = 30_000, read = readMemory } = options;
|
|
69
|
+
let highs = 0;
|
|
70
|
+
let lows = 0;
|
|
71
|
+
let said = false;
|
|
72
|
+
/** What was used when the bot started to remember less. */
|
|
73
|
+
let before;
|
|
74
|
+
const check = () => {
|
|
75
|
+
const reading = read();
|
|
76
|
+
const cache = options.cache();
|
|
77
|
+
if (reading.used >= reading.limit * high) {
|
|
78
|
+
lows = 0;
|
|
79
|
+
// Node frees memory by itself when it gets full: only a level that
|
|
80
|
+
// stays high means something has to go.
|
|
81
|
+
if (++highs < 2)
|
|
82
|
+
return;
|
|
83
|
+
const now = cache ? tighten(cache) : null;
|
|
84
|
+
if (now) {
|
|
85
|
+
before ??= reading.used;
|
|
86
|
+
options.onTightened(now, reading);
|
|
87
|
+
}
|
|
88
|
+
else if (!said) {
|
|
89
|
+
// Said once, until memory is no longer full.
|
|
90
|
+
said = true;
|
|
91
|
+
options.onFull(reading, before === undefined ? 0 : Math.max(0, before - reading.used));
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
highs = 0;
|
|
96
|
+
said = false;
|
|
97
|
+
before = undefined;
|
|
98
|
+
// Between the two levels nothing moves: limits don't go up and down.
|
|
99
|
+
if (reading.used >= reading.limit * low) {
|
|
100
|
+
lows = 0;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (++lows < 2 || !cache)
|
|
104
|
+
return;
|
|
105
|
+
const now = relax(cache);
|
|
106
|
+
// Said when everything is back, not at every step up.
|
|
107
|
+
if (now && now.members === cache.configured.members) {
|
|
108
|
+
options.onRestored(now);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const timer = setInterval(check, every);
|
|
112
|
+
// Never what keeps the process alive.
|
|
113
|
+
timer.unref();
|
|
114
|
+
return { check, stop: () => clearInterval(timer) };
|
|
115
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The API and gateway version the framework speaks.
|
|
3
|
+
* @see https://docs.discord.com/developers/reference#api-versioning
|
|
4
|
+
*/
|
|
5
|
+
export declare const API_VERSION = 10;
|
|
6
|
+
/** @see https://docs.discord.com/developers/reference#api-reference */
|
|
7
|
+
export declare const API_BASE_URL = "https://discord.com/api";
|
|
8
|
+
/** @see https://docs.discord.com/developers/reference#image-formatting */
|
|
9
|
+
export declare const CDN_BASE_URL = "https://cdn.discordapp.com";
|
|
10
|
+
/**
|
|
11
|
+
* Sticker GIFs are not served by the CDN base URL.
|
|
12
|
+
* @see https://docs.discord.com/developers/reference#image-formatting
|
|
13
|
+
*/
|
|
14
|
+
export declare const MEDIA_BASE_URL = "https://media.discordapp.net";
|
|
15
|
+
/**
|
|
16
|
+
* Milliseconds since the first second of 2015: where snowflake time starts.
|
|
17
|
+
* @see https://docs.discord.com/developers/reference#snowflakes
|
|
18
|
+
*/
|
|
19
|
+
export declare const DISCORD_EPOCH = 1420070400000n;
|
|
20
|
+
/**
|
|
21
|
+
* How many requests per second a bot can make in total.
|
|
22
|
+
* @see https://docs.discord.com/developers/topics/rate-limits#global-rate-limit
|
|
23
|
+
*/
|
|
24
|
+
export declare const GLOBAL_REQUESTS_PER_SECOND = 50;
|
|
25
|
+
/**
|
|
26
|
+
* The longest reason an audit log entry accepts, in characters.
|
|
27
|
+
* @see https://docs.discord.com/developers/resources/audit-log#audit-log-entry-object
|
|
28
|
+
*/
|
|
29
|
+
export declare const AUDIT_LOG_REASON_MAX_LENGTH = 512;
|
|
30
|
+
/**
|
|
31
|
+
* The value of the `User-Agent` header Discord requires.
|
|
32
|
+
* @see https://docs.discord.com/developers/reference#user-agent
|
|
33
|
+
*/
|
|
34
|
+
export declare function userAgent(version: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Limits Discord enforces on what a bot sends: checked before sending, so
|
|
37
|
+
* the developer gets a clear message instead of an "Invalid Form Body".
|
|
38
|
+
*/
|
|
39
|
+
export declare const Limits: {
|
|
40
|
+
/** @see https://docs.discord.com/developers/resources/message#create-message */
|
|
41
|
+
readonly MessageContent: 2000;
|
|
42
|
+
readonly MessageEmbeds: 10;
|
|
43
|
+
readonly MessageStickers: 3;
|
|
44
|
+
/** @see https://docs.discord.com/developers/reference#uploading-files */
|
|
45
|
+
readonly MessageAttachments: 10;
|
|
46
|
+
/** @see https://docs.discord.com/developers/resources/message#embed-object-embed-limits */
|
|
47
|
+
readonly EmbedTitle: 256;
|
|
48
|
+
readonly EmbedDescription: 4096;
|
|
49
|
+
readonly EmbedFields: 25;
|
|
50
|
+
readonly EmbedFieldName: 256;
|
|
51
|
+
readonly EmbedFieldValue: 1024;
|
|
52
|
+
readonly EmbedFooterText: 2048;
|
|
53
|
+
readonly EmbedAuthorName: 256;
|
|
54
|
+
/** The characters of every embed of a message, added up. */
|
|
55
|
+
readonly EmbedTotal: 6000;
|
|
56
|
+
/** @see https://docs.discord.com/developers/resources/message#bulk-delete-messages */
|
|
57
|
+
readonly BulkDeleteMin: 2;
|
|
58
|
+
readonly BulkDeleteMax: 100;
|
|
59
|
+
/** Bulk delete refuses messages older than two weeks, in milliseconds. */
|
|
60
|
+
readonly BulkDeleteMaxAge: number;
|
|
61
|
+
/** @see https://docs.discord.com/developers/resources/guild#list-guild-members */
|
|
62
|
+
readonly ListGuildMembers: 1000;
|
|
63
|
+
/** @see https://docs.discord.com/developers/resources/message#get-channel-messages */
|
|
64
|
+
readonly GetChannelMessages: 100;
|
|
65
|
+
/** @see https://docs.discord.com/developers/resources/guild#bulk-guild-ban */
|
|
66
|
+
readonly BulkBanUsers: 200;
|
|
67
|
+
/** Seconds of messages a ban can delete: 7 days. */
|
|
68
|
+
readonly BanDeleteMessageSeconds: 604800;
|
|
69
|
+
/** @see https://docs.discord.com/developers/resources/user#usernames-and-nicknames */
|
|
70
|
+
readonly Nickname: 32;
|
|
71
|
+
/** A timeout can't end more than 28 days from now, in milliseconds. */
|
|
72
|
+
readonly TimeoutMaxDuration: number;
|
|
73
|
+
/** @see https://docs.discord.com/developers/components/reference#anatomy-of-a-component-custom-id */
|
|
74
|
+
readonly CustomId: 100;
|
|
75
|
+
/** @see https://docs.discord.com/developers/components/reference#component-object */
|
|
76
|
+
readonly MessageComponents: 40;
|
|
77
|
+
/** @see https://docs.discord.com/developers/components/reference#action-row */
|
|
78
|
+
readonly ActionRowButtons: 5;
|
|
79
|
+
/** @see https://docs.discord.com/developers/components/reference#button-button-structure */
|
|
80
|
+
readonly ButtonLabel: 80;
|
|
81
|
+
readonly ButtonUrl: 512;
|
|
82
|
+
/** @see https://docs.discord.com/developers/components/reference#string-select-string-select-structure */
|
|
83
|
+
readonly SelectOptions: 25;
|
|
84
|
+
readonly SelectPlaceholder: 150;
|
|
85
|
+
/** The label, the value and the description of one option of a menu. */
|
|
86
|
+
readonly SelectOptionText: 100;
|
|
87
|
+
readonly SelectValues: 25;
|
|
88
|
+
/** The characters of every text of a message built with components. */
|
|
89
|
+
readonly TextDisplayTotal: 4000;
|
|
90
|
+
/** @see https://docs.discord.com/developers/components/reference#section-section-structure */
|
|
91
|
+
readonly SectionTexts: 3;
|
|
92
|
+
/** @see https://docs.discord.com/developers/components/reference#media-gallery-media-gallery-structure */
|
|
93
|
+
readonly MediaGalleryItems: 10;
|
|
94
|
+
readonly MediaDescription: 1024;
|
|
95
|
+
/** @see https://docs.discord.com/developers/interactions/receiving-and-responding#interaction-response-object-modal */
|
|
96
|
+
readonly ModalTitle: 45;
|
|
97
|
+
readonly ModalFields: 5;
|
|
98
|
+
/** @see https://docs.discord.com/developers/components/reference#label-label-structure */
|
|
99
|
+
readonly LabelText: 45;
|
|
100
|
+
readonly LabelDescription: 100;
|
|
101
|
+
/** @see https://docs.discord.com/developers/components/reference#text-input-text-input-structure */
|
|
102
|
+
readonly TextInputLength: 4000;
|
|
103
|
+
readonly TextInputPlaceholder: 100;
|
|
104
|
+
/** @see https://docs.discord.com/developers/components/reference#file-upload-file-upload-structure */
|
|
105
|
+
readonly FileUploadMax: 10;
|
|
106
|
+
readonly FileUploadTypes: 10;
|
|
107
|
+
/** @see https://docs.discord.com/developers/components/reference#radio-group-structure */
|
|
108
|
+
readonly RadioOptionsMin: 2;
|
|
109
|
+
readonly RadioOptions: 10;
|
|
110
|
+
/** @see https://docs.discord.com/developers/components/reference#checkbox-group-structure */
|
|
111
|
+
readonly CheckboxOptions: 10;
|
|
112
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Constants of the Discord API that never depend on a bot.
|
|
2
|
+
/**
|
|
3
|
+
* The API and gateway version the framework speaks.
|
|
4
|
+
* @see https://docs.discord.com/developers/reference#api-versioning
|
|
5
|
+
*/
|
|
6
|
+
export const API_VERSION = 10;
|
|
7
|
+
/** @see https://docs.discord.com/developers/reference#api-reference */
|
|
8
|
+
export const API_BASE_URL = 'https://discord.com/api';
|
|
9
|
+
/** @see https://docs.discord.com/developers/reference#image-formatting */
|
|
10
|
+
export const CDN_BASE_URL = 'https://cdn.discordapp.com';
|
|
11
|
+
/**
|
|
12
|
+
* Sticker GIFs are not served by the CDN base URL.
|
|
13
|
+
* @see https://docs.discord.com/developers/reference#image-formatting
|
|
14
|
+
*/
|
|
15
|
+
export const MEDIA_BASE_URL = 'https://media.discordapp.net';
|
|
16
|
+
/**
|
|
17
|
+
* Milliseconds since the first second of 2015: where snowflake time starts.
|
|
18
|
+
* @see https://docs.discord.com/developers/reference#snowflakes
|
|
19
|
+
*/
|
|
20
|
+
export const DISCORD_EPOCH = 1420070400000n;
|
|
21
|
+
/**
|
|
22
|
+
* How many requests per second a bot can make in total.
|
|
23
|
+
* @see https://docs.discord.com/developers/topics/rate-limits#global-rate-limit
|
|
24
|
+
*/
|
|
25
|
+
export const GLOBAL_REQUESTS_PER_SECOND = 50;
|
|
26
|
+
/**
|
|
27
|
+
* The longest reason an audit log entry accepts, in characters.
|
|
28
|
+
* @see https://docs.discord.com/developers/resources/audit-log#audit-log-entry-object
|
|
29
|
+
*/
|
|
30
|
+
export const AUDIT_LOG_REASON_MAX_LENGTH = 512;
|
|
31
|
+
/**
|
|
32
|
+
* The value of the `User-Agent` header Discord requires.
|
|
33
|
+
* @see https://docs.discord.com/developers/reference#user-agent
|
|
34
|
+
*/
|
|
35
|
+
export function userAgent(version) {
|
|
36
|
+
return `DiscordBot (https://github.com/chapterjs/chapterjs, ${version})`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Limits Discord enforces on what a bot sends: checked before sending, so
|
|
40
|
+
* the developer gets a clear message instead of an "Invalid Form Body".
|
|
41
|
+
*/
|
|
42
|
+
export const Limits = {
|
|
43
|
+
/** @see https://docs.discord.com/developers/resources/message#create-message */
|
|
44
|
+
MessageContent: 2000,
|
|
45
|
+
MessageEmbeds: 10,
|
|
46
|
+
MessageStickers: 3,
|
|
47
|
+
/** @see https://docs.discord.com/developers/reference#uploading-files */
|
|
48
|
+
MessageAttachments: 10,
|
|
49
|
+
/** @see https://docs.discord.com/developers/resources/message#embed-object-embed-limits */
|
|
50
|
+
EmbedTitle: 256,
|
|
51
|
+
EmbedDescription: 4096,
|
|
52
|
+
EmbedFields: 25,
|
|
53
|
+
EmbedFieldName: 256,
|
|
54
|
+
EmbedFieldValue: 1024,
|
|
55
|
+
EmbedFooterText: 2048,
|
|
56
|
+
EmbedAuthorName: 256,
|
|
57
|
+
/** The characters of every embed of a message, added up. */
|
|
58
|
+
EmbedTotal: 6000,
|
|
59
|
+
/** @see https://docs.discord.com/developers/resources/message#bulk-delete-messages */
|
|
60
|
+
BulkDeleteMin: 2,
|
|
61
|
+
BulkDeleteMax: 100,
|
|
62
|
+
/** Bulk delete refuses messages older than two weeks, in milliseconds. */
|
|
63
|
+
BulkDeleteMaxAge: 14 * 24 * 60 * 60 * 1000,
|
|
64
|
+
/** @see https://docs.discord.com/developers/resources/guild#list-guild-members */
|
|
65
|
+
ListGuildMembers: 1000,
|
|
66
|
+
/** @see https://docs.discord.com/developers/resources/message#get-channel-messages */
|
|
67
|
+
GetChannelMessages: 100,
|
|
68
|
+
/** @see https://docs.discord.com/developers/resources/guild#bulk-guild-ban */
|
|
69
|
+
BulkBanUsers: 200,
|
|
70
|
+
/** Seconds of messages a ban can delete: 7 days. */
|
|
71
|
+
BanDeleteMessageSeconds: 604_800,
|
|
72
|
+
/** @see https://docs.discord.com/developers/resources/user#usernames-and-nicknames */
|
|
73
|
+
Nickname: 32,
|
|
74
|
+
/** A timeout can't end more than 28 days from now, in milliseconds. */
|
|
75
|
+
TimeoutMaxDuration: 28 * 24 * 60 * 60 * 1000,
|
|
76
|
+
/** @see https://docs.discord.com/developers/components/reference#anatomy-of-a-component-custom-id */
|
|
77
|
+
CustomId: 100,
|
|
78
|
+
/** @see https://docs.discord.com/developers/components/reference#component-object */
|
|
79
|
+
MessageComponents: 40,
|
|
80
|
+
/** @see https://docs.discord.com/developers/components/reference#action-row */
|
|
81
|
+
ActionRowButtons: 5,
|
|
82
|
+
/** @see https://docs.discord.com/developers/components/reference#button-button-structure */
|
|
83
|
+
ButtonLabel: 80,
|
|
84
|
+
ButtonUrl: 512,
|
|
85
|
+
/** @see https://docs.discord.com/developers/components/reference#string-select-string-select-structure */
|
|
86
|
+
SelectOptions: 25,
|
|
87
|
+
SelectPlaceholder: 150,
|
|
88
|
+
/** The label, the value and the description of one option of a menu. */
|
|
89
|
+
SelectOptionText: 100,
|
|
90
|
+
SelectValues: 25,
|
|
91
|
+
/** The characters of every text of a message built with components. */
|
|
92
|
+
TextDisplayTotal: 4000,
|
|
93
|
+
/** @see https://docs.discord.com/developers/components/reference#section-section-structure */
|
|
94
|
+
SectionTexts: 3,
|
|
95
|
+
/** @see https://docs.discord.com/developers/components/reference#media-gallery-media-gallery-structure */
|
|
96
|
+
MediaGalleryItems: 10,
|
|
97
|
+
MediaDescription: 1024,
|
|
98
|
+
/** @see https://docs.discord.com/developers/interactions/receiving-and-responding#interaction-response-object-modal */
|
|
99
|
+
ModalTitle: 45,
|
|
100
|
+
ModalFields: 5,
|
|
101
|
+
/** @see https://docs.discord.com/developers/components/reference#label-label-structure */
|
|
102
|
+
LabelText: 45,
|
|
103
|
+
LabelDescription: 100,
|
|
104
|
+
/** @see https://docs.discord.com/developers/components/reference#text-input-text-input-structure */
|
|
105
|
+
TextInputLength: 4000,
|
|
106
|
+
TextInputPlaceholder: 100,
|
|
107
|
+
/** @see https://docs.discord.com/developers/components/reference#file-upload-file-upload-structure */
|
|
108
|
+
FileUploadMax: 10,
|
|
109
|
+
FileUploadTypes: 10,
|
|
110
|
+
/** @see https://docs.discord.com/developers/components/reference#radio-group-structure */
|
|
111
|
+
RadioOptionsMin: 2,
|
|
112
|
+
RadioOptions: 10,
|
|
113
|
+
/** @see https://docs.discord.com/developers/components/reference#checkbox-group-structure */
|
|
114
|
+
CheckboxOptions: 10,
|
|
115
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Snowflake } from './types/common.js';
|
|
2
|
+
import { StickerFormatType } from './types/sticker.js';
|
|
3
|
+
/** @see https://docs.discord.com/developers/reference#image-formatting-image-formats */
|
|
4
|
+
export type ImageFormat = 'png' | 'jpg' | 'jpeg' | 'webp' | 'gif';
|
|
5
|
+
/** Image size can be any power of two between 16 and 4096. */
|
|
6
|
+
export type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
|
7
|
+
export interface ImageOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The file format. By default: WebP, which Discord recommends since it
|
|
10
|
+
* works for still and animated images, whatever was uploaded.
|
|
11
|
+
*/
|
|
12
|
+
format?: ImageFormat;
|
|
13
|
+
/** The size in pixels: a power of two between 16 and 4096. */
|
|
14
|
+
size?: ImageSize;
|
|
15
|
+
/**
|
|
16
|
+
* `false` to get the first frame of an animated image. By default an
|
|
17
|
+
* animated image stays animated.
|
|
18
|
+
*/
|
|
19
|
+
animated?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** @see https://docs.discord.com/developers/reference#image-formatting-cdn-endpoints */
|
|
22
|
+
export declare const cdn: {
|
|
23
|
+
/** Custom Emoji */
|
|
24
|
+
readonly emoji: (emojiId: Snowflake, animated: boolean, options?: ImageOptions) => string;
|
|
25
|
+
/** Guild Icon */
|
|
26
|
+
readonly guildIcon: (guildId: Snowflake, hash: string, options?: ImageOptions) => string;
|
|
27
|
+
/** Guild Splash */
|
|
28
|
+
readonly guildSplash: (guildId: Snowflake, hash: string, options?: ImageOptions) => string;
|
|
29
|
+
/** Guild Discovery Splash */
|
|
30
|
+
readonly guildDiscoverySplash: (guildId: Snowflake, hash: string, options?: ImageOptions) => string;
|
|
31
|
+
/** Guild Banner */
|
|
32
|
+
readonly guildBanner: (guildId: Snowflake, hash: string, options?: ImageOptions) => string;
|
|
33
|
+
/** User Banner */
|
|
34
|
+
readonly userBanner: (userId: Snowflake, hash: string, options?: ImageOptions) => string;
|
|
35
|
+
/**
|
|
36
|
+
* Default User Avatar: always a PNG of a fixed size. The index is
|
|
37
|
+
* `(user_id >> 22) % 6` for users on the new username system and
|
|
38
|
+
* `discriminator % 5` for the others.
|
|
39
|
+
*/
|
|
40
|
+
readonly defaultUserAvatar: (userId: Snowflake, discriminator: string) => string;
|
|
41
|
+
/** User Avatar */
|
|
42
|
+
readonly userAvatar: (userId: Snowflake, hash: string, options?: ImageOptions) => string;
|
|
43
|
+
/** Guild Member Avatar */
|
|
44
|
+
readonly memberAvatar: (guildId: Snowflake, userId: Snowflake, hash: string, options?: ImageOptions) => string;
|
|
45
|
+
/** Guild Member Banner */
|
|
46
|
+
readonly memberBanner: (guildId: Snowflake, userId: Snowflake, hash: string, options?: ImageOptions) => string;
|
|
47
|
+
/** Avatar Decoration: always a PNG. */
|
|
48
|
+
readonly avatarDecoration: (asset: string) => string;
|
|
49
|
+
/** Application Icon */
|
|
50
|
+
readonly applicationIcon: (applicationId: Snowflake, hash: string, options?: ImageOptions) => string;
|
|
51
|
+
/** Application Cover */
|
|
52
|
+
readonly applicationCover: (applicationId: Snowflake, hash: string, options?: ImageOptions) => string;
|
|
53
|
+
/** Team Icon */
|
|
54
|
+
readonly teamIcon: (teamId: Snowflake, hash: string, options?: ImageOptions) => string;
|
|
55
|
+
/**
|
|
56
|
+
* Sticker: a PNG if its format is PNG or APNG, a Lottie file (`.json`) if
|
|
57
|
+
* it is LOTTIE, and a GIF served by another host if it is GIF. The size
|
|
58
|
+
* is fixed.
|
|
59
|
+
*/
|
|
60
|
+
readonly sticker: (stickerId: Snowflake, format: StickerFormatType) => string;
|
|
61
|
+
/** Role Icon */
|
|
62
|
+
readonly roleIcon: (roleId: Snowflake, hash: string, options?: ImageOptions) => string;
|
|
63
|
+
/** Guild Scheduled Event Cover */
|
|
64
|
+
readonly scheduledEventCover: (eventId: Snowflake, hash: string, options?: ImageOptions) => string;
|
|
65
|
+
/** Guild Tag Badge */
|
|
66
|
+
readonly guildTagBadge: (guildId: Snowflake, hash: string, options?: ImageOptions) => string;
|
|
67
|
+
};
|