Fix manual voice selection bug
This commit is contained in:
parent
ecf1234821
commit
a2ebbb5799
2 changed files with 13 additions and 6 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue