chapterjs 0.1.2 → 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.
- 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 +205 -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 +253 -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 +135 -0
- package/dist/cli/project.js +517 -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 +360 -0
- package/dist/commands/command.js +28 -0
- package/dist/commands/declaration.d.ts +77 -0
- package/dist/commands/declaration.js +492 -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 +47 -0
- package/dist/commands/tree.js +216 -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 +106 -0
- package/dist/components/component.d.ts +140 -0
- package/dist/components/component.js +39 -0
- package/dist/components/custom-id.d.ts +72 -0
- package/dist/components/custom-id.js +128 -0
- package/dist/components/declaration.d.ts +42 -0
- package/dist/components/declaration.js +342 -0
- package/dist/components/declared.d.ts +29 -0
- package/dist/components/declared.js +49 -0
- package/dist/components/embed.d.ts +29 -0
- package/dist/components/embed.js +11 -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 +245 -0
- package/dist/components/modal.js +398 -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 +19 -0
- package/dist/components/router.js +251 -0
- package/dist/components/select.d.ts +146 -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/declaration.d.ts +16 -0
- package/dist/events/declaration.js +80 -0
- package/dist/events/event.d.ts +45 -0
- package/dist/events/event.js +34 -0
- package/dist/events/registry.d.ts +697 -0
- package/dist/events/registry.js +839 -0
- package/dist/events/router.d.ts +46 -0
- package/dist/events/router.js +133 -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 +57 -18
- package/dist/index.js +40 -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 +10 -0
- package/dist/loader/generated.js +80 -0
- package/dist/loader/hot.d.ts +13 -0
- package/dist/loader/hot.js +85 -0
- package/dist/loader/loader.d.ts +85 -0
- package/dist/loader/loader.js +119 -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 +2 -0
- package/dist/main.js +5 -0
- package/dist/messages/commands.d.ts +23 -0
- package/dist/messages/commands.js +142 -0
- package/dist/messages/declaration.d.ts +89 -0
- package/dist/messages/declaration.js +455 -0
- package/dist/messages/messages.d.ts +241 -0
- package/dist/messages/messages.js +31 -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/declaration.d.ts +19 -0
- package/dist/presence/declaration.js +118 -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/declaration.d.ts +16 -0
- package/dist/tasks/declaration.js +56 -0
- package/dist/tasks/schedule.d.ts +54 -0
- package/dist/tasks/schedule.js +236 -0
- package/dist/tasks/scheduler.d.ts +35 -0
- package/dist/tasks/scheduler.js +107 -0
- package/dist/tasks/task.d.ts +75 -0
- package/dist/tasks/task.js +27 -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
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type ImageOptions } from '../discord/cdn.js';
|
|
2
|
+
import type { Snowflake } from '../discord/types/common.js';
|
|
3
|
+
import type { RawEmoji } from '../discord/types/emoji.js';
|
|
4
|
+
import { IdStructure } from './base.js';
|
|
5
|
+
import type { Context } from './context.js';
|
|
6
|
+
export type GuildEmojiData = Omit<RawEmoji, 'id' | 'user'> & {
|
|
7
|
+
id: Snowflake;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A custom emoji of a server.
|
|
11
|
+
* @see https://docs.discord.com/developers/resources/emoji#emoji-object
|
|
12
|
+
*/
|
|
13
|
+
export declare class GuildEmoji extends IdStructure<GuildEmojiData> {
|
|
14
|
+
/** The id of the server of the emoji. */
|
|
15
|
+
readonly guildId: Snowflake;
|
|
16
|
+
constructor(ctx: Context, data: GuildEmojiData, guildId: Snowflake);
|
|
17
|
+
/** The name of the emoji, without the colons. */
|
|
18
|
+
get name(): string;
|
|
19
|
+
/** Whether the emoji moves. */
|
|
20
|
+
get animated(): boolean;
|
|
21
|
+
/** `false` when the server lost the boosts that gave it this emoji. */
|
|
22
|
+
get available(): boolean;
|
|
23
|
+
/** Whether the emoji belongs to an integration. */
|
|
24
|
+
get managed(): boolean;
|
|
25
|
+
/** The ids of the roles allowed to use the emoji; empty for everyone. */
|
|
26
|
+
get roleIds(): readonly Snowflake[];
|
|
27
|
+
/** The URL of the image of the emoji. */
|
|
28
|
+
url(options?: ImageOptions): string;
|
|
29
|
+
/**
|
|
30
|
+
* Renames the emoji, or changes which roles can use it.
|
|
31
|
+
* @see https://docs.discord.com/developers/resources/emoji#modify-guild-emoji
|
|
32
|
+
*/
|
|
33
|
+
edit(options: {
|
|
34
|
+
name?: string;
|
|
35
|
+
roles?: (Snowflake | {
|
|
36
|
+
id: Snowflake;
|
|
37
|
+
})[] | null;
|
|
38
|
+
}, reason?: string): Promise<GuildEmoji>;
|
|
39
|
+
/**
|
|
40
|
+
* Deletes the emoji.
|
|
41
|
+
* @see https://docs.discord.com/developers/resources/emoji#delete-guild-emoji
|
|
42
|
+
*/
|
|
43
|
+
delete(reason?: string): Promise<void>;
|
|
44
|
+
/** `<:name:id>`: shows the emoji when put in a message. */
|
|
45
|
+
toString(): string;
|
|
46
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { cdn } from '../discord/cdn.js';
|
|
2
|
+
import { DeleteGuildEmoji, ModifyGuildEmoji } from '../discord/endpoints.js';
|
|
3
|
+
import { emojiMention } from '../discord/formatting.js';
|
|
4
|
+
import { ctxOf, dataOf, idOf, IdStructure } from './base.js';
|
|
5
|
+
/**
|
|
6
|
+
* A custom emoji of a server.
|
|
7
|
+
* @see https://docs.discord.com/developers/resources/emoji#emoji-object
|
|
8
|
+
*/
|
|
9
|
+
export class GuildEmoji extends IdStructure {
|
|
10
|
+
/** The id of the server of the emoji. */
|
|
11
|
+
guildId;
|
|
12
|
+
constructor(ctx, data, guildId) {
|
|
13
|
+
super(ctx, data);
|
|
14
|
+
this.guildId = guildId;
|
|
15
|
+
}
|
|
16
|
+
/** The name of the emoji, without the colons. */
|
|
17
|
+
get name() {
|
|
18
|
+
return dataOf(this).name ?? '';
|
|
19
|
+
}
|
|
20
|
+
/** Whether the emoji moves. */
|
|
21
|
+
get animated() {
|
|
22
|
+
return dataOf(this).animated ?? false;
|
|
23
|
+
}
|
|
24
|
+
/** `false` when the server lost the boosts that gave it this emoji. */
|
|
25
|
+
get available() {
|
|
26
|
+
return dataOf(this).available ?? true;
|
|
27
|
+
}
|
|
28
|
+
/** Whether the emoji belongs to an integration. */
|
|
29
|
+
get managed() {
|
|
30
|
+
return dataOf(this).managed ?? false;
|
|
31
|
+
}
|
|
32
|
+
/** The ids of the roles allowed to use the emoji; empty for everyone. */
|
|
33
|
+
get roleIds() {
|
|
34
|
+
return dataOf(this).roles ?? [];
|
|
35
|
+
}
|
|
36
|
+
/** The URL of the image of the emoji. */
|
|
37
|
+
url(options) {
|
|
38
|
+
return cdn.emoji(this.id, this.animated, options);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Renames the emoji, or changes which roles can use it.
|
|
42
|
+
* @see https://docs.discord.com/developers/resources/emoji#modify-guild-emoji
|
|
43
|
+
*/
|
|
44
|
+
async edit(options, reason) {
|
|
45
|
+
const { rest, entities } = ctxOf(this);
|
|
46
|
+
const raw = await rest.request(ModifyGuildEmoji, [this.guildId, this.id], {
|
|
47
|
+
body: { name: options.name, roles: options.roles?.map(idOf) },
|
|
48
|
+
reason,
|
|
49
|
+
});
|
|
50
|
+
return entities.emoji(this.guildId, raw);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Deletes the emoji.
|
|
54
|
+
* @see https://docs.discord.com/developers/resources/emoji#delete-guild-emoji
|
|
55
|
+
*/
|
|
56
|
+
async delete(reason) {
|
|
57
|
+
await ctxOf(this).rest.request(DeleteGuildEmoji, [this.guildId, this.id], {
|
|
58
|
+
reason,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/** `<:name:id>`: shows the emoji when put in a message. */
|
|
62
|
+
toString() {
|
|
63
|
+
return emojiMention(this.name, this.id, this.animated);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Cache } from '../cache/cache.js';
|
|
2
|
+
import type { RawChannel } from '../discord/types/channel.js';
|
|
3
|
+
import type { Snowflake } from '../discord/types/common.js';
|
|
4
|
+
import type { RawEmoji } from '../discord/types/emoji.js';
|
|
5
|
+
import type { RawGuildCreateExtra } from '../discord/types/gateway-events.js';
|
|
6
|
+
import type { RawGuild, RawGuildMember } from '../discord/types/guild.js';
|
|
7
|
+
import type { RawInvite } from '../discord/types/invite.js';
|
|
8
|
+
import type { RawMessage } from '../discord/types/message.js';
|
|
9
|
+
import type { RawRole } from '../discord/types/permissions.js';
|
|
10
|
+
import type { RawUser } from '../discord/types/user.js';
|
|
11
|
+
import type { RawVoiceState } from '../discord/types/voice.js';
|
|
12
|
+
import type { RawWebhook } from '../discord/types/webhook.js';
|
|
13
|
+
import type { Rest } from '../rest/rest.js';
|
|
14
|
+
import { Channel } from './channel.js';
|
|
15
|
+
import type { Context } from './context.js';
|
|
16
|
+
import { GuildEmoji } from './emoji.js';
|
|
17
|
+
import { Guild, type VoiceEntry } from './guild.js';
|
|
18
|
+
import { Invite } from './invite.js';
|
|
19
|
+
import { GuildMember } from './member.js';
|
|
20
|
+
import { Message } from './message.js';
|
|
21
|
+
import { Role } from './role.js';
|
|
22
|
+
import { User } from './user.js';
|
|
23
|
+
import { Webhook } from './webhook.js';
|
|
24
|
+
export declare class Entities {
|
|
25
|
+
#private;
|
|
26
|
+
constructor(ctx: Context);
|
|
27
|
+
user(raw: RawUser): User;
|
|
28
|
+
/** A server, with everything Discord sent along (roles, channels...). */
|
|
29
|
+
guild(raw: RawGuild & Partial<RawGuildCreateExtra>): Guild;
|
|
30
|
+
/**
|
|
31
|
+
* Where someone is in voice: remembered while they are in a voice
|
|
32
|
+
* channel of a server the bot is in, forgotten when they leave it.
|
|
33
|
+
* Returns what is remembered now, nothing once they left.
|
|
34
|
+
*/
|
|
35
|
+
voiceState(guildId: Snowflake, raw: Partial<RawVoiceState>): VoiceEntry | undefined;
|
|
36
|
+
role(guildId: Snowflake, raw: RawRole): Role;
|
|
37
|
+
emoji(guildId: Snowflake, raw: RawEmoji): GuildEmoji;
|
|
38
|
+
/**
|
|
39
|
+
* A member. Discord leaves the user out in some payloads (messages,
|
|
40
|
+
* interactions): it is then given apart.
|
|
41
|
+
*/
|
|
42
|
+
member(guildId: Snowflake, raw: RawGuildMember, rawUser?: RawUser): GuildMember;
|
|
43
|
+
/**
|
|
44
|
+
* A channel of any kind. Events of a server don't always repeat its id
|
|
45
|
+
* in the channel: it is then given apart.
|
|
46
|
+
*/
|
|
47
|
+
channel(raw: RawChannel, guildId?: Snowflake): Channel;
|
|
48
|
+
/** Forgets a channel that was deleted. */
|
|
49
|
+
removeChannel(id: Snowflake): Channel | undefined;
|
|
50
|
+
/** Forgets a server the bot left, with everything that belongs to it. */
|
|
51
|
+
removeGuild(id: Snowflake): Guild | undefined;
|
|
52
|
+
message(raw: RawMessage & {
|
|
53
|
+
member?: Partial<RawGuildMember>;
|
|
54
|
+
}, guildId?: Snowflake): Message;
|
|
55
|
+
invite(raw: RawInvite): Invite;
|
|
56
|
+
webhook(raw: RawWebhook): Webhook;
|
|
57
|
+
}
|
|
58
|
+
/** Assembles what structures work with. */
|
|
59
|
+
export declare function createContext(input: {
|
|
60
|
+
rest: Rest;
|
|
61
|
+
cache: Cache;
|
|
62
|
+
}): Context;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// The single place where what Discord sends becomes structures. Everything
|
|
2
|
+
// goes through the cache: the same server, user or channel is always the
|
|
3
|
+
// same object, updated in place, whether it came from an event or from a
|
|
4
|
+
// request.
|
|
5
|
+
import { patch } from './base.js';
|
|
6
|
+
import { channelClass, messagesOf, VoiceChannel, } from './channel.js';
|
|
7
|
+
import { GuildEmoji } from './emoji.js';
|
|
8
|
+
import { Guild, storesOf, } from './guild.js';
|
|
9
|
+
import { Invite } from './invite.js';
|
|
10
|
+
import { remember } from './known.js';
|
|
11
|
+
import { GuildMember } from './member.js';
|
|
12
|
+
import { Message } from './message.js';
|
|
13
|
+
import { Role } from './role.js';
|
|
14
|
+
import { User } from './user.js';
|
|
15
|
+
import { Webhook } from './webhook.js';
|
|
16
|
+
/** Updates the cached structure, or creates and remembers a new one. */
|
|
17
|
+
function upsert(store, id, data, create) {
|
|
18
|
+
const cached = store.get(id);
|
|
19
|
+
if (cached) {
|
|
20
|
+
patch(cached, data);
|
|
21
|
+
// Seen again: the most recent of a store that keeps a limited number.
|
|
22
|
+
store.set(id, cached);
|
|
23
|
+
return cached;
|
|
24
|
+
}
|
|
25
|
+
const created = create();
|
|
26
|
+
store.set(id, created);
|
|
27
|
+
return created;
|
|
28
|
+
}
|
|
29
|
+
export class Entities {
|
|
30
|
+
#ctx;
|
|
31
|
+
constructor(ctx) {
|
|
32
|
+
this.#ctx = ctx;
|
|
33
|
+
}
|
|
34
|
+
user(raw) {
|
|
35
|
+
return upsert(this.#ctx.cache.users, raw.id, raw, () => new User(this.#ctx, raw));
|
|
36
|
+
}
|
|
37
|
+
/** A server, with everything Discord sent along (roles, channels...). */
|
|
38
|
+
guild(raw) {
|
|
39
|
+
const { roles, emojis, stickers: _stickers, channels, threads, members, voice_states: voiceStates, presences: _presences, stage_instances: _stageInstances, guild_scheduled_events: _scheduledEvents, soundboard_sounds: _soundboardSounds, ...data } = raw;
|
|
40
|
+
const guild = upsert(this.#ctx.cache.guilds, raw.id, data, () => new Guild(this.#ctx, data));
|
|
41
|
+
const stores = storesOf(guild);
|
|
42
|
+
if (roles) {
|
|
43
|
+
const ids = new Set(roles.map(role => role.id));
|
|
44
|
+
for (const id of stores.roles.keys()) {
|
|
45
|
+
if (!ids.has(id))
|
|
46
|
+
stores.roles.delete(id);
|
|
47
|
+
}
|
|
48
|
+
for (const role of roles)
|
|
49
|
+
this.role(guild.id, role);
|
|
50
|
+
}
|
|
51
|
+
if (emojis) {
|
|
52
|
+
stores.emojis.clear();
|
|
53
|
+
for (const emoji of emojis)
|
|
54
|
+
this.emoji(guild.id, emoji);
|
|
55
|
+
}
|
|
56
|
+
for (const channel of channels ?? [])
|
|
57
|
+
this.channel(channel, guild.id);
|
|
58
|
+
for (const thread of threads ?? [])
|
|
59
|
+
this.channel(thread, guild.id);
|
|
60
|
+
for (const member of members ?? [])
|
|
61
|
+
this.member(guild.id, member);
|
|
62
|
+
if (voiceStates) {
|
|
63
|
+
// Everyone in voice right now: who is not listed has left meanwhile.
|
|
64
|
+
stores.voiceStates.clear();
|
|
65
|
+
for (const state of voiceStates)
|
|
66
|
+
this.voiceState(guild.id, state);
|
|
67
|
+
}
|
|
68
|
+
return guild;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Where someone is in voice: remembered while they are in a voice
|
|
72
|
+
* channel of a server the bot is in, forgotten when they leave it.
|
|
73
|
+
* Returns what is remembered now, nothing once they left.
|
|
74
|
+
*/
|
|
75
|
+
voiceState(guildId, raw) {
|
|
76
|
+
const guild = this.#ctx.cache.guilds.get(guildId);
|
|
77
|
+
const { member: _member, guild_id: _guildId, ...state } = raw;
|
|
78
|
+
if (!guild || !state.user_id)
|
|
79
|
+
return undefined;
|
|
80
|
+
const store = storesOf(guild).voiceStates;
|
|
81
|
+
const channel = state.channel_id
|
|
82
|
+
? this.#ctx.cache.channels.get(state.channel_id)
|
|
83
|
+
: undefined;
|
|
84
|
+
if (!(channel instanceof VoiceChannel)) {
|
|
85
|
+
store.delete(state.user_id);
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
const entry = { state: state, channel };
|
|
89
|
+
store.set(state.user_id, entry);
|
|
90
|
+
return entry;
|
|
91
|
+
}
|
|
92
|
+
role(guildId, raw) {
|
|
93
|
+
const guild = this.#ctx.cache.guilds.get(guildId);
|
|
94
|
+
const create = () => new Role(this.#ctx, raw, guildId);
|
|
95
|
+
const role = guild
|
|
96
|
+
? upsert(storesOf(guild).roles, raw.id, raw, create)
|
|
97
|
+
: create();
|
|
98
|
+
remember(role, { guild });
|
|
99
|
+
return role;
|
|
100
|
+
}
|
|
101
|
+
emoji(guildId, raw) {
|
|
102
|
+
const { user: _user, ...rest } = raw;
|
|
103
|
+
const data = { ...rest, id: raw.id };
|
|
104
|
+
const guild = this.#ctx.cache.guilds.get(guildId);
|
|
105
|
+
const create = () => new GuildEmoji(this.#ctx, data, guildId);
|
|
106
|
+
return guild
|
|
107
|
+
? upsert(storesOf(guild).emojis, data.id, data, create)
|
|
108
|
+
: create();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* A member. Discord leaves the user out in some payloads (messages,
|
|
112
|
+
* interactions): it is then given apart.
|
|
113
|
+
*/
|
|
114
|
+
member(guildId, raw, rawUser) {
|
|
115
|
+
const { user: ownUser, ...data } = raw;
|
|
116
|
+
const userData = ownUser ?? rawUser;
|
|
117
|
+
if (!userData) {
|
|
118
|
+
throw new TypeError('A member needs its user to be identified.');
|
|
119
|
+
}
|
|
120
|
+
const user = this.user(userData);
|
|
121
|
+
const guild = this.#ctx.cache.guilds.get(guildId);
|
|
122
|
+
const create = () => new GuildMember(this.#ctx, data, guildId, user);
|
|
123
|
+
const member = guild
|
|
124
|
+
? upsert(storesOf(guild).members, user.id, data, create)
|
|
125
|
+
: create();
|
|
126
|
+
remember(member, { guild });
|
|
127
|
+
// The bot itself, kept by its server whatever the cache keeps.
|
|
128
|
+
if (guild && user.id === this.#ctx.self?.userId) {
|
|
129
|
+
remember(guild, { member });
|
|
130
|
+
}
|
|
131
|
+
return member;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* A channel of any kind. Events of a server don't always repeat its id
|
|
135
|
+
* in the channel: it is then given apart.
|
|
136
|
+
*/
|
|
137
|
+
channel(raw, guildId) {
|
|
138
|
+
const data = guildId && !raw.guild_id ? { ...raw, guild_id: guildId } : raw;
|
|
139
|
+
for (const recipient of data.recipients ?? [])
|
|
140
|
+
this.user(recipient);
|
|
141
|
+
const channel = upsert(this.#ctx.cache.channels, data.id, data, () => {
|
|
142
|
+
const Class = channelClass(data);
|
|
143
|
+
return new Class(this.#ctx, data);
|
|
144
|
+
});
|
|
145
|
+
const guild = data.guild_id
|
|
146
|
+
? this.#ctx.cache.guilds.get(data.guild_id)
|
|
147
|
+
: undefined;
|
|
148
|
+
if (guild) {
|
|
149
|
+
storesOf(guild).channels.set(channel.id, channel);
|
|
150
|
+
remember(channel, { guild });
|
|
151
|
+
}
|
|
152
|
+
return channel;
|
|
153
|
+
}
|
|
154
|
+
/** Forgets a channel that was deleted. */
|
|
155
|
+
removeChannel(id) {
|
|
156
|
+
const { cache } = this.#ctx;
|
|
157
|
+
const channel = cache.channels.get(id);
|
|
158
|
+
if (!channel)
|
|
159
|
+
return undefined;
|
|
160
|
+
cache.channels.delete(id);
|
|
161
|
+
const guild = channel.guildId
|
|
162
|
+
? cache.guilds.get(channel.guildId)
|
|
163
|
+
: undefined;
|
|
164
|
+
if (guild)
|
|
165
|
+
storesOf(guild).channels.delete(id);
|
|
166
|
+
return channel;
|
|
167
|
+
}
|
|
168
|
+
/** Forgets a server the bot left, with everything that belongs to it. */
|
|
169
|
+
removeGuild(id) {
|
|
170
|
+
const { cache } = this.#ctx;
|
|
171
|
+
const guild = cache.guilds.get(id);
|
|
172
|
+
if (!guild)
|
|
173
|
+
return undefined;
|
|
174
|
+
for (const channelId of storesOf(guild).channels.keys()) {
|
|
175
|
+
cache.channels.delete(channelId);
|
|
176
|
+
}
|
|
177
|
+
cache.guilds.delete(id);
|
|
178
|
+
return guild;
|
|
179
|
+
}
|
|
180
|
+
message(raw, guildId) {
|
|
181
|
+
const { author: rawAuthor, mentions: rawMentions, member, ...others } = raw;
|
|
182
|
+
const rest = others;
|
|
183
|
+
const author = this.user(rawAuthor);
|
|
184
|
+
const mentions = (rawMentions ?? []).map(user => this.user(user));
|
|
185
|
+
const data = guildId && !rest.guild_id ? { ...rest, guild_id: guildId } : rest;
|
|
186
|
+
// Messages of a server come with the member who wrote them.
|
|
187
|
+
const writer = member && data.guild_id && member.roles && !raw.webhook_id
|
|
188
|
+
? this.member(data.guild_id, member, rawAuthor)
|
|
189
|
+
: undefined;
|
|
190
|
+
const channel = this.#ctx.cache.channels.get(raw.channel_id);
|
|
191
|
+
const create = () => new Message(this.#ctx, data, author, mentions);
|
|
192
|
+
const message = channel
|
|
193
|
+
? upsert(messagesOf(channel), raw.id, data, create)
|
|
194
|
+
: create();
|
|
195
|
+
remember(message, {
|
|
196
|
+
guild: data.guild_id
|
|
197
|
+
? this.#ctx.cache.guilds.get(data.guild_id)
|
|
198
|
+
: undefined,
|
|
199
|
+
member: writer,
|
|
200
|
+
channel,
|
|
201
|
+
});
|
|
202
|
+
return message;
|
|
203
|
+
}
|
|
204
|
+
invite(raw) {
|
|
205
|
+
const { inviter, ...data } = raw;
|
|
206
|
+
return new Invite(this.#ctx, data, inviter ? this.user(inviter) : null);
|
|
207
|
+
}
|
|
208
|
+
webhook(raw) {
|
|
209
|
+
const { user, ...data } = raw;
|
|
210
|
+
if (user)
|
|
211
|
+
this.user(user);
|
|
212
|
+
return new Webhook(this.#ctx, data);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/** Assembles what structures work with. */
|
|
216
|
+
export function createContext(input) {
|
|
217
|
+
const ctx = {
|
|
218
|
+
rest: input.rest,
|
|
219
|
+
cache: input.cache,
|
|
220
|
+
self: null,
|
|
221
|
+
messages: null,
|
|
222
|
+
voice: null,
|
|
223
|
+
};
|
|
224
|
+
ctx.entities = new Entities(ctx);
|
|
225
|
+
return ctx;
|
|
226
|
+
}
|