From 5becd0e301c921a448a376d6576fe285b3e1752b Mon Sep 17 00:00:00 2001 From: Erit Islami Date: Tue, 21 Sep 2021 16:57:45 +0200 Subject: [PATCH] fix(clip): support .mp3 suffix, return error if file doesn't exist --- .gitignore | 2 ++ commands/clip.js | 10 ++++++++++ commands/nowplaying.js | 2 +- commands/queue.js | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 3771d4b89..e28c4d949 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ /config.json /.idea /.vscode +/sounds/** +!/sounds/putmusichere.mp3 # Logs logs diff --git a/commands/clip.js b/commands/clip.js index 4b511acab..d414b9cdb 100644 --- a/commands/clip.js +++ b/commands/clip.js @@ -1,4 +1,5 @@ const i18n = require("../util/i18n"); +const fs = require("fs"); module.exports = { name: "clip", @@ -11,6 +12,10 @@ module.exports = { if (queue) return message.reply(i18n.__("clip.errorQueue")); if (!channel) return message.reply(i18n.__("clip.errorNotChannel")).catch(console.error); + if (args[0].includes(".mp3")) args[0] = args[0].replace(".mp3", ""); + + if (!fs.existsSync(`./sounds/${args[0]}.mp3`)) return message.reply(i18n.__("common.errorCommand")).catch(console.error); + const queueConstruct = { textChannel: message.channel, channel, @@ -37,6 +42,11 @@ module.exports = { channel.leave(); console.error(err); }); + dispatcher.setVolumeLogarithmic(queueConstruct.volume / 100); + + await queueConstruct.textChannel.send( + i18n.__mf("play.startedPlaying", { title: `${args[0]}.mp3`, url: "" }) + ); } catch (error) { console.error(error); } diff --git a/commands/nowplaying.js b/commands/nowplaying.js index 5b449b3ed..d773b2e8a 100644 --- a/commands/nowplaying.js +++ b/commands/nowplaying.js @@ -7,7 +7,7 @@ module.exports = { description: i18n.__("nowplaying.description"), execute(message) { const queue = message.client.queue.get(message.guild.id); - if (!queue) return message.reply(i18n.__("nowplaying.errorNotQueue")).catch(console.error); + if (!queue || !queue.songs.length) return message.reply(i18n.__("nowplaying.errorNotQueue")).catch(console.error); const song = queue.songs[0]; const seek = (queue.connection.dispatcher.streamTime - queue.connection.dispatcher.pausedTime) / 1000; diff --git a/commands/queue.js b/commands/queue.js index f94cdf017..400902d4c 100644 --- a/commands/queue.js +++ b/commands/queue.js @@ -12,7 +12,7 @@ module.exports = { return message.reply(i18n.__("queue.missingPermissionMessage")); const queue = message.client.queue.get(message.guild.id); - if (!queue) return message.channel.send(i18n.__("queue.errorNotQueue")); + if (!queue || !queue.songs.length) return message.channel.send(i18n.__("queue.errorNotQueue")); let currentPage = 0; const embeds = generateQueueEmbed(message, queue.songs);