tardis-bot/modules/announcer/index.js

35 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2024-04-24 23:08:11 +00:00
const printf = require('printf');
const AudioQueue = require('../../AudioQueue.js')
module.exports = function (bot, api) {
bot.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;
2023-03-21 12:40:22 +00:00
if (channel.members.size < 2) {
2024-04-24 23:08:11 +00:00
api.AudioQueue.flush();
2024-04-24 23:08:18 +00:00
await api.leaveChannel(channel);
}
await api.joinChannel(channel);
let joined = false;
if (!oldState.channel) {
joined = true;
2024-04-24 23:08:11 +00:00
let conn = api.getConnectionForVoiceChannel(channel);
if (!api.queue) api.queue = new AudioQueue(conn, api);
}
let username = newState.member.displayName;
let str = "";
if (!joined) {
str = printf(api.strings.USER_LEFT, username);
} else {
str = printf(api.strings.USER_JOINED, username);
}
const filepath = await api.generateVoice(str, api.announcementEngine, api.announcementVoice);
api.queue.add(__dirname + "/sysmsg.wav");
api.queue.add(filepath);
})
}