Fix join and leave and sysmsg.wav
This commit is contained in:
@@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user