From b18cf6f779ce981fbf6f0b11d92722ae3d4bb27a Mon Sep 17 00:00:00 2001 From: Cynthia Date: Sat, 10 Dec 2022 15:08:58 -0700 Subject: [PATCH] music: more misc fixes --- src/modules/music.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/modules/music.js b/src/modules/music.js index b4c7505..71ced76 100644 --- a/src/modules/music.js +++ b/src/modules/music.js @@ -138,7 +138,10 @@ async function processPlaylist( } async function createVoiceConnection(guild_id, voice_id, text_id) { - const state = {}; + const state = { + voice_id, + text_id, + }; const guild = hf.bot.guilds.get(guild_id); state.connection = hf.bot.joinVoiceChannel({ @@ -148,7 +151,6 @@ async function createVoiceConnection(guild_id, voice_id, text_id) { selfMute: false, voiceAdapterCreator: guild.voiceAdapterCreator, }); - state.text_id = text_id; state.queue = []; state.player = createAudioPlayer(); state.connection.subscribe(state.player); @@ -169,8 +171,8 @@ async function createVoiceConnection(guild_id, voice_id, text_id) { addedBy: next.addedBy, }); } else { - await state.player.stop(); - await state.connection.disconnect(); + state.player.stop(); + state.connection.disconnect(); if (!state.__leave) { await hf.bot.guilds .get(guild_id) @@ -178,6 +180,7 @@ async function createVoiceConnection(guild_id, voice_id, text_id) { .createMessage({ content: ":musical_note: Queue is empty, leaving voice channel.", }); + await hf.bot.leaveVoiceChannel(voice_id); } state.player.off(AudioPlayerStatus.Idle, state.onEnd); voiceStorage.delete(guild_id); @@ -375,7 +378,7 @@ async function enqueue({ ], }); - connection._music_nowplaying = { + connection.nowplaying = { title, addedBy, thumbnail, @@ -435,7 +438,7 @@ command.callback = async function ( if (msg.member?.voiceState?.channelID) { if (voiceStorage.has(msg.guildID)) { const connection = voiceStorage.get(msg.guildID); - if (connection.channelID != msg.member.voiceState.channelID) { + if (connection.voice_id != msg.member.voiceState.channelID) { return "You are in a different voice channel than the bot."; } } @@ -584,7 +587,7 @@ command.callback = async function ( if (msg.member?.voiceState?.channelID) { const connection = voiceStorage.get(msg.guildID); if (voiceStorage.has(msg.guildID)) { - if (connection.channelID != msg.member.voiceState.channelID) { + if (connection.voice_id != msg.member.voiceState.channelID) { return "You are in a different voice channel than the bot."; } } @@ -601,7 +604,7 @@ command.callback = async function ( if (msg.member?.voiceState?.channelID) { const connection = voiceStorage.get(msg.guildID); if (voiceStorage.has(msg.guildID)) { - if (connection.channelID != msg.member.voiceState.channelID) { + if (connection.voice_id != msg.member.voiceState.channelID) { return "You are in a different voice channel than the bot."; } } @@ -609,7 +612,8 @@ command.callback = async function ( // TODO: skip lock checks connection.queue = []; connection.__leave = true; - await connection.stopPlaying(); + connection.player.stop(); + connection.connection.disconnect(); await hf.bot.leaveVoiceChannel(msg.member.voiceState.channelID); return {reaction: "\uD83D\uDC4B"}; } else { @@ -620,7 +624,7 @@ command.callback = async function ( return "The bot is not in a voice channel."; const connection = voiceStorage.get(msg.guildID); - const nowPlaying = connection._music_nowplaying; + const nowPlaying = connection.nowplaying; if (!nowPlaying || !connection.playing) return "Nothing is currently playing."; @@ -671,10 +675,10 @@ command.callback = async function ( return "The bot is not in a voice channel"; const connection = voiceStorage.get(msg.guildID); - const queue = connection._music_queue; + const queue = connection.queue; if (queue.length === 0) return "Nothing else is currently queued"; - const nowPlaying = connection._music_nowplaying; + const nowPlaying = connection.nowplaying; const now = Date.now(); let nextTrack = now + (nowPlaying.length - (now - nowPlaying.start)); @@ -716,12 +720,12 @@ command.callback = async function ( if (msg.member?.voiceState?.channelID) { const connection = voiceStorage.get(msg.guildID); if (voiceStorage.has(msg.guildID)) { - if (connection.channelID != msg.member.voiceState.channelID) { + if (connection.voice_id != msg.member.voiceState.channelID) { return "You are in a different voice channel than the bot."; } } - let queue = connection._music_queue; + let queue = connection.queue; if (queue.length === 0) return "Nothing else is currently queued"; const hasManageMessages = msg.member.permissions.has("manageMessages"); @@ -746,7 +750,7 @@ command.callback = async function ( ); if (Array.isArray(toRemove)) { - connection._music_queue = connection._music_queue.filter( + connection.queue = connection.queue.filter( (item) => !toRemove.includes(item.id) ); return `Removed ${toRemove.length} item(s).`;