diff --git a/src/modules/announcer.ts b/src/modules/announcer.ts index b20b8c4..86cbf21 100644 --- a/src/modules/announcer.ts +++ b/src/modules/announcer.ts @@ -1,26 +1,25 @@ -import { join } from "node:path"; import type { Module } from "./types.js"; -export const announcer: Module = ({ client, audio, tts, t, rootDir }) => { - const sysmsg = join(rootDir, "sysmsg.wav"); - +export const announcer: Module = ({ client, audio, tts, t }) => { client.on("voiceStateUpdate", async (oldState, newState) => { if (newState.member?.user.bot) return; if (oldState.channel && newState.channel) return; const channel = oldState.channel ?? newState.channel; if (!channel) return; - if (channel.members.size < 2) { + const joined = !oldState.channel; + + if (!joined && channel.members.size < 2) { audio.queue.flush(); await audio.leaveChannel(channel); + return; } + await audio.joinChannel(channel); - const joined = !oldState.channel; const username = newState.member?.displayName ?? oldState.member?.displayName ?? "someone"; const str = joined ? t("USER_JOINED", username) : t("USER_LEFT", username); const filepath = await audio.generateVoice(str, tts.announcement, tts.announcementVoice); - audio.queue.add(sysmsg); audio.queue.add(filepath); }); };