From a2ebbb5799db4e40de871eea4fab8ec0492b77d0 Mon Sep 17 00:00:00 2001 From: kimpure Date: Mon, 23 Feb 2026 11:31:35 +0000 Subject: [PATCH] Fix manual voice selection bug --- packages/bot/events/readChannel.ts | 6 ++++-- packages/bot/tts.ts | 13 +++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/bot/events/readChannel.ts b/packages/bot/events/readChannel.ts index c8ec943..7aaee89 100644 --- a/packages/bot/events/readChannel.ts +++ b/packages/bot/events/readChannel.ts @@ -2,6 +2,7 @@ import { getOrCreateVoiceConnection } from "../util"; import { getUserProfile, hasGuildReadChannel } from "../db"; import { defineEvent } from "../event"; import { playVoice } from "../tts"; +import { Voice } from "../../db/generated/prisma/enums"; export default defineEvent("messageCreate", async (message) => { if (message.author.bot) @@ -18,7 +19,7 @@ export default defineEvent("messageCreate", async (message) => { const profile = await getUserProfile(message.author.id); let content = message.cleanContent; - let voice: string | null = null + let voice: Voice | null = null if (content.startsWith("$t ")) { voice = "TypeCast" } else if (content.startsWith("$p ")) { @@ -44,6 +45,7 @@ export default defineEvent("messageCreate", async (message) => { return await playVoice( guild, profile, + voice, content = message.attachments.size > 0 ? `${message.attachments.size} 개의 첨부파일` @@ -51,7 +53,7 @@ export default defineEvent("messageCreate", async (message) => { ); } else { for (const text of content.split("\n")) { - await playVoice(guild, profile, text); + await playVoice(guild, profile, voice, text); } } diff --git a/packages/bot/tts.ts b/packages/bot/tts.ts index 6ff71e3..bd31a48 100644 --- a/packages/bot/tts.ts +++ b/packages/bot/tts.ts @@ -67,7 +67,12 @@ class VoiceQueue { } } -export async function playVoice(guild: Guild, profile: DiscordUserProfile, text: string) { +export async function playVoice( + guild: Guild, + profile: DiscordUserProfile, + voice: Voice, + text: string +) { if (profile.nya) text = nyaize(text); @@ -77,14 +82,14 @@ export async function playVoice(guild: Guild, profile: DiscordUserProfile, text: throw new Error("Yaeju is not joined VoiceChat"); let voiceBuffer: Buffer; - if (profile.voice == "TypeCast") { + if (voice == "TypeCast") { if (profile.canTypecast) { - voiceBuffer = await createVoiceBuffer(profile.voice, text); + voiceBuffer = await createVoiceBuffer(voice, text); } else { throw new Error(`the user ${profile.userId} is can't use typecast voice`); } } else { - voiceBuffer = await createVoiceBuffer(profile.voice, text); + voiceBuffer = await createVoiceBuffer(voice, text); } VoiceQueue.fromConnection(connection).enqueue(