mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2024-11-14 03:50:18 +00:00
42 lines
1.7 KiB
JavaScript
42 lines
1.7 KiB
JavaScript
module.exports = {
|
|
name: 'voiceStateUpdate',
|
|
async execute(client, oldState, newState) {
|
|
if (oldState.channel === null) return;
|
|
let change = false;
|
|
const radio = client.radio.get(newState.guild.id);
|
|
if (!radio) return;
|
|
if (newState.member.id === client.user.id && oldState.member.id === client.user.id) {
|
|
if (newState.channel === null) {
|
|
return client.radio.delete(newState.guild.id);
|
|
}
|
|
|
|
const newPermissions = newState.channel.permissionsFor(newState.client.user);
|
|
if (!newPermissions.has('CONNECT') || !newPermissions.has('SPEAK') || !newPermissions.has('VIEW_CHANNEL')) {
|
|
try {
|
|
const connection = await oldState.channel.join();
|
|
return radio.connection = connection;
|
|
} catch (error) {
|
|
radio.connection.dispatcher.destroy();
|
|
radio.voiceChannel.leave();
|
|
client.radio.delete(msg.guild.id);
|
|
return;
|
|
}
|
|
}
|
|
if (newState.channel !== radio.voiceChannel) {
|
|
change = true;
|
|
radio.voiceChannel = newState.channel;
|
|
radio.connection = newState.connection;
|
|
}
|
|
}
|
|
if (oldState.channel.members.size === 1 && oldState.channel === radio.voiceChannel || change) {
|
|
setTimeout(() => {
|
|
if (!radio) return;
|
|
if (radio.voiceChannel.members.size === 1) {
|
|
radio.connection.dispatcher.destroy();
|
|
radio.voiceChannel.leave();
|
|
client.radio.delete(newState.guild.id);
|
|
}
|
|
}, 120000);
|
|
}
|
|
}
|
|
} |