@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,67 @@
|
|
|
1
|
+
import type { EventEmitter } from "node:events";
|
|
2
|
+
import { logVerbose } from "autobot/plugin-sdk/runtime-env";
|
|
3
|
+
import type { RuntimeEnv } from "autobot/plugin-sdk/runtime-env";
|
|
4
|
+
|
|
5
|
+
type GatewayEmitter = Pick<EventEmitter, "on" | "removeListener">;
|
|
6
|
+
|
|
7
|
+
const INFO_DEBUG_MARKERS = [
|
|
8
|
+
"Gateway websocket closed",
|
|
9
|
+
"Gateway reconnect scheduled in",
|
|
10
|
+
"Gateway forcing fresh IDENTIFY after",
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
const shouldPromoteGatewayDebug = (message: string) =>
|
|
14
|
+
INFO_DEBUG_MARKERS.some((marker) => message.includes(marker));
|
|
15
|
+
|
|
16
|
+
const formatGatewayMetrics = (metrics: unknown) => {
|
|
17
|
+
if (metrics === null || metrics === undefined) {
|
|
18
|
+
return String(metrics);
|
|
19
|
+
}
|
|
20
|
+
if (typeof metrics === "string") {
|
|
21
|
+
return metrics;
|
|
22
|
+
}
|
|
23
|
+
if (typeof metrics === "number" || typeof metrics === "boolean" || typeof metrics === "bigint") {
|
|
24
|
+
return String(metrics);
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
return JSON.stringify(metrics);
|
|
28
|
+
} catch {
|
|
29
|
+
return "[unserializable metrics]";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export function attachDiscordGatewayLogging(params: {
|
|
34
|
+
emitter?: GatewayEmitter;
|
|
35
|
+
runtime: RuntimeEnv;
|
|
36
|
+
}) {
|
|
37
|
+
const { emitter, runtime } = params;
|
|
38
|
+
if (!emitter) {
|
|
39
|
+
return () => {};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const onGatewayDebug = (msg: unknown) => {
|
|
43
|
+
const message = String(msg);
|
|
44
|
+
logVerbose(`discord gateway: ${message}`);
|
|
45
|
+
if (shouldPromoteGatewayDebug(message)) {
|
|
46
|
+
runtime.log?.(`discord gateway: ${message}`);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const onGatewayWarning = (warning: unknown) => {
|
|
51
|
+
logVerbose(`discord gateway warning: ${String(warning)}`);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const onGatewayMetrics = (metrics: unknown) => {
|
|
55
|
+
logVerbose(`discord gateway metrics: ${formatGatewayMetrics(metrics)}`);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
emitter.on("debug", onGatewayDebug);
|
|
59
|
+
emitter.on("warning", onGatewayWarning);
|
|
60
|
+
emitter.on("metrics", onGatewayMetrics);
|
|
61
|
+
|
|
62
|
+
return () => {
|
|
63
|
+
emitter.removeListener("debug", onGatewayDebug);
|
|
64
|
+
emitter.removeListener("warning", onGatewayWarning);
|
|
65
|
+
emitter.removeListener("metrics", onGatewayMetrics);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { ChannelGroupContext } from "autobot/plugin-sdk/channel-contract";
|
|
2
|
+
import {
|
|
3
|
+
resolveToolsBySender,
|
|
4
|
+
type GroupToolPolicyBySenderConfig,
|
|
5
|
+
type GroupToolPolicyConfig,
|
|
6
|
+
} from "autobot/plugin-sdk/channel-policy";
|
|
7
|
+
import { normalizeOptionalString } from "autobot/plugin-sdk/string-coerce-runtime";
|
|
8
|
+
import { normalizeAtHashSlug } from "autobot/plugin-sdk/string-normalization-runtime";
|
|
9
|
+
import type { DiscordConfig } from "./runtime-api.js";
|
|
10
|
+
|
|
11
|
+
function normalizeDiscordSlug(value?: string | null) {
|
|
12
|
+
return normalizeAtHashSlug(value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type SenderScopedToolsEntry = {
|
|
16
|
+
tools?: GroupToolPolicyConfig;
|
|
17
|
+
toolsBySender?: GroupToolPolicyBySenderConfig;
|
|
18
|
+
requireMention?: boolean;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function resolveDiscordGuildEntry(guilds: DiscordConfig["guilds"], groupSpace?: string | null) {
|
|
22
|
+
if (!guilds || Object.keys(guilds).length === 0) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const space = normalizeOptionalString(groupSpace) ?? "";
|
|
26
|
+
if (space && guilds[space]) {
|
|
27
|
+
return guilds[space];
|
|
28
|
+
}
|
|
29
|
+
const normalized = normalizeDiscordSlug(space);
|
|
30
|
+
if (normalized && guilds[normalized]) {
|
|
31
|
+
return guilds[normalized];
|
|
32
|
+
}
|
|
33
|
+
if (normalized) {
|
|
34
|
+
const match = Object.values(guilds).find(
|
|
35
|
+
(entry) => normalizeDiscordSlug(entry?.slug ?? undefined) === normalized,
|
|
36
|
+
);
|
|
37
|
+
if (match) {
|
|
38
|
+
return match;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return guilds["*"] ?? null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function resolveDiscordChannelEntry<TEntry extends SenderScopedToolsEntry>(
|
|
45
|
+
channelEntries: Record<string, TEntry> | undefined,
|
|
46
|
+
params: { groupId?: string | null; groupChannel?: string | null },
|
|
47
|
+
): TEntry | undefined {
|
|
48
|
+
if (!channelEntries || Object.keys(channelEntries).length === 0) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
const groupChannel = params.groupChannel;
|
|
52
|
+
const channelSlug = normalizeDiscordSlug(groupChannel);
|
|
53
|
+
return (
|
|
54
|
+
(params.groupId ? channelEntries[params.groupId] : undefined) ??
|
|
55
|
+
(channelSlug
|
|
56
|
+
? (channelEntries[channelSlug] ?? channelEntries[`#${channelSlug}`])
|
|
57
|
+
: undefined) ??
|
|
58
|
+
(groupChannel ? channelEntries[normalizeDiscordSlug(groupChannel)] : undefined)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function resolveSenderToolsEntry(
|
|
63
|
+
entry: SenderScopedToolsEntry | undefined | null,
|
|
64
|
+
params: ChannelGroupContext,
|
|
65
|
+
): GroupToolPolicyConfig | undefined {
|
|
66
|
+
if (!entry) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
const senderPolicy = resolveToolsBySender({
|
|
70
|
+
toolsBySender: entry.toolsBySender,
|
|
71
|
+
senderId: params.senderId,
|
|
72
|
+
senderName: params.senderName,
|
|
73
|
+
senderUsername: params.senderUsername,
|
|
74
|
+
senderE164: params.senderE164,
|
|
75
|
+
});
|
|
76
|
+
return senderPolicy ?? entry.tools;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function resolveDiscordPolicyContext(params: ChannelGroupContext) {
|
|
80
|
+
const guilds =
|
|
81
|
+
(params.accountId
|
|
82
|
+
? params.cfg.channels?.discord?.accounts?.[params.accountId]?.guilds
|
|
83
|
+
: undefined) ?? params.cfg.channels?.discord?.guilds;
|
|
84
|
+
const guildEntry = resolveDiscordGuildEntry(guilds, params.groupSpace);
|
|
85
|
+
const channelEntries = guildEntry?.channels;
|
|
86
|
+
const channelEntry =
|
|
87
|
+
channelEntries && Object.keys(channelEntries).length > 0
|
|
88
|
+
? resolveDiscordChannelEntry(channelEntries, params)
|
|
89
|
+
: undefined;
|
|
90
|
+
return { guildEntry, channelEntry };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function resolveDiscordGroupRequireMention(params: ChannelGroupContext): boolean {
|
|
94
|
+
const context = resolveDiscordPolicyContext(params);
|
|
95
|
+
if (typeof context.channelEntry?.requireMention === "boolean") {
|
|
96
|
+
return context.channelEntry.requireMention;
|
|
97
|
+
}
|
|
98
|
+
if (typeof context.guildEntry?.requireMention === "boolean") {
|
|
99
|
+
return context.guildEntry.requireMention;
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function resolveDiscordGroupToolPolicy(
|
|
105
|
+
params: ChannelGroupContext,
|
|
106
|
+
): GroupToolPolicyConfig | undefined {
|
|
107
|
+
const context = resolveDiscordPolicyContext(params);
|
|
108
|
+
const channelPolicy = resolveSenderToolsEntry(context.channelEntry, params);
|
|
109
|
+
if (channelPolicy) {
|
|
110
|
+
return channelPolicy;
|
|
111
|
+
}
|
|
112
|
+
return resolveSenderToolsEntry(context.guildEntry, params);
|
|
113
|
+
}
|
package/src/guilds.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { fetchDiscord } from "./api.js";
|
|
2
|
+
import { normalizeDiscordSlug } from "./monitor/allow-list.js";
|
|
3
|
+
|
|
4
|
+
export type DiscordGuildSummary = {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
slug: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export async function listGuilds(
|
|
11
|
+
token: string,
|
|
12
|
+
fetcher: typeof fetch,
|
|
13
|
+
): Promise<DiscordGuildSummary[]> {
|
|
14
|
+
const raw = await fetchDiscord<Array<{ id?: string; name?: string }>>(
|
|
15
|
+
"/users/@me/guilds",
|
|
16
|
+
token,
|
|
17
|
+
fetcher,
|
|
18
|
+
);
|
|
19
|
+
return raw
|
|
20
|
+
.filter(
|
|
21
|
+
(guild): guild is { id: string; name: string } =>
|
|
22
|
+
typeof guild.id === "string" && typeof guild.name === "string",
|
|
23
|
+
)
|
|
24
|
+
.map((guild) => ({
|
|
25
|
+
id: guild.id,
|
|
26
|
+
name: guild.name,
|
|
27
|
+
slug: normalizeDiscordSlug(guild.name),
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { ReplyPayload } from "autobot/plugin-sdk/reply-payload";
|
|
2
|
+
|
|
3
|
+
export type DiscordInboundEventDeliveryEnd = () => void;
|
|
4
|
+
|
|
5
|
+
type ActiveEvent = {
|
|
6
|
+
outboundTo: string;
|
|
7
|
+
outboundAccountId?: string;
|
|
8
|
+
markInboundEventDelivered: () => void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const DISCORD_INBOUND_EVENT_DELIVERY_KEY = "__autobotInboundEventDelivery";
|
|
12
|
+
const registry = new Map<string, ActiveEvent>();
|
|
13
|
+
|
|
14
|
+
function normalizeDiscordDeliveryTarget(value: string): string {
|
|
15
|
+
return value
|
|
16
|
+
.trim()
|
|
17
|
+
.replace(/^discord:/iu, "")
|
|
18
|
+
.replace(/^channel:/iu, "")
|
|
19
|
+
.toLowerCase();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function resolveDiscordInboundEventDeliveryCorrelationKey(
|
|
23
|
+
sessionKey: string | undefined,
|
|
24
|
+
inboundEventKind?: string,
|
|
25
|
+
): string | undefined {
|
|
26
|
+
const key = sessionKey?.trim();
|
|
27
|
+
if (!key) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
return inboundEventKind === "room_event" ? `${key}:room_event` : key;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function beginDiscordInboundEventDeliveryCorrelation(
|
|
34
|
+
sessionKey: string | undefined,
|
|
35
|
+
event: ActiveEvent,
|
|
36
|
+
options?: { inboundEventKind?: string },
|
|
37
|
+
): DiscordInboundEventDeliveryEnd {
|
|
38
|
+
const key = resolveDiscordInboundEventDeliveryCorrelationKey(
|
|
39
|
+
sessionKey,
|
|
40
|
+
options?.inboundEventKind,
|
|
41
|
+
);
|
|
42
|
+
if (!key) {
|
|
43
|
+
return () => {};
|
|
44
|
+
}
|
|
45
|
+
registry.set(key, event);
|
|
46
|
+
return () => {
|
|
47
|
+
if (registry.get(key) === event) {
|
|
48
|
+
registry.delete(key);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function notifyDiscordInboundEventOutboundSuccess(params: {
|
|
54
|
+
sessionKey: string | undefined;
|
|
55
|
+
to: string;
|
|
56
|
+
accountId?: string | null;
|
|
57
|
+
inboundEventKind?: string;
|
|
58
|
+
}): void {
|
|
59
|
+
const key = resolveDiscordInboundEventDeliveryCorrelationKey(
|
|
60
|
+
params.sessionKey,
|
|
61
|
+
params.inboundEventKind,
|
|
62
|
+
);
|
|
63
|
+
if (!key) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const event = registry.get(key);
|
|
67
|
+
if (
|
|
68
|
+
!event ||
|
|
69
|
+
normalizeDiscordDeliveryTarget(event.outboundTo) !== normalizeDiscordDeliveryTarget(params.to)
|
|
70
|
+
) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (event.outboundAccountId && params.accountId && params.accountId !== event.outboundAccountId) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
registry.delete(key);
|
|
77
|
+
event.markInboundEventDelivered();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function readRecord(value: unknown): Record<string, unknown> | undefined {
|
|
81
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
82
|
+
? (value as Record<string, unknown>)
|
|
83
|
+
: undefined;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function readString(value: unknown): string | undefined {
|
|
87
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function withDiscordInboundEventDeliveryMetadata(
|
|
91
|
+
payload: ReplyPayload,
|
|
92
|
+
params: {
|
|
93
|
+
sessionKey?: string | null;
|
|
94
|
+
inboundEventKind?: string;
|
|
95
|
+
},
|
|
96
|
+
): ReplyPayload {
|
|
97
|
+
const sessionKey = params.sessionKey?.trim();
|
|
98
|
+
if (!sessionKey || params.inboundEventKind !== "room_event") {
|
|
99
|
+
return payload;
|
|
100
|
+
}
|
|
101
|
+
const channelData = readRecord(payload.channelData) ?? {};
|
|
102
|
+
const discordData = readRecord(channelData.discord) ?? {};
|
|
103
|
+
return {
|
|
104
|
+
...payload,
|
|
105
|
+
channelData: {
|
|
106
|
+
...channelData,
|
|
107
|
+
discord: {
|
|
108
|
+
...discordData,
|
|
109
|
+
[DISCORD_INBOUND_EVENT_DELIVERY_KEY]: {
|
|
110
|
+
sessionKey,
|
|
111
|
+
inboundEventKind: params.inboundEventKind,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function notifyDiscordInboundEventOutboundPayloadSuccess(params: {
|
|
119
|
+
payload: ReplyPayload;
|
|
120
|
+
to: string;
|
|
121
|
+
accountId?: string | null;
|
|
122
|
+
}): void {
|
|
123
|
+
const channelData = readRecord(params.payload.channelData);
|
|
124
|
+
const discordData = readRecord(channelData?.discord);
|
|
125
|
+
const metadata = readRecord(discordData?.[DISCORD_INBOUND_EVENT_DELIVERY_KEY]);
|
|
126
|
+
if (!metadata) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
notifyDiscordInboundEventOutboundSuccess({
|
|
130
|
+
sessionKey: readString(metadata.sessionKey),
|
|
131
|
+
inboundEventKind: readString(metadata.inboundEventKind),
|
|
132
|
+
to: params.to,
|
|
133
|
+
accountId: params.accountId,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { ChannelStructuredComponents } from "autobot/plugin-sdk/channel-contract";
|
|
2
|
+
import {
|
|
3
|
+
createInteractiveConversationBindingHelpers,
|
|
4
|
+
dispatchPluginInteractiveHandler,
|
|
5
|
+
type PluginConversationBinding,
|
|
6
|
+
type PluginConversationBindingRequestParams,
|
|
7
|
+
type PluginConversationBindingRequestResult,
|
|
8
|
+
type PluginInteractiveRegistration,
|
|
9
|
+
} from "autobot/plugin-sdk/plugin-runtime";
|
|
10
|
+
|
|
11
|
+
export type DiscordInteractiveHandlerContext = {
|
|
12
|
+
channel: "discord";
|
|
13
|
+
accountId: string;
|
|
14
|
+
interactionId: string;
|
|
15
|
+
conversationId: string;
|
|
16
|
+
parentConversationId?: string;
|
|
17
|
+
guildId?: string;
|
|
18
|
+
senderId?: string;
|
|
19
|
+
senderUsername?: string;
|
|
20
|
+
auth: {
|
|
21
|
+
isAuthorizedSender: boolean;
|
|
22
|
+
};
|
|
23
|
+
interaction: {
|
|
24
|
+
kind: "button" | "select" | "modal";
|
|
25
|
+
data: string;
|
|
26
|
+
namespace: string;
|
|
27
|
+
payload: string;
|
|
28
|
+
messageId?: string;
|
|
29
|
+
values?: string[];
|
|
30
|
+
fields?: Array<{ id: string; name: string; values: string[] }>;
|
|
31
|
+
};
|
|
32
|
+
respond: {
|
|
33
|
+
acknowledge: () => Promise<void>;
|
|
34
|
+
reply: (params: { text: string; ephemeral?: boolean }) => Promise<void>;
|
|
35
|
+
followUp: (params: { text: string; ephemeral?: boolean }) => Promise<void>;
|
|
36
|
+
editMessage: (params: {
|
|
37
|
+
text?: string;
|
|
38
|
+
components?: ChannelStructuredComponents;
|
|
39
|
+
}) => Promise<void>;
|
|
40
|
+
clearComponents: (params?: { text?: string }) => Promise<void>;
|
|
41
|
+
};
|
|
42
|
+
requestConversationBinding: (
|
|
43
|
+
params?: PluginConversationBindingRequestParams,
|
|
44
|
+
) => Promise<PluginConversationBindingRequestResult>;
|
|
45
|
+
detachConversationBinding: () => Promise<{ removed: boolean }>;
|
|
46
|
+
getCurrentConversationBinding: () => Promise<PluginConversationBinding | null>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type DiscordInteractiveHandlerRegistration = PluginInteractiveRegistration<
|
|
50
|
+
DiscordInteractiveHandlerContext,
|
|
51
|
+
"discord"
|
|
52
|
+
>;
|
|
53
|
+
|
|
54
|
+
type DiscordInteractiveDispatchContext = Omit<
|
|
55
|
+
DiscordInteractiveHandlerContext,
|
|
56
|
+
| "interaction"
|
|
57
|
+
| "respond"
|
|
58
|
+
| "channel"
|
|
59
|
+
| "requestConversationBinding"
|
|
60
|
+
| "detachConversationBinding"
|
|
61
|
+
| "getCurrentConversationBinding"
|
|
62
|
+
> & {
|
|
63
|
+
interaction: Omit<
|
|
64
|
+
DiscordInteractiveHandlerContext["interaction"],
|
|
65
|
+
"data" | "namespace" | "payload"
|
|
66
|
+
>;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export async function dispatchDiscordPluginInteractiveHandler(params: {
|
|
70
|
+
data: string;
|
|
71
|
+
interactionId: string;
|
|
72
|
+
ctx: DiscordInteractiveDispatchContext;
|
|
73
|
+
respond: DiscordInteractiveHandlerContext["respond"];
|
|
74
|
+
onMatched?: () => Promise<void> | void;
|
|
75
|
+
}) {
|
|
76
|
+
return await dispatchPluginInteractiveHandler<DiscordInteractiveHandlerRegistration>({
|
|
77
|
+
channel: "discord",
|
|
78
|
+
data: params.data,
|
|
79
|
+
dedupeId: params.interactionId,
|
|
80
|
+
onMatched: params.onMatched,
|
|
81
|
+
invoke: ({ registration, namespace, payload }) =>
|
|
82
|
+
registration.handler({
|
|
83
|
+
...params.ctx,
|
|
84
|
+
channel: "discord",
|
|
85
|
+
interaction: {
|
|
86
|
+
...params.ctx.interaction,
|
|
87
|
+
data: params.data,
|
|
88
|
+
namespace,
|
|
89
|
+
payload,
|
|
90
|
+
},
|
|
91
|
+
respond: params.respond,
|
|
92
|
+
...createInteractiveConversationBindingHelpers({
|
|
93
|
+
registration,
|
|
94
|
+
senderId: params.ctx.senderId,
|
|
95
|
+
conversation: {
|
|
96
|
+
channel: "discord",
|
|
97
|
+
accountId: params.ctx.accountId,
|
|
98
|
+
conversationId: params.ctx.conversationId,
|
|
99
|
+
parentConversationId: params.ctx.parentConversationId,
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
}),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Routes, type APIApplicationCommand } from "discord-api-types/v10";
|
|
2
|
+
import type { RequestClient } from "./rest.js";
|
|
3
|
+
|
|
4
|
+
export async function listApplicationCommands(
|
|
5
|
+
rest: RequestClient,
|
|
6
|
+
clientId: string,
|
|
7
|
+
): Promise<APIApplicationCommand[]> {
|
|
8
|
+
return (await rest.get(Routes.applicationCommands(clientId))) as APIApplicationCommand[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function createApplicationCommand(
|
|
12
|
+
rest: RequestClient,
|
|
13
|
+
clientId: string,
|
|
14
|
+
body: unknown,
|
|
15
|
+
): Promise<unknown> {
|
|
16
|
+
return await rest.post(Routes.applicationCommands(clientId), { body });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function editApplicationCommand(
|
|
20
|
+
rest: RequestClient,
|
|
21
|
+
clientId: string,
|
|
22
|
+
commandId: string,
|
|
23
|
+
body: unknown,
|
|
24
|
+
): Promise<unknown> {
|
|
25
|
+
return await rest.patch(Routes.applicationCommand(clientId, commandId), { body });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function deleteApplicationCommand(
|
|
29
|
+
rest: RequestClient,
|
|
30
|
+
clientId: string,
|
|
31
|
+
commandId: string,
|
|
32
|
+
): Promise<void> {
|
|
33
|
+
await rest.delete(Routes.applicationCommand(clientId, commandId));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function overwriteApplicationCommands(
|
|
37
|
+
rest: RequestClient,
|
|
38
|
+
clientId: string,
|
|
39
|
+
body: unknown,
|
|
40
|
+
): Promise<void> {
|
|
41
|
+
await rest.put(Routes.applicationCommands(clientId), { body });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function overwriteGuildApplicationCommands(
|
|
45
|
+
rest: RequestClient,
|
|
46
|
+
clientId: string,
|
|
47
|
+
guildId: string,
|
|
48
|
+
body: unknown,
|
|
49
|
+
): Promise<void> {
|
|
50
|
+
await rest.put(Routes.applicationGuildCommands(clientId, guildId), { body });
|
|
51
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Routes,
|
|
3
|
+
type APIChannel,
|
|
4
|
+
type APIGuild,
|
|
5
|
+
type APIGuildMember,
|
|
6
|
+
type APIGuildScheduledEvent,
|
|
7
|
+
type APIRole,
|
|
8
|
+
type APIVoiceState,
|
|
9
|
+
type RESTPostAPIGuildScheduledEventJSONBody,
|
|
10
|
+
} from "discord-api-types/v10";
|
|
11
|
+
import type { RequestClient, RequestData } from "./rest.js";
|
|
12
|
+
|
|
13
|
+
export async function getGuild(rest: RequestClient, guildId: string): Promise<APIGuild> {
|
|
14
|
+
return (await rest.get(Routes.guild(guildId))) as APIGuild;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function createGuildChannel(
|
|
18
|
+
rest: RequestClient,
|
|
19
|
+
guildId: string,
|
|
20
|
+
data: RequestData,
|
|
21
|
+
): Promise<APIChannel> {
|
|
22
|
+
return (await rest.post(Routes.guildChannels(guildId), data)) as APIChannel;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function moveGuildChannels(
|
|
26
|
+
rest: RequestClient,
|
|
27
|
+
guildId: string,
|
|
28
|
+
data: RequestData,
|
|
29
|
+
): Promise<void> {
|
|
30
|
+
await rest.patch(Routes.guildChannels(guildId), data);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function getGuildMember(
|
|
34
|
+
rest: RequestClient,
|
|
35
|
+
guildId: string,
|
|
36
|
+
userId: string,
|
|
37
|
+
): Promise<APIGuildMember> {
|
|
38
|
+
return (await rest.get(Routes.guildMember(guildId, userId))) as APIGuildMember;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function listGuildRoles(rest: RequestClient, guildId: string): Promise<APIRole[]> {
|
|
42
|
+
return (await rest.get(Routes.guildRoles(guildId))) as APIRole[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function listGuildChannels(
|
|
46
|
+
rest: RequestClient,
|
|
47
|
+
guildId: string,
|
|
48
|
+
): Promise<APIChannel[]> {
|
|
49
|
+
return (await rest.get(Routes.guildChannels(guildId))) as APIChannel[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function putChannelPermission(
|
|
53
|
+
rest: RequestClient,
|
|
54
|
+
channelId: string,
|
|
55
|
+
targetId: string,
|
|
56
|
+
data: RequestData,
|
|
57
|
+
): Promise<void> {
|
|
58
|
+
await rest.put(Routes.channelPermission(channelId, targetId), data);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function deleteChannelPermission(
|
|
62
|
+
rest: RequestClient,
|
|
63
|
+
channelId: string,
|
|
64
|
+
targetId: string,
|
|
65
|
+
): Promise<void> {
|
|
66
|
+
await rest.delete(Routes.channelPermission(channelId, targetId));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function listGuildActiveThreads(
|
|
70
|
+
rest: RequestClient,
|
|
71
|
+
guildId: string,
|
|
72
|
+
): Promise<unknown> {
|
|
73
|
+
return await rest.get(Routes.guildActiveThreads(guildId));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function getGuildVoiceState(
|
|
77
|
+
rest: RequestClient,
|
|
78
|
+
guildId: string,
|
|
79
|
+
userId: string,
|
|
80
|
+
): Promise<APIVoiceState> {
|
|
81
|
+
return (await rest.get(Routes.guildVoiceState(guildId, userId))) as APIVoiceState;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function listGuildScheduledEvents(
|
|
85
|
+
rest: RequestClient,
|
|
86
|
+
guildId: string,
|
|
87
|
+
): Promise<APIGuildScheduledEvent[]> {
|
|
88
|
+
return (await rest.get(Routes.guildScheduledEvents(guildId))) as APIGuildScheduledEvent[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function createGuildScheduledEvent(
|
|
92
|
+
rest: RequestClient,
|
|
93
|
+
guildId: string,
|
|
94
|
+
body: RESTPostAPIGuildScheduledEventJSONBody,
|
|
95
|
+
): Promise<APIGuildScheduledEvent> {
|
|
96
|
+
return (await rest.post(Routes.guildScheduledEvents(guildId), {
|
|
97
|
+
body,
|
|
98
|
+
})) as APIGuildScheduledEvent;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export async function timeoutGuildMember(
|
|
102
|
+
rest: RequestClient,
|
|
103
|
+
guildId: string,
|
|
104
|
+
userId: string,
|
|
105
|
+
data: RequestData,
|
|
106
|
+
): Promise<APIGuildMember> {
|
|
107
|
+
return (await rest.patch(Routes.guildMember(guildId, userId), data)) as APIGuildMember;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export async function addGuildMemberRole(
|
|
111
|
+
rest: RequestClient,
|
|
112
|
+
guildId: string,
|
|
113
|
+
userId: string,
|
|
114
|
+
roleId: string,
|
|
115
|
+
): Promise<void> {
|
|
116
|
+
await rest.put(Routes.guildMemberRole(guildId, userId, roleId));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export async function removeGuildMemberRole(
|
|
120
|
+
rest: RequestClient,
|
|
121
|
+
guildId: string,
|
|
122
|
+
userId: string,
|
|
123
|
+
roleId: string,
|
|
124
|
+
): Promise<void> {
|
|
125
|
+
await rest.delete(Routes.guildMemberRole(guildId, userId, roleId));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export async function removeGuildMember(
|
|
129
|
+
rest: RequestClient,
|
|
130
|
+
guildId: string,
|
|
131
|
+
userId: string,
|
|
132
|
+
data?: RequestData,
|
|
133
|
+
): Promise<void> {
|
|
134
|
+
await rest.delete(Routes.guildMember(guildId, userId), data);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export async function createGuildBan(
|
|
138
|
+
rest: RequestClient,
|
|
139
|
+
guildId: string,
|
|
140
|
+
userId: string,
|
|
141
|
+
data?: RequestData,
|
|
142
|
+
): Promise<void> {
|
|
143
|
+
await rest.put(Routes.guildBan(guildId, userId), data);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export async function listGuildEmojis(rest: RequestClient, guildId: string): Promise<unknown> {
|
|
147
|
+
return await rest.get(Routes.guildEmojis(guildId));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function createGuildEmoji(
|
|
151
|
+
rest: RequestClient,
|
|
152
|
+
guildId: string,
|
|
153
|
+
data: RequestData,
|
|
154
|
+
): Promise<unknown> {
|
|
155
|
+
return await rest.post(Routes.guildEmojis(guildId), data);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export async function createGuildSticker(
|
|
159
|
+
rest: RequestClient,
|
|
160
|
+
guildId: string,
|
|
161
|
+
data: RequestData,
|
|
162
|
+
): Promise<unknown> {
|
|
163
|
+
return await rest.post(Routes.guildStickers(guildId), data);
|
|
164
|
+
}
|