auto-completion for musics inside folders

This commit is contained in:
ChomeNS 2023-03-13 14:03:40 +07:00
parent 8332c2c15d
commit 55e11f5809

View file

@ -21,16 +21,31 @@ let song
async function play (bot, values, discord, channeldc, selector, config) { async function play (bot, values, discord, channeldc, selector, config) {
try { try {
const songs = await fileList(SONGS_PATH)
const filepath = values.join(' ') 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 let absolutePath
if (!path.isAbsolute(filepath) && if (filepath.includes(seperator) && filepath !== '') {
!filepath.includes('/') && // please improve, this is so bad const pathSplitted = filepath.split(seperator)
filepath !== '') absolutePath = await resolve(file)
else absolutePath = await resolve(filepath) 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)) 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.queue.push(song)
bot.music.play(song) bot.music.play(song)
} catch (e) { } catch (e) {
bot.console.error(e.stack)
if (discord) { if (discord) {
const Embed = new EmbedBuilder() const Embed = new EmbedBuilder()
.setColor(config.discord.embedsColors.error) .setColor(config.discord.embedsColors.error)