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";
|
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);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user