tardis-bot/modules/announcer/index.js

33 lines
1.1 KiB
JavaScript
Raw Normal View History

const printf=require('printf');
2021-04-09 11:23:13 +00:00
const AudioQueue=require('../../AudioQueue.js')
2021-04-06 23:36:35 +00:00
module.exports = function (bot, api) {
2021-04-05 14:09:36 +00:00
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;
if (channel.members.array().length < 2) {
return await api.leaveChannel(channel);
}
await api.joinChannel(channel);
let joined = false;
if (!oldState.channel) {
joined = true;
2021-04-09 11:23:13 +00:00
let conn=api.getConnectionForVoiceChannel(channel);
api.queue=new AudioQueue(conn);
2021-04-05 14:09:36 +00:00
}
2021-04-06 23:36:35 +00:00
2021-04-05 14:09:36 +00:00
let username = newState.member.displayName;
let str = "";
if (!joined) {
str = printf(api.strings.USER_LEFT, username);
2021-04-05 14:09:36 +00:00
} else {
str = printf(api.strings.USER_JOINED, username);
2021-04-05 14:09:36 +00:00
}
2021-07-03 20:51:19 +00:00
const filepath = await api.generateVoice(str, api.announcementEngine, api.announcementVoice);
2021-04-09 11:33:14 +00:00
api.queue.add(__dirname + "/sysmsg.wav");
2021-07-03 20:51:19 +00:00
api.queue.add(filepath);
2021-04-05 14:09:36 +00:00
})
}