Skip to content

Commit

Permalink
fix(clip): support .mp3 suffix, return error if file doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
eritislami committed Sep 21, 2021
1 parent 48e33a4 commit 5becd0e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/config.json
/.idea
/.vscode
/sounds/**
!/sounds/putmusichere.mp3

# Logs
logs
Expand Down
10 changes: 10 additions & 0 deletions commands/clip.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const i18n = require("../util/i18n");
const fs = require("fs");

module.exports = {
name: "clip",
Expand All @@ -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,
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion commands/nowplaying.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion commands/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5becd0e

Please sign in to comment.