mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 07:17:26 +00:00
Discord: fix voice command typing
This commit is contained in:
@@ -2,8 +2,10 @@ import { inspect } from "node:util";
|
|||||||
import {
|
import {
|
||||||
Client,
|
Client,
|
||||||
ReadyListener,
|
ReadyListener,
|
||||||
|
type BaseCommand,
|
||||||
type BaseMessageInteractiveComponent,
|
type BaseMessageInteractiveComponent,
|
||||||
type Modal,
|
type Modal,
|
||||||
|
type Plugin,
|
||||||
} from "@buape/carbon";
|
} from "@buape/carbon";
|
||||||
import { GatewayCloseCodes, type GatewayPlugin } from "@buape/carbon/gateway";
|
import { GatewayCloseCodes, type GatewayPlugin } from "@buape/carbon/gateway";
|
||||||
import { VoicePlugin } from "@buape/carbon/voice";
|
import { VoicePlugin } from "@buape/carbon/voice";
|
||||||
@@ -433,7 +435,7 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
const voiceManagerRef: { current: DiscordVoiceManager | null } = { current: null };
|
const voiceManagerRef: { current: DiscordVoiceManager | null } = { current: null };
|
||||||
const commands = commandSpecs.map((spec) =>
|
const commands: BaseCommand[] = commandSpecs.map((spec) =>
|
||||||
createDiscordNativeCommand({
|
createDiscordNativeCommand({
|
||||||
command: spec,
|
command: spec,
|
||||||
cfg,
|
cfg,
|
||||||
@@ -524,7 +526,9 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const clientPlugins = [createDiscordGatewayPlugin({ discordConfig: discordCfg, runtime })];
|
const clientPlugins: Plugin[] = [
|
||||||
|
createDiscordGatewayPlugin({ discordConfig: discordCfg, runtime }),
|
||||||
|
];
|
||||||
if (voiceEnabled) {
|
if (voiceEnabled) {
|
||||||
clientPlugins.push(new VoicePlugin());
|
clientPlugins.push(new VoicePlugin());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ import {
|
|||||||
Command,
|
Command,
|
||||||
CommandWithSubcommands,
|
CommandWithSubcommands,
|
||||||
type CommandInteraction,
|
type CommandInteraction,
|
||||||
|
type CommandOptions,
|
||||||
} from "@buape/carbon";
|
} from "@buape/carbon";
|
||||||
import {
|
import {
|
||||||
ApplicationCommandOptionType,
|
ApplicationCommandOptionType,
|
||||||
ChannelType as DiscordChannelType,
|
ChannelType as DiscordChannelType,
|
||||||
|
type APIApplicationCommandChannelOption,
|
||||||
} from "discord-api-types/v10";
|
} from "discord-api-types/v10";
|
||||||
import { resolveCommandAuthorizedFromAuthorizers } from "../../channels/command-gating.js";
|
import { resolveCommandAuthorizedFromAuthorizers } from "../../channels/command-gating.js";
|
||||||
import type { OpenClawConfig } from "../../config/config.js";
|
import type { OpenClawConfig } from "../../config/config.js";
|
||||||
@@ -25,7 +27,7 @@ import { resolveDiscordSenderIdentity } from "../monitor/sender-identity.js";
|
|||||||
import { resolveDiscordThreadParentInfo } from "../monitor/threading.js";
|
import { resolveDiscordThreadParentInfo } from "../monitor/threading.js";
|
||||||
import type { DiscordVoiceManager } from "./manager.js";
|
import type { DiscordVoiceManager } from "./manager.js";
|
||||||
|
|
||||||
const VOICE_CHANNEL_TYPES: DiscordChannelType[] = [
|
const VOICE_CHANNEL_TYPES: NonNullable<APIApplicationCommandChannelOption["channel_types"]> = [
|
||||||
DiscordChannelType.GuildVoice,
|
DiscordChannelType.GuildVoice,
|
||||||
DiscordChannelType.GuildStageVoice,
|
DiscordChannelType.GuildStageVoice,
|
||||||
];
|
];
|
||||||
@@ -192,7 +194,7 @@ export function createDiscordVoiceCommand(params: VoiceCommandContext): CommandW
|
|||||||
description = "Join a voice channel";
|
description = "Join a voice channel";
|
||||||
defer = true;
|
defer = true;
|
||||||
ephemeral = params.ephemeralDefault;
|
ephemeral = params.ephemeralDefault;
|
||||||
options = [
|
options: CommandOptions = [
|
||||||
{
|
{
|
||||||
name: "channel",
|
name: "channel",
|
||||||
description: "Voice channel to join",
|
description: "Voice channel to join",
|
||||||
|
|||||||
@@ -620,15 +620,16 @@ export class DiscordVoiceManager {
|
|||||||
logger.warn(`discord voice: TTS failed: ${ttsResult.error ?? "unknown error"}`);
|
logger.warn(`discord voice: TTS failed: ${ttsResult.error ?? "unknown error"}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const audioPath = ttsResult.audioPath;
|
||||||
logVoiceVerbose(
|
logVoiceVerbose(
|
||||||
`tts ok (${speakText.length} chars): guild ${entry.guildId} channel ${entry.channelId}`,
|
`tts ok (${speakText.length} chars): guild ${entry.guildId} channel ${entry.channelId}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.enqueuePlayback(entry, async () => {
|
this.enqueuePlayback(entry, async () => {
|
||||||
logVoiceVerbose(
|
logVoiceVerbose(
|
||||||
`playback start: guild ${entry.guildId} channel ${entry.channelId} file ${path.basename(ttsResult.audioPath)}`,
|
`playback start: guild ${entry.guildId} channel ${entry.channelId} file ${path.basename(audioPath)}`,
|
||||||
);
|
);
|
||||||
const resource = createAudioResource(ttsResult.audioPath);
|
const resource = createAudioResource(audioPath);
|
||||||
entry.player.play(resource);
|
entry.player.play(resource);
|
||||||
await entersState(entry.player, AudioPlayerStatus.Playing, PLAYBACK_READY_TIMEOUT_MS).catch(
|
await entersState(entry.player, AudioPlayerStatus.Playing, PLAYBACK_READY_TIMEOUT_MS).catch(
|
||||||
() => undefined,
|
() => undefined,
|
||||||
|
|||||||
Reference in New Issue
Block a user