woomy/events/voiceStateUpdate.js

41 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-04-22 07:39:46 +00:00
// Copyright 2020 Emily J. / mudkipscience and contributors. Subject to the AGPLv3 license.
2020-04-22 07:58:25 +00:00
const music = require('../utils/music')
2020-04-22 07:39:46 +00:00
module.exports = (client, oldState, newState) => {
2020-04-22 07:58:25 +00:00
if (newState.channelID !== oldState.channelID) {
const guild = music.getGuild(newState.guild.id)
2020-04-22 07:39:46 +00:00
2020-04-22 07:58:25 +00:00
if (guild.playing && guild.voiceChannel.id === oldState.channelID) {
if (guild.voiceChannel.members.size === 1) {
guild.autoDisconnect = true
setTimeout(() => {
if (guild.voiceChannel.members.size === 1 && guild.autoDisconnect) {
setTimeout(() => {
if (guild.voiceChannel.members.size === 1 && guild.autoDisconnect) {
2020-04-22 07:49:45 +00:00
setTimeout(() => {
2020-04-22 07:58:25 +00:00
if (guild.voiceChannel.members.size === 1 && guild.autoDisconnect) {
guild.playing = false
guild.queue = []
2020-04-22 07:53:55 +00:00
2020-04-22 07:58:25 +00:00
// Probably should be async? But no need here I think
guild.dispatcher.end('silent')
guild.message.channel.send('No one is listening to me. Leaving voice chat!')
} else {
guild.autoDisconnect = false
}
}, 30000)
} else {
guild.autoDisconnect = false
}
}, 20000)
} else {
guild.autoDisconnect = false
}
}, 10000)
}
2020-04-22 07:39:46 +00:00
}
2020-04-22 07:58:25 +00:00
}
}