Fixing indentation and removing unnecessary line changes

This commit is contained in:
Christer Warén 2021-01-21 14:14:58 +02:00
parent ff49fbd16c
commit 84a780723e

View File

@ -1,66 +1,48 @@
module.exports = { module.exports = {
name: "voiceStateUpdate", name: "voiceStateUpdate",
async execute(client, oldState, newState) { async execute(client, oldState, newState) {
if (oldState.channel === null) return; if (oldState.channel === null) return;
let change = false; let change = false;
const radio = client.radio.get(newState.guild.id); const radio = client.radio.get(newState.guild.id);
if (!radio) return; if (!radio) return;
if ( if (newState.member.id === client.user.id && oldState.member.id === client.user.id) {
newState.member.id === client.user.id && if (newState.channel === null) {
oldState.member.id === client.user.id client.funcs.statisticsUpdate(client, newState.guild, radio);
) { return client.radio.delete(newState.guild.id);
if (newState.channel === null) { }
client.funcs.statisticsUpdate(client, newState.guild, radio);
return client.radio.delete(newState.guild.id);
}
const newPermissions = newState.channel.permissionsFor( const newPermissions = newState.channel.permissionsFor(newState.client.user);
newState.client.user if (!newPermissions.has("CONNECT") || !newPermissions.has("SPEAK") || !newPermissions.has("VIEW_CHANNEL")) {
); try {
if ( setTimeout(
!newPermissions.has("CONNECT") || async () => (radio.connection = await oldState.channel.join()),
!newPermissions.has("SPEAK") || 1000
!newPermissions.has("VIEW_CHANNEL") );
) { } catch (error) {
try { client.funcs.statisticsUpdate(client, newState.guild, radio);
setTimeout( radio.connection.dispatcher.destroy();
async () => (radio.connection = await oldState.channel.join()), radio.voiceChannel.leave();
1000 client.radio.delete(oldState.guild.id);
); }
} catch (error) { return;
client.funcs.statisticsUpdate(client, newState.guild, radio); }
radio.connection.dispatcher.destroy(); if (newState.channel !== radio.voiceChannel) {
radio.voiceChannel.leave(); change = true;
client.radio.delete(oldState.guild.id); radio.voiceChannel = newState.channel;
radio.connection = await newState.channel.join();
}
} }
return; if ((oldState.channel.members.size === 1 && oldState.channel === radio.voiceChannel) || change) {
} setTimeout(() => {
if (newState.channel !== radio.voiceChannel) { if (!radio || !radio.connection.dispatcher || !radio.connection.dispatcher === null) return;
change = true; if (radio.voiceChannel.members.size === 1) {
radio.voiceChannel = newState.channel; client.funcs.statisticsUpdate(client, newState.guild, radio);
radio.connection = await newState.channel.join(); radio.connection.dispatcher.destroy();
} radio.voiceChannel.leave();
} client.radio.delete(newState.guild.id);
if ( }
(oldState.channel.members.size === 1 && }, 120000);
oldState.channel === radio.voiceChannel) ||
change
) {
setTimeout(() => {
if (
!radio ||
!radio.connection.dispatcher ||
!radio.connection.dispatcher === null
)
return;
if (radio.voiceChannel.members.size === 1) {
client.funcs.statisticsUpdate(client, newState.guild, radio);
radio.connection.dispatcher.destroy();
radio.voiceChannel.leave();
client.radio.delete(newState.guild.id);
} }
}, 120000); },
}
},
}; };