Fix manual voice selection bug

This commit is contained in:
kimpure 2026-02-23 11:31:35 +00:00
parent ecf1234821
commit a2ebbb5799
2 changed files with 13 additions and 6 deletions

View file

@ -2,6 +2,7 @@ import { getOrCreateVoiceConnection } from "../util";
import { getUserProfile, hasGuildReadChannel } from "../db"; import { getUserProfile, hasGuildReadChannel } from "../db";
import { defineEvent } from "../event"; import { defineEvent } from "../event";
import { playVoice } from "../tts"; import { playVoice } from "../tts";
import { Voice } from "../../db/generated/prisma/enums";
export default defineEvent("messageCreate", async (message) => { export default defineEvent("messageCreate", async (message) => {
if (message.author.bot) if (message.author.bot)
@ -18,7 +19,7 @@ export default defineEvent("messageCreate", async (message) => {
const profile = await getUserProfile(message.author.id); const profile = await getUserProfile(message.author.id);
let content = message.cleanContent; let content = message.cleanContent;
let voice: string | null = null let voice: Voice | null = null
if (content.startsWith("$t ")) { if (content.startsWith("$t ")) {
voice = "TypeCast" voice = "TypeCast"
} else if (content.startsWith("$p ")) { } else if (content.startsWith("$p ")) {
@ -44,6 +45,7 @@ export default defineEvent("messageCreate", async (message) => {
return await playVoice( return await playVoice(
guild, guild,
profile, profile,
voice,
content = content =
message.attachments.size > 0 message.attachments.size > 0
? `${message.attachments.size} 개의 첨부파일` ? `${message.attachments.size} 개의 첨부파일`
@ -51,7 +53,7 @@ export default defineEvent("messageCreate", async (message) => {
); );
} else { } else {
for (const text of content.split("\n")) { for (const text of content.split("\n")) {
await playVoice(guild, profile, text); await playVoice(guild, profile, voice, text);
} }
} }

View file

@ -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) if (profile.nya)
text = nyaize(text); text = nyaize(text);
@ -77,14 +82,14 @@ export async function playVoice(guild: Guild, profile: DiscordUserProfile, text:
throw new Error("Yaeju is not joined VoiceChat"); throw new Error("Yaeju is not joined VoiceChat");
let voiceBuffer: Buffer; let voiceBuffer: Buffer;
if (profile.voice == "TypeCast") { if (voice == "TypeCast") {
if (profile.canTypecast) { if (profile.canTypecast) {
voiceBuffer = await createVoiceBuffer(profile.voice, text); voiceBuffer = await createVoiceBuffer(voice, text);
} else { } else {
throw new Error(`the user ${profile.userId} is can't use typecast voice`); throw new Error(`the user ${profile.userId} is can't use typecast voice`);
} }
} else { } else {
voiceBuffer = await createVoiceBuffer(profile.voice, text); voiceBuffer = await createVoiceBuffer(voice, text);
} }
VoiceQueue.fromConnection(connection).enqueue( VoiceQueue.fromConnection(connection).enqueue(