From 69815dbdf26e1b6c4e144cd8f5e43469d29c9738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20H?= Date: Wed, 22 Apr 2020 09:39:46 +0200 Subject: [PATCH 1/2] voice chat leave detection --- events/voiceStateUpdate.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 events/voiceStateUpdate.js diff --git a/events/voiceStateUpdate.js b/events/voiceStateUpdate.js new file mode 100644 index 0000000..c8118e0 --- /dev/null +++ b/events/voiceStateUpdate.js @@ -0,0 +1,13 @@ +// Copyright 2020 Emily J. / mudkipscience and contributors. Subject to the AGPLv3 license. + +const music = require('../utils/music'); + +module.exports = (client, oldState, newState) => { + if(newState.channelID != oldState.channelID) { + let guild = music.getGuild(newState.guild.id); + + if(guild.playing && guild.voiceChannel.id == oldState.channelID) { + console.log(newState.id + ' left VC, in which Woomy is playing music'); + }; + } +} \ No newline at end of file From e7ed2881394ff33b481fc210791061588100ade1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20H?= Date: Wed, 22 Apr 2020 09:49:45 +0200 Subject: [PATCH 2/2] Leave if no one is listening --- events/voiceStateUpdate.js | 26 +++++++++++++++++++++++++- utils/music.js | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/events/voiceStateUpdate.js b/events/voiceStateUpdate.js index c8118e0..56d7fdb 100644 --- a/events/voiceStateUpdate.js +++ b/events/voiceStateUpdate.js @@ -7,7 +7,31 @@ module.exports = (client, oldState, newState) => { let guild = music.getGuild(newState.guild.id); if(guild.playing && guild.voiceChannel.id == oldState.channelID) { - console.log(newState.id + ' left VC, in which Woomy is playing music'); + 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) { + setTimeout(() => { + if(guild.voiceChannel.members.size == 1 && guild.autoDisconnect) { + // 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); + }; }; } } \ No newline at end of file diff --git a/utils/music.js b/utils/music.js index d5747d4..bd7e1ea 100644 --- a/utils/music.js +++ b/utils/music.js @@ -66,6 +66,7 @@ exports.getVideoByQuery = async function (client, query) { exports.play = async function (client, message, query, ignoreQueue) { const guild = exports.getGuild(message.guild.id) + guild.message = message; if (!message.member.voice.channel && !guild.voiceChannel) { return message.reply('You have to be connected to a voice channel to use this command!')