@gakr-gakr/discord 0.1.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/account-inspect-api.ts +6 -0
- package/action-runtime-api.ts +1 -0
- package/api.ts +130 -0
- package/autobot.plugin.json +15 -0
- package/channel-config-api.ts +1 -0
- package/channel-plugin-api.ts +3 -0
- package/config-api.ts +4 -0
- package/configured-state.ts +6 -0
- package/contract-api.ts +21 -0
- package/directory-contract-api.ts +4 -0
- package/doctor-contract-api.ts +1 -0
- package/index.ts +24 -0
- package/package.json +79 -0
- package/runtime-api.actions.ts +15 -0
- package/runtime-api.lookup.ts +22 -0
- package/runtime-api.monitor.ts +50 -0
- package/runtime-api.send.ts +79 -0
- package/runtime-api.threads.ts +31 -0
- package/runtime-api.ts +181 -0
- package/runtime-setter-api.ts +3 -0
- package/secret-contract-api.ts +4 -0
- package/security-audit-contract-api.ts +1 -0
- package/security-contract-api.ts +4 -0
- package/session-key-api.ts +1 -0
- package/setup-entry.ts +9 -0
- package/setup-plugin-api.ts +3 -0
- package/src/account-inspect.ts +131 -0
- package/src/accounts.ts +205 -0
- package/src/actions/handle-action.guild-admin.ts +421 -0
- package/src/actions/handle-action.ts +402 -0
- package/src/actions/runtime.guild.ts +446 -0
- package/src/actions/runtime.messaging.messages.ts +226 -0
- package/src/actions/runtime.messaging.reactions.ts +67 -0
- package/src/actions/runtime.messaging.runtime.ts +73 -0
- package/src/actions/runtime.messaging.send.ts +336 -0
- package/src/actions/runtime.messaging.shared.ts +97 -0
- package/src/actions/runtime.messaging.ts +37 -0
- package/src/actions/runtime.moderation-shared.ts +48 -0
- package/src/actions/runtime.moderation.ts +116 -0
- package/src/actions/runtime.presence.ts +117 -0
- package/src/actions/runtime.shared.ts +86 -0
- package/src/actions/runtime.ts +87 -0
- package/src/api.ts +219 -0
- package/src/approval-handler.runtime.ts +636 -0
- package/src/approval-native.ts +219 -0
- package/src/approval-runtime.ts +14 -0
- package/src/approval-shared.ts +56 -0
- package/src/audit-core.ts +178 -0
- package/src/audit.ts +32 -0
- package/src/channel-actions.runtime.ts +1 -0
- package/src/channel-actions.ts +254 -0
- package/src/channel-api.ts +29 -0
- package/src/channel.conversation.ts +159 -0
- package/src/channel.loaders.ts +50 -0
- package/src/channel.runtime.ts +1 -0
- package/src/channel.setup.ts +12 -0
- package/src/channel.ts +728 -0
- package/src/chunk.ts +321 -0
- package/src/client.ts +143 -0
- package/src/component-custom-id.ts +72 -0
- package/src/components-registry.ts +356 -0
- package/src/components.builders.ts +410 -0
- package/src/components.modal.ts +124 -0
- package/src/components.parse.ts +407 -0
- package/src/components.ts +54 -0
- package/src/components.types.ts +187 -0
- package/src/config-schema.ts +6 -0
- package/src/config-ui-hints.ts +354 -0
- package/src/conversation-identity.ts +58 -0
- package/src/delivery-retry.ts +56 -0
- package/src/directory-cache.ts +116 -0
- package/src/directory-config.ts +58 -0
- package/src/directory-live.ts +135 -0
- package/src/doctor-contract.ts +477 -0
- package/src/doctor-shared.ts +5 -0
- package/src/doctor.ts +340 -0
- package/src/draft-chunking.ts +43 -0
- package/src/draft-stream.ts +162 -0
- package/src/error-body.ts +38 -0
- package/src/exec-approvals.ts +110 -0
- package/src/gateway-logging.ts +67 -0
- package/src/group-policy.ts +113 -0
- package/src/guilds.ts +29 -0
- package/src/inbound-event-delivery.ts +135 -0
- package/src/interactive-dispatch.ts +104 -0
- package/src/internal/api.commands.ts +51 -0
- package/src/internal/api.guild.ts +164 -0
- package/src/internal/api.interactions.ts +53 -0
- package/src/internal/api.messages.ts +113 -0
- package/src/internal/api.reactions.ts +38 -0
- package/src/internal/api.ts +61 -0
- package/src/internal/api.users.ts +19 -0
- package/src/internal/api.webhooks.ts +13 -0
- package/src/internal/client.ts +310 -0
- package/src/internal/command-deploy.ts +352 -0
- package/src/internal/commands.ts +188 -0
- package/src/internal/components.base.ts +65 -0
- package/src/internal/components.message.ts +279 -0
- package/src/internal/components.modal.ts +95 -0
- package/src/internal/components.ts +31 -0
- package/src/internal/discord.ts +11 -0
- package/src/internal/embeds.ts +35 -0
- package/src/internal/entity-cache.ts +98 -0
- package/src/internal/event-queue.ts +185 -0
- package/src/internal/gateway-close-codes.ts +25 -0
- package/src/internal/gateway-dispatch.ts +96 -0
- package/src/internal/gateway-identify-limiter.ts +26 -0
- package/src/internal/gateway-lifecycle.ts +75 -0
- package/src/internal/gateway-rate-limit.ts +104 -0
- package/src/internal/gateway.ts +479 -0
- package/src/internal/interaction-dispatch.ts +162 -0
- package/src/internal/interaction-options.ts +98 -0
- package/src/internal/interaction-response.ts +53 -0
- package/src/internal/interactions.ts +378 -0
- package/src/internal/listeners.ts +91 -0
- package/src/internal/modal-fields.ts +95 -0
- package/src/internal/payload.ts +69 -0
- package/src/internal/rest-body.ts +115 -0
- package/src/internal/rest-errors.ts +88 -0
- package/src/internal/rest-routes.ts +50 -0
- package/src/internal/rest-scheduler.ts +557 -0
- package/src/internal/rest.ts +322 -0
- package/src/internal/schemas.ts +36 -0
- package/src/internal/structures.ts +280 -0
- package/src/internal/test-builders.test-support.ts +167 -0
- package/src/internal/voice.ts +49 -0
- package/src/media-detection.ts +28 -0
- package/src/mentions.ts +147 -0
- package/src/monitor/ack-reactions.ts +70 -0
- package/src/monitor/agent-components-auth.ts +7 -0
- package/src/monitor/agent-components-context.ts +154 -0
- package/src/monitor/agent-components-data.ts +224 -0
- package/src/monitor/agent-components-dm-auth.ts +177 -0
- package/src/monitor/agent-components-guild-auth.ts +322 -0
- package/src/monitor/agent-components-helpers.runtime.ts +3 -0
- package/src/monitor/agent-components-helpers.ts +34 -0
- package/src/monitor/agent-components-reply.ts +10 -0
- package/src/monitor/agent-components.deps.runtime.ts +2 -0
- package/src/monitor/agent-components.dispatch.ts +359 -0
- package/src/monitor/agent-components.handlers.ts +303 -0
- package/src/monitor/agent-components.modal.ts +160 -0
- package/src/monitor/agent-components.plugin-interactive.ts +187 -0
- package/src/monitor/agent-components.runtime.ts +14 -0
- package/src/monitor/agent-components.system-controls.ts +215 -0
- package/src/monitor/agent-components.ts +70 -0
- package/src/monitor/agent-components.types.ts +58 -0
- package/src/monitor/agent-components.wildcard-controls.ts +171 -0
- package/src/monitor/allow-list.ts +631 -0
- package/src/monitor/auto-presence.ts +356 -0
- package/src/monitor/channel-access.ts +102 -0
- package/src/monitor/commands.ts +9 -0
- package/src/monitor/dm-command-auth.ts +259 -0
- package/src/monitor/dm-command-decision.ts +49 -0
- package/src/monitor/exec-approvals.ts +161 -0
- package/src/monitor/format.ts +45 -0
- package/src/monitor/gateway-handle.ts +34 -0
- package/src/monitor/gateway-metadata.ts +298 -0
- package/src/monitor/gateway-plugin.ts +302 -0
- package/src/monitor/gateway-registry.ts +37 -0
- package/src/monitor/gateway-supervisor.ts +206 -0
- package/src/monitor/inbound-context.ts +95 -0
- package/src/monitor/inbound-dedupe.ts +79 -0
- package/src/monitor/inbound-job.ts +118 -0
- package/src/monitor/listeners.queue.ts +91 -0
- package/src/monitor/listeners.reactions.ts +594 -0
- package/src/monitor/listeners.ts +150 -0
- package/src/monitor/message-channel-info.ts +96 -0
- package/src/monitor/message-forwarded.ts +114 -0
- package/src/monitor/message-handler.batch-gate.ts +19 -0
- package/src/monitor/message-handler.context.ts +492 -0
- package/src/monitor/message-handler.dm-preflight.ts +119 -0
- package/src/monitor/message-handler.draft-preview.ts +436 -0
- package/src/monitor/message-handler.hydration.ts +198 -0
- package/src/monitor/message-handler.module-test-helpers.ts +31 -0
- package/src/monitor/message-handler.preflight-channel-access.ts +86 -0
- package/src/monitor/message-handler.preflight-channel-context.ts +58 -0
- package/src/monitor/message-handler.preflight-context.ts +54 -0
- package/src/monitor/message-handler.preflight-helpers.ts +164 -0
- package/src/monitor/message-handler.preflight-history.ts +23 -0
- package/src/monitor/message-handler.preflight-logging.ts +36 -0
- package/src/monitor/message-handler.preflight-pluralkit.ts +28 -0
- package/src/monitor/message-handler.preflight-runtime.ts +28 -0
- package/src/monitor/message-handler.preflight-thread.ts +49 -0
- package/src/monitor/message-handler.preflight.ts +822 -0
- package/src/monitor/message-handler.preflight.types.ts +115 -0
- package/src/monitor/message-handler.process.ts +1033 -0
- package/src/monitor/message-handler.routing-preflight.ts +112 -0
- package/src/monitor/message-handler.ts +309 -0
- package/src/monitor/message-media.ts +536 -0
- package/src/monitor/message-run-queue.ts +101 -0
- package/src/monitor/message-text.ts +171 -0
- package/src/monitor/message-utils.ts +34 -0
- package/src/monitor/model-picker-preferences.ts +184 -0
- package/src/monitor/model-picker.state.ts +364 -0
- package/src/monitor/model-picker.test-utils.ts +26 -0
- package/src/monitor/model-picker.ts +38 -0
- package/src/monitor/model-picker.view.ts +722 -0
- package/src/monitor/native-command-agent-reply.ts +125 -0
- package/src/monitor/native-command-arg-ui.ts +233 -0
- package/src/monitor/native-command-auth.ts +309 -0
- package/src/monitor/native-command-bypass.ts +13 -0
- package/src/monitor/native-command-context.ts +109 -0
- package/src/monitor/native-command-dispatch.ts +35 -0
- package/src/monitor/native-command-model-picker-apply.ts +209 -0
- package/src/monitor/native-command-model-picker-interaction.ts +516 -0
- package/src/monitor/native-command-model-picker-ui.ts +357 -0
- package/src/monitor/native-command-reply.ts +185 -0
- package/src/monitor/native-command-route.ts +91 -0
- package/src/monitor/native-command-status.ts +76 -0
- package/src/monitor/native-command-ui.ts +26 -0
- package/src/monitor/native-command-ui.types.ts +20 -0
- package/src/monitor/native-command.args.ts +45 -0
- package/src/monitor/native-command.options.ts +153 -0
- package/src/monitor/native-command.runtime.ts +51 -0
- package/src/monitor/native-command.ts +747 -0
- package/src/monitor/native-command.types.ts +9 -0
- package/src/monitor/native-interaction-channel-context.ts +50 -0
- package/src/monitor/preflight-audio.runtime.ts +9 -0
- package/src/monitor/preflight-audio.ts +130 -0
- package/src/monitor/presence-cache.ts +61 -0
- package/src/monitor/presence.ts +50 -0
- package/src/monitor/provider-session.runtime.ts +12 -0
- package/src/monitor/provider.acp.ts +89 -0
- package/src/monitor/provider.allowlist.ts +398 -0
- package/src/monitor/provider.cleanup.ts +41 -0
- package/src/monitor/provider.commands.ts +129 -0
- package/src/monitor/provider.config-log.ts +45 -0
- package/src/monitor/provider.deploy-errors.ts +362 -0
- package/src/monitor/provider.deploy.ts +221 -0
- package/src/monitor/provider.interactions.ts +160 -0
- package/src/monitor/provider.lifecycle.ts +562 -0
- package/src/monitor/provider.runtime.ts +1 -0
- package/src/monitor/provider.startup-log.ts +32 -0
- package/src/monitor/provider.startup.ts +323 -0
- package/src/monitor/provider.ts +688 -0
- package/src/monitor/reply-context.ts +64 -0
- package/src/monitor/reply-delivery.ts +216 -0
- package/src/monitor/reply-safety.ts +96 -0
- package/src/monitor/rest-fetch.ts +97 -0
- package/src/monitor/route-resolution.ts +140 -0
- package/src/monitor/sender-identity.ts +81 -0
- package/src/monitor/startup-status.ts +10 -0
- package/src/monitor/status.ts +22 -0
- package/src/monitor/system-events.ts +55 -0
- package/src/monitor/thread-bindings.config.ts +35 -0
- package/src/monitor/thread-bindings.discord-api.ts +310 -0
- package/src/monitor/thread-bindings.lifecycle.ts +354 -0
- package/src/monitor/thread-bindings.manager.ts +554 -0
- package/src/monitor/thread-bindings.messages.ts +6 -0
- package/src/monitor/thread-bindings.persona.ts +25 -0
- package/src/monitor/thread-bindings.session-adapter.ts +229 -0
- package/src/monitor/thread-bindings.session-shared.ts +59 -0
- package/src/monitor/thread-bindings.session-updates.ts +35 -0
- package/src/monitor/thread-bindings.state.ts +540 -0
- package/src/monitor/thread-bindings.ts +48 -0
- package/src/monitor/thread-bindings.types.ts +83 -0
- package/src/monitor/thread-channel-context.ts +112 -0
- package/src/monitor/thread-session-close.ts +63 -0
- package/src/monitor/thread-title.ts +181 -0
- package/src/monitor/threading.auto-thread.ts +287 -0
- package/src/monitor/threading.cache.ts +45 -0
- package/src/monitor/threading.starter.ts +288 -0
- package/src/monitor/threading.ts +20 -0
- package/src/monitor/threading.types.ts +102 -0
- package/src/monitor/timeouts.ts +84 -0
- package/src/monitor/typing.ts +17 -0
- package/src/monitor.gateway.ts +75 -0
- package/src/monitor.ts +28 -0
- package/src/network-config.ts +79 -0
- package/src/normalize.ts +86 -0
- package/src/outbound-adapter.ts +327 -0
- package/src/outbound-approval.ts +29 -0
- package/src/outbound-components.ts +86 -0
- package/src/outbound-payload.ts +208 -0
- package/src/outbound-send-context.ts +92 -0
- package/src/outbound-session-route.ts +72 -0
- package/src/pluralkit.ts +58 -0
- package/src/preview-streaming.ts +18 -0
- package/src/probe.runtime.ts +1 -0
- package/src/probe.ts +237 -0
- package/src/proxy-fetch.ts +92 -0
- package/src/proxy-request-client.ts +21 -0
- package/src/recipient-resolution.ts +39 -0
- package/src/resolve-allowlist-common.ts +39 -0
- package/src/resolve-channels.ts +369 -0
- package/src/resolve-users.ts +184 -0
- package/src/retry.ts +98 -0
- package/src/runtime-api.ts +64 -0
- package/src/runtime-config.ts +16 -0
- package/src/runtime.ts +23 -0
- package/src/secret-config-contract.ts +140 -0
- package/src/security-audit.runtime.ts +1 -0
- package/src/security-audit.ts +208 -0
- package/src/security-contract.ts +47 -0
- package/src/security-doctor.ts +20 -0
- package/src/security.ts +60 -0
- package/src/send-target-parsing.ts +14 -0
- package/src/send.channels.ts +139 -0
- package/src/send.components.ts +391 -0
- package/src/send.emojis-stickers.ts +57 -0
- package/src/send.guild.ts +170 -0
- package/src/send.message-request.ts +112 -0
- package/src/send.messages.ts +229 -0
- package/src/send.outbound.ts +459 -0
- package/src/send.permissions.ts +283 -0
- package/src/send.reactions.ts +155 -0
- package/src/send.receipt.ts +69 -0
- package/src/send.shared.ts +469 -0
- package/src/send.ts +82 -0
- package/src/send.types.ts +191 -0
- package/src/send.typing.ts +9 -0
- package/src/send.voice.ts +140 -0
- package/src/send.webhook.ts +137 -0
- package/src/session-contract.ts +3 -0
- package/src/session-key-normalization.ts +47 -0
- package/src/setup-account-state.ts +144 -0
- package/src/setup-adapter.ts +14 -0
- package/src/setup-core.ts +215 -0
- package/src/setup-runtime-helpers.ts +10 -0
- package/src/setup-surface.ts +132 -0
- package/src/shared-interactive.ts +167 -0
- package/src/shared.ts +197 -0
- package/src/status-issues.ts +201 -0
- package/src/subagent-hooks.ts +232 -0
- package/src/target-parsing.ts +70 -0
- package/src/target-resolver.ts +129 -0
- package/src/targets.ts +12 -0
- package/src/token.ts +107 -0
- package/src/ui-colors.ts +27 -0
- package/src/ui.ts +20 -0
- package/src/voice/access.ts +126 -0
- package/src/voice/audio.ts +249 -0
- package/src/voice/capture-state.ts +120 -0
- package/src/voice/command.ts +284 -0
- package/src/voice/config.ts +8 -0
- package/src/voice/ingress.ts +164 -0
- package/src/voice/manager.runtime.ts +14 -0
- package/src/voice/manager.ts +1155 -0
- package/src/voice/prompt.ts +22 -0
- package/src/voice/realtime.ts +1370 -0
- package/src/voice/receive-recovery.ts +159 -0
- package/src/voice/sanitize.ts +29 -0
- package/src/voice/sdk-runtime.ts +14 -0
- package/src/voice/segment.ts +160 -0
- package/src/voice/session.ts +81 -0
- package/src/voice/speaker-context.ts +127 -0
- package/src/voice/tts.ts +151 -0
- package/src/voice-message.ts +474 -0
- package/subagent-hooks-api.ts +27 -0
- package/test-api.ts +4 -0
- package/thread-binding-api.ts +1 -0
- package/timeouts.ts +6 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ButtonStyle,
|
|
3
|
+
ComponentType,
|
|
4
|
+
type APIActionRowComponent,
|
|
5
|
+
type APIButtonComponent,
|
|
6
|
+
type APIChannelSelectComponent,
|
|
7
|
+
type APIComponentInMessageActionRow,
|
|
8
|
+
type APIContainerComponent,
|
|
9
|
+
type APIFileComponent,
|
|
10
|
+
type APIMediaGalleryComponent,
|
|
11
|
+
type APISectionComponent,
|
|
12
|
+
type APISeparatorComponent,
|
|
13
|
+
type APIStringSelectComponent,
|
|
14
|
+
type APITextDisplayComponent,
|
|
15
|
+
type APIThumbnailComponent,
|
|
16
|
+
} from "discord-api-types/v10";
|
|
17
|
+
import {
|
|
18
|
+
BaseComponent,
|
|
19
|
+
BaseMessageInteractiveComponent,
|
|
20
|
+
clean,
|
|
21
|
+
colorToNumber,
|
|
22
|
+
} from "./components.base.js";
|
|
23
|
+
|
|
24
|
+
abstract class BaseButton extends BaseMessageInteractiveComponent {
|
|
25
|
+
readonly type = ComponentType.Button;
|
|
26
|
+
abstract label: string;
|
|
27
|
+
emoji?: { name: string; id?: string; animated?: boolean };
|
|
28
|
+
style: ButtonStyle = ButtonStyle.Primary;
|
|
29
|
+
disabled = false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export abstract class Button extends BaseButton {
|
|
33
|
+
serialize(): APIButtonComponent {
|
|
34
|
+
return clean({
|
|
35
|
+
type: this.type,
|
|
36
|
+
style: this.style,
|
|
37
|
+
custom_id: this.customId,
|
|
38
|
+
label: this.label,
|
|
39
|
+
emoji: this.emoji,
|
|
40
|
+
disabled: this.disabled || undefined,
|
|
41
|
+
}) as APIButtonComponent;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export abstract class LinkButton extends BaseButton {
|
|
46
|
+
customId = "";
|
|
47
|
+
abstract url: string;
|
|
48
|
+
override style = ButtonStyle.Link;
|
|
49
|
+
override async run(): Promise<never> {
|
|
50
|
+
throw new Error("Link buttons do not run handlers");
|
|
51
|
+
}
|
|
52
|
+
serialize(): APIButtonComponent {
|
|
53
|
+
return clean({
|
|
54
|
+
type: this.type,
|
|
55
|
+
style: this.style,
|
|
56
|
+
label: this.label,
|
|
57
|
+
emoji: this.emoji,
|
|
58
|
+
disabled: this.disabled || undefined,
|
|
59
|
+
url: this.url,
|
|
60
|
+
}) as APIButtonComponent;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export abstract class AnySelectMenu extends BaseMessageInteractiveComponent {
|
|
65
|
+
placeholder?: string;
|
|
66
|
+
minValues?: number;
|
|
67
|
+
maxValues?: number;
|
|
68
|
+
disabled = false;
|
|
69
|
+
required?: boolean;
|
|
70
|
+
abstract serializeOptions(): Record<string, unknown>;
|
|
71
|
+
serialize() {
|
|
72
|
+
return clean({
|
|
73
|
+
...this.serializeOptions(),
|
|
74
|
+
custom_id: this.customId,
|
|
75
|
+
placeholder: this.placeholder,
|
|
76
|
+
min_values: this.minValues,
|
|
77
|
+
max_values: this.maxValues,
|
|
78
|
+
disabled: this.disabled || undefined,
|
|
79
|
+
required: this.required,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export abstract class StringSelectMenu extends AnySelectMenu {
|
|
85
|
+
readonly type = ComponentType.StringSelect;
|
|
86
|
+
abstract options: APIStringSelectComponent["options"];
|
|
87
|
+
serializeOptions() {
|
|
88
|
+
return { type: this.type, options: this.options };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export abstract class UserSelectMenu extends AnySelectMenu {
|
|
93
|
+
readonly type = ComponentType.UserSelect;
|
|
94
|
+
defaultValues?: unknown[];
|
|
95
|
+
serializeOptions() {
|
|
96
|
+
return { type: this.type, default_values: this.defaultValues };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export abstract class RoleSelectMenu extends AnySelectMenu {
|
|
101
|
+
readonly type = ComponentType.RoleSelect;
|
|
102
|
+
defaultValues?: unknown[];
|
|
103
|
+
serializeOptions() {
|
|
104
|
+
return { type: this.type, default_values: this.defaultValues };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export abstract class MentionableSelectMenu extends AnySelectMenu {
|
|
109
|
+
readonly type = ComponentType.MentionableSelect;
|
|
110
|
+
defaultValues?: unknown[];
|
|
111
|
+
serializeOptions() {
|
|
112
|
+
return { type: this.type, default_values: this.defaultValues };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export abstract class ChannelSelectMenu extends AnySelectMenu {
|
|
117
|
+
readonly type = ComponentType.ChannelSelect;
|
|
118
|
+
channelTypes?: APIChannelSelectComponent["channel_types"];
|
|
119
|
+
defaultValues?: unknown[];
|
|
120
|
+
serializeOptions() {
|
|
121
|
+
return {
|
|
122
|
+
type: this.type,
|
|
123
|
+
default_values: this.defaultValues,
|
|
124
|
+
channel_types: this.channelTypes,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export class Row<T extends BaseMessageInteractiveComponent> extends BaseComponent {
|
|
130
|
+
readonly type = ComponentType.ActionRow;
|
|
131
|
+
override readonly isV2 = false;
|
|
132
|
+
components: T[];
|
|
133
|
+
constructor(components: T[] = []) {
|
|
134
|
+
super();
|
|
135
|
+
this.components = components;
|
|
136
|
+
}
|
|
137
|
+
addComponent(component: T): void {
|
|
138
|
+
this.components.push(component);
|
|
139
|
+
}
|
|
140
|
+
removeComponent(component: T): void {
|
|
141
|
+
this.components = this.components.filter((entry) => entry !== component);
|
|
142
|
+
}
|
|
143
|
+
removeAllComponents(): void {
|
|
144
|
+
this.components = [];
|
|
145
|
+
}
|
|
146
|
+
serialize(): APIActionRowComponent<APIComponentInMessageActionRow> {
|
|
147
|
+
return {
|
|
148
|
+
type: this.type,
|
|
149
|
+
components: this.components.map(
|
|
150
|
+
(entry) => entry.serialize() as APIComponentInMessageActionRow,
|
|
151
|
+
),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export class TextDisplay extends BaseComponent {
|
|
157
|
+
readonly type = ComponentType.TextDisplay;
|
|
158
|
+
override readonly isV2 = true;
|
|
159
|
+
constructor(public content?: string) {
|
|
160
|
+
super();
|
|
161
|
+
}
|
|
162
|
+
serialize(): APITextDisplayComponent {
|
|
163
|
+
return clean({ type: this.type, content: this.content }) as APITextDisplayComponent;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export class Separator extends BaseComponent {
|
|
168
|
+
readonly type = ComponentType.Separator;
|
|
169
|
+
override readonly isV2 = true;
|
|
170
|
+
divider = true;
|
|
171
|
+
spacing: 1 | 2 | "small" | "large" = "small";
|
|
172
|
+
constructor(options?: { spacing?: Separator["spacing"]; divider?: boolean }) {
|
|
173
|
+
super();
|
|
174
|
+
this.spacing = options?.spacing ?? this.spacing;
|
|
175
|
+
this.divider = options?.divider ?? this.divider;
|
|
176
|
+
}
|
|
177
|
+
serialize(): APISeparatorComponent {
|
|
178
|
+
return clean({
|
|
179
|
+
type: this.type,
|
|
180
|
+
divider: this.divider,
|
|
181
|
+
spacing: this.spacing === "large" ? 2 : this.spacing === "small" ? 1 : this.spacing,
|
|
182
|
+
}) as APISeparatorComponent;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export class Thumbnail extends BaseComponent {
|
|
187
|
+
readonly type = ComponentType.Thumbnail;
|
|
188
|
+
override readonly isV2 = true;
|
|
189
|
+
constructor(public url?: string) {
|
|
190
|
+
super();
|
|
191
|
+
}
|
|
192
|
+
serialize(): APIThumbnailComponent {
|
|
193
|
+
return clean({
|
|
194
|
+
type: this.type,
|
|
195
|
+
media: this.url ? { url: this.url } : undefined,
|
|
196
|
+
}) as APIThumbnailComponent;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export class Section extends BaseComponent {
|
|
201
|
+
readonly type = ComponentType.Section;
|
|
202
|
+
override readonly isV2 = true;
|
|
203
|
+
constructor(
|
|
204
|
+
public components: TextDisplay[] = [],
|
|
205
|
+
public accessory?: Thumbnail | Button | LinkButton,
|
|
206
|
+
) {
|
|
207
|
+
super();
|
|
208
|
+
}
|
|
209
|
+
serialize(): APISectionComponent {
|
|
210
|
+
return clean({
|
|
211
|
+
type: this.type,
|
|
212
|
+
components: this.components.map((entry) => entry.serialize()),
|
|
213
|
+
accessory: this.accessory?.serialize(),
|
|
214
|
+
}) as APISectionComponent;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export class MediaGallery extends BaseComponent {
|
|
219
|
+
readonly type = ComponentType.MediaGallery;
|
|
220
|
+
override readonly isV2 = true;
|
|
221
|
+
constructor(public items: Array<{ url: string; description?: string; spoiler?: boolean }> = []) {
|
|
222
|
+
super();
|
|
223
|
+
}
|
|
224
|
+
serialize(): APIMediaGalleryComponent {
|
|
225
|
+
return {
|
|
226
|
+
type: this.type,
|
|
227
|
+
items: this.items.map((entry) => ({
|
|
228
|
+
media: { url: entry.url },
|
|
229
|
+
description: entry.description,
|
|
230
|
+
spoiler: entry.spoiler,
|
|
231
|
+
})),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export class File extends BaseComponent {
|
|
237
|
+
readonly type = ComponentType.File;
|
|
238
|
+
override readonly isV2 = true;
|
|
239
|
+
constructor(
|
|
240
|
+
public file?: `attachment://${string}`,
|
|
241
|
+
public spoiler = false,
|
|
242
|
+
) {
|
|
243
|
+
super();
|
|
244
|
+
}
|
|
245
|
+
serialize(): APIFileComponent {
|
|
246
|
+
return clean({
|
|
247
|
+
type: this.type,
|
|
248
|
+
file: this.file ? { url: this.file } : undefined,
|
|
249
|
+
spoiler: this.spoiler || undefined,
|
|
250
|
+
}) as APIFileComponent;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export class Container extends BaseComponent {
|
|
255
|
+
readonly type = ComponentType.Container;
|
|
256
|
+
override readonly isV2 = true;
|
|
257
|
+
components: Array<
|
|
258
|
+
Row<BaseMessageInteractiveComponent> | TextDisplay | Section | MediaGallery | Separator | File
|
|
259
|
+
>;
|
|
260
|
+
accentColor?: string | number;
|
|
261
|
+
spoiler = false;
|
|
262
|
+
constructor(
|
|
263
|
+
components: Container["components"] = [],
|
|
264
|
+
options?: { accentColor?: string | number; spoiler?: boolean },
|
|
265
|
+
) {
|
|
266
|
+
super();
|
|
267
|
+
this.components = components;
|
|
268
|
+
this.accentColor = options?.accentColor;
|
|
269
|
+
this.spoiler = options?.spoiler ?? false;
|
|
270
|
+
}
|
|
271
|
+
serialize(): APIContainerComponent {
|
|
272
|
+
return clean({
|
|
273
|
+
type: this.type,
|
|
274
|
+
components: this.components.map((entry) => entry.serialize()),
|
|
275
|
+
accent_color: colorToNumber(this.accentColor),
|
|
276
|
+
spoiler: this.spoiler || undefined,
|
|
277
|
+
}) as APIContainerComponent;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ComponentType, TextInputStyle, type APITextInputComponent } from "discord-api-types/v10";
|
|
2
|
+
import { BaseModalComponent, clean, parseCustomId, type ComponentData } from "./components.base.js";
|
|
3
|
+
import { AnySelectMenu, TextDisplay } from "./components.message.js";
|
|
4
|
+
|
|
5
|
+
export abstract class TextInput extends BaseModalComponent {
|
|
6
|
+
readonly type = ComponentType.TextInput;
|
|
7
|
+
customIdParser = parseCustomId;
|
|
8
|
+
style: TextInputStyle = TextInputStyle.Short;
|
|
9
|
+
minLength?: number;
|
|
10
|
+
maxLength?: number;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
value?: string;
|
|
13
|
+
placeholder?: string;
|
|
14
|
+
serialize(): APITextInputComponent {
|
|
15
|
+
return clean({
|
|
16
|
+
type: this.type,
|
|
17
|
+
custom_id: this.customId,
|
|
18
|
+
style: this.style,
|
|
19
|
+
min_length: this.minLength,
|
|
20
|
+
max_length: this.maxLength,
|
|
21
|
+
required: this.required,
|
|
22
|
+
value: this.value,
|
|
23
|
+
placeholder: this.placeholder,
|
|
24
|
+
}) as APITextInputComponent;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export abstract class CheckboxGroup extends BaseModalComponent {
|
|
29
|
+
readonly type = 22;
|
|
30
|
+
options: Array<{ value: string; label: string; description?: string; default?: boolean }> = [];
|
|
31
|
+
required?: boolean;
|
|
32
|
+
minValues?: number;
|
|
33
|
+
maxValues?: number;
|
|
34
|
+
serialize() {
|
|
35
|
+
return clean({
|
|
36
|
+
type: this.type,
|
|
37
|
+
custom_id: this.customId,
|
|
38
|
+
options: this.options,
|
|
39
|
+
required: this.required,
|
|
40
|
+
min_values: this.minValues,
|
|
41
|
+
max_values: this.maxValues,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export abstract class RadioGroup extends BaseModalComponent {
|
|
47
|
+
readonly type = 21;
|
|
48
|
+
options: Array<{ value: string; label: string; description?: string; default?: boolean }> = [];
|
|
49
|
+
required?: boolean;
|
|
50
|
+
minValues?: number;
|
|
51
|
+
maxValues?: number;
|
|
52
|
+
serialize() {
|
|
53
|
+
return clean({
|
|
54
|
+
type: this.type,
|
|
55
|
+
custom_id: this.customId,
|
|
56
|
+
options: this.options,
|
|
57
|
+
required: this.required,
|
|
58
|
+
min_values: this.minValues,
|
|
59
|
+
max_values: this.maxValues,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export abstract class Label extends BaseModalComponent {
|
|
65
|
+
readonly type = ComponentType.Label;
|
|
66
|
+
abstract label: string;
|
|
67
|
+
description?: string;
|
|
68
|
+
customId = "";
|
|
69
|
+
constructor(public component?: TextInput | AnySelectMenu | CheckboxGroup | RadioGroup) {
|
|
70
|
+
super();
|
|
71
|
+
}
|
|
72
|
+
serialize() {
|
|
73
|
+
return clean({
|
|
74
|
+
type: this.type,
|
|
75
|
+
label: this.label,
|
|
76
|
+
description: this.description,
|
|
77
|
+
component: this.component?.serialize(),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export abstract class Modal {
|
|
83
|
+
abstract title: string;
|
|
84
|
+
components: Array<Label | TextDisplay> = [];
|
|
85
|
+
abstract customId: string;
|
|
86
|
+
customIdParser = parseCustomId;
|
|
87
|
+
abstract run(interaction: unknown, data: ComponentData): unknown;
|
|
88
|
+
serialize() {
|
|
89
|
+
return {
|
|
90
|
+
title: this.title,
|
|
91
|
+
custom_id: this.customId,
|
|
92
|
+
components: this.components.map((entry) => entry.serialize()),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export {
|
|
2
|
+
BaseComponent,
|
|
3
|
+
BaseMessageInteractiveComponent,
|
|
4
|
+
BaseModalComponent,
|
|
5
|
+
clean,
|
|
6
|
+
colorToNumber,
|
|
7
|
+
parseCustomId,
|
|
8
|
+
type ComponentData,
|
|
9
|
+
type ComponentParserResult,
|
|
10
|
+
type ConditionalComponentOption,
|
|
11
|
+
} from "./components.base.js";
|
|
12
|
+
export {
|
|
13
|
+
AnySelectMenu,
|
|
14
|
+
Button,
|
|
15
|
+
ChannelSelectMenu,
|
|
16
|
+
Container,
|
|
17
|
+
File,
|
|
18
|
+
LinkButton,
|
|
19
|
+
MediaGallery,
|
|
20
|
+
MentionableSelectMenu,
|
|
21
|
+
RoleSelectMenu,
|
|
22
|
+
Row,
|
|
23
|
+
Section,
|
|
24
|
+
Separator,
|
|
25
|
+
StringSelectMenu,
|
|
26
|
+
TextDisplay,
|
|
27
|
+
Thumbnail,
|
|
28
|
+
UserSelectMenu,
|
|
29
|
+
} from "./components.message.js";
|
|
30
|
+
export { CheckboxGroup, Label, Modal, RadioGroup, TextInput } from "./components.modal.js";
|
|
31
|
+
export { serializePayload, type MessagePayload, type MessagePayloadObject } from "./payload.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "discord-api-types/v10";
|
|
2
|
+
export * from "./api.js";
|
|
3
|
+
export * from "./client.js";
|
|
4
|
+
export * from "./commands.js";
|
|
5
|
+
export * from "./components.js";
|
|
6
|
+
export * from "./embeds.js";
|
|
7
|
+
export * from "./interactions.js";
|
|
8
|
+
export * from "./listeners.js";
|
|
9
|
+
export * from "./payload.js";
|
|
10
|
+
export * from "./rest.js";
|
|
11
|
+
export * from "./structures.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { APIEmbed } from "discord-api-types/v10";
|
|
2
|
+
|
|
3
|
+
function clean<T extends Record<string, unknown>>(value: T): T {
|
|
4
|
+
return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined)) as T;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class Embed {
|
|
8
|
+
title?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
timestamp?: string;
|
|
12
|
+
color?: number;
|
|
13
|
+
footer?: APIEmbed["footer"];
|
|
14
|
+
image?: string | APIEmbed["image"];
|
|
15
|
+
thumbnail?: string | APIEmbed["thumbnail"];
|
|
16
|
+
author?: APIEmbed["author"];
|
|
17
|
+
fields?: APIEmbed["fields"];
|
|
18
|
+
constructor(embed?: APIEmbed) {
|
|
19
|
+
Object.assign(this, embed);
|
|
20
|
+
}
|
|
21
|
+
serialize(): APIEmbed {
|
|
22
|
+
return clean({
|
|
23
|
+
title: this.title,
|
|
24
|
+
description: this.description,
|
|
25
|
+
url: this.url,
|
|
26
|
+
timestamp: this.timestamp,
|
|
27
|
+
color: this.color,
|
|
28
|
+
footer: this.footer,
|
|
29
|
+
image: typeof this.image === "string" ? { url: this.image } : this.image,
|
|
30
|
+
thumbnail: typeof this.thumbnail === "string" ? { url: this.thumbnail } : this.thumbnail,
|
|
31
|
+
author: this.author,
|
|
32
|
+
fields: this.fields,
|
|
33
|
+
}) as APIEmbed;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { GatewayDispatchEvents } from "discord-api-types/v10";
|
|
2
|
+
import { getChannel, getGuild, getGuildMember, getUser } from "./api.js";
|
|
3
|
+
import type { RequestClient } from "./rest.js";
|
|
4
|
+
import { Guild, GuildMember, User, channelFactory, type StructureClient } from "./structures.js";
|
|
5
|
+
|
|
6
|
+
type CacheEntry<T> = {
|
|
7
|
+
expiresAt: number;
|
|
8
|
+
value: T;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const DEFAULT_REST_CACHE_TTL_MS = 30_000;
|
|
12
|
+
|
|
13
|
+
export class DiscordEntityCache {
|
|
14
|
+
private readonly entries = new Map<string, CacheEntry<unknown>>();
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
private readonly params: {
|
|
18
|
+
client: StructureClient;
|
|
19
|
+
rest: RequestClient | (() => RequestClient);
|
|
20
|
+
ttlMs?: number;
|
|
21
|
+
},
|
|
22
|
+
) {}
|
|
23
|
+
|
|
24
|
+
async fetchUser(id: string): Promise<User> {
|
|
25
|
+
return await this.fetchCached(`user:${id}`, async () => {
|
|
26
|
+
const raw = await getUser(this.rest, id);
|
|
27
|
+
return new User(this.params.client, raw);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async fetchChannel(id: string) {
|
|
32
|
+
return await this.fetchCached(`channel:${id}`, async () => {
|
|
33
|
+
const raw = await getChannel(this.rest, id);
|
|
34
|
+
return channelFactory(this.params.client, raw);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async fetchGuild(id: string): Promise<Guild> {
|
|
39
|
+
return await this.fetchCached(`guild:${id}`, async () => {
|
|
40
|
+
const raw = await getGuild(this.rest, id);
|
|
41
|
+
return new Guild(this.params.client, raw);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async fetchMember(guildId: string, userId: string): Promise<GuildMember> {
|
|
46
|
+
return await this.fetchCached(`member:${guildId}:${userId}`, async () => {
|
|
47
|
+
const raw = await getGuildMember(this.rest, guildId, userId);
|
|
48
|
+
return new GuildMember(this.params.client, raw);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
invalidateForGatewayEvent(type: string, data: unknown): void {
|
|
53
|
+
const raw = data && typeof data === "object" ? (data as Record<string, unknown>) : {};
|
|
54
|
+
const channelUpdate: string = GatewayDispatchEvents.ChannelUpdate;
|
|
55
|
+
const channelDelete: string = GatewayDispatchEvents.ChannelDelete;
|
|
56
|
+
const guildUpdate: string = GatewayDispatchEvents.GuildUpdate;
|
|
57
|
+
const guildMemberUpdate: string = GatewayDispatchEvents.GuildMemberUpdate;
|
|
58
|
+
if (type === channelUpdate || type === channelDelete) {
|
|
59
|
+
this.deleteId("channel", raw.id);
|
|
60
|
+
}
|
|
61
|
+
if (type === guildUpdate) {
|
|
62
|
+
this.deleteId("guild", raw.id);
|
|
63
|
+
}
|
|
64
|
+
if (type === guildMemberUpdate) {
|
|
65
|
+
const guildId = raw.guild_id;
|
|
66
|
+
const user = raw.user && typeof raw.user === "object" ? (raw.user as { id?: unknown }) : {};
|
|
67
|
+
if (typeof guildId === "string" && typeof user.id === "string") {
|
|
68
|
+
this.entries.delete(`member:${guildId}:${user.id}`);
|
|
69
|
+
this.entries.delete(`user:${user.id}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private deleteId(prefix: string, id: unknown): void {
|
|
75
|
+
if (typeof id === "string") {
|
|
76
|
+
this.entries.delete(`${prefix}:${id}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private async fetchCached<T>(key: string, fetcher: () => Promise<T>): Promise<T> {
|
|
81
|
+
const ttl = this.params.ttlMs ?? DEFAULT_REST_CACHE_TTL_MS;
|
|
82
|
+
if (ttl > 0) {
|
|
83
|
+
const cached = this.entries.get(key) as CacheEntry<T> | undefined;
|
|
84
|
+
if (cached && cached.expiresAt > Date.now()) {
|
|
85
|
+
return cached.value;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const value = await fetcher();
|
|
89
|
+
if (ttl > 0) {
|
|
90
|
+
this.entries.set(key, { expiresAt: Date.now() + ttl, value });
|
|
91
|
+
}
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private get rest(): RequestClient {
|
|
96
|
+
return typeof this.params.rest === "function" ? this.params.rest() : this.params.rest;
|
|
97
|
+
}
|
|
98
|
+
}
|