From 55e11f5809db0d212ecddc63d924565daf40e569 Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Mon, 13 Mar 2023 14:03:40 +0700 Subject: [PATCH] auto-completion for musics inside folders --- commands/music.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/commands/music.js b/commands/music.js index e4be319..a9c110e 100644 --- a/commands/music.js +++ b/commands/music.js @@ -21,16 +21,31 @@ let song async function play (bot, values, discord, channeldc, selector, config) { try { - const songs = await fileList(SONGS_PATH) const filepath = values.join(' ') - const file = songs.filter((song) => song.toLowerCase().includes(filepath.toLowerCase()))[0] + const seperator = path.sep // for hosting bot on windows let absolutePath - if (!path.isAbsolute(filepath) && - !filepath.includes('/') && // please improve, this is so bad - filepath !== '') absolutePath = await resolve(file) - else absolutePath = await resolve(filepath) + if (filepath.includes(seperator) && filepath !== '') { + const pathSplitted = filepath.split(seperator) + + const songs = await fileList( + path.join( + SONGS_PATH, + pathSplitted[0] + ) + ) + + // this part took a bunch of time to figure out, but still chomens moment!1! + const lowerCaseFile = pathSplitted.pop().toLowerCase() + const file = songs.filter((song) => song.toLowerCase().includes(lowerCaseFile))[0] + + absolutePath = await resolve(path.join(pathSplitted.join(seperator), file)) + } else { + const songs = await fileList(SONGS_PATH) + const file = songs.filter((song) => song.toLowerCase().includes(filepath.toLowerCase()))[0] + absolutePath = await resolve(file) + } song = await bot.music.load(await fs.readFile(absolutePath), path.basename(absolutePath)) @@ -47,6 +62,7 @@ async function play (bot, values, discord, channeldc, selector, config) { bot.music.queue.push(song) bot.music.play(song) } catch (e) { + bot.console.error(e.stack) if (discord) { const Embed = new EmbedBuilder() .setColor(config.discord.embedsColors.error)