mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-14 02:44:53 -05:00
auto-completion for musics inside folders
This commit is contained in:
parent
8332c2c15d
commit
55e11f5809
1 changed files with 22 additions and 6 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue