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-29 10:59:08 +00:00
|
|
|
// Reset queue, dispatcher, etc if Woomy is forcibly disconnected from the queue
|
2020-04-28 09:35:11 +00:00
|
|
|
if (guild.voiceChannel && !guild.voiceChannel.members.get(client.user.id) && guild.queue.length > 0) {
|
2020-04-22 09:18:14 +00:00
|
|
|
guild.queue = []
|
|
|
|
guild.playing = false
|
|
|
|
guild.paused = false
|
|
|
|
guild.skippers = []
|
|
|
|
}
|
|
|
|
|
|
|
|
// Auto-disconnect feature
|
2020-04-29 10:59:08 +00:00
|
|
|
if (guild.playing && guild.channel && guild.voiceChannel.id === oldState.channelID) {
|
2020-04-22 09:00:57 +00:00
|
|
|
if (guild.voiceChannel.members.filter(member => !member.user.bot).size < 1) {
|
2020-04-22 07:58:25 +00:00
|
|
|
guild.autoDisconnect = true
|
|
|
|
|
2020-04-22 09:00:57 +00:00
|
|
|
guild.message.channel.send(`The music will end in 2 minutes if nobody rejoins **${guild.voiceChannel.name}**`)
|
|
|
|
.then(msg => {
|
|
|
|
msg.delete({ timeout: 120000 })
|
|
|
|
})
|
|
|
|
|
2020-04-22 07:58:25 +00:00
|
|
|
setTimeout(() => {
|
2020-04-22 09:00:57 +00:00
|
|
|
if (guild.dispatcher !== null && guild.voiceChannel.members.filter(member => !member.user.bot).size < 1 && guild.autoDisconnect) {
|
|
|
|
// Probably should be async? But no need here I think
|
|
|
|
guild.dispatcher.end('silent')
|
|
|
|
|
|
|
|
guild.queue = []
|
|
|
|
guild.playing = false
|
|
|
|
guild.paused = false
|
|
|
|
guild.dispatcher = null
|
|
|
|
guild.skippers = []
|
2020-04-22 07:53:55 +00:00
|
|
|
|
2020-04-22 09:00:57 +00:00
|
|
|
guild.message.channel.send('The music has ended because no one was listening to me ;~;')
|
2020-04-22 07:58:25 +00:00
|
|
|
} else {
|
|
|
|
guild.autoDisconnect = false
|
|
|
|
}
|
2020-04-22 09:00:57 +00:00
|
|
|
}, 120000)
|
|
|
|
} else {
|
|
|
|
guild.autoDisconnect = false
|
2020-04-22 07:58:25 +00:00
|
|
|
}
|
2020-04-22 07:39:46 +00:00
|
|
|
}
|
2020-04-22 07:58:25 +00:00
|
|
|
}
|
|
|
|
}
|