Fix join and leave and sysmsg.wav

This commit is contained in:
2026-05-14 21:05:04 +02:00
parent afeb05447d
commit c8d4c4c02f

View File

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