Skip to content

Commit

Permalink
[Enhancement] playlist command now validates playlist url user inpu…
Browse files Browse the repository at this point in the history
…t. Now a list of all available playlist aliases will be print to the error message if there are any
  • Loading branch information
naseif committed Nov 15, 2021
1 parent fc64be3 commit 6970ea5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 20 additions & 1 deletion commands/Music/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ module.exports = {
});
}

let checkPlaylists = await client.db.all();
const filterPlaylists = checkPlaylists
.filter((playlist) => playlist.ID.startsWith(message.guildId))
.map((playlist) => playlist.ID.slice(playlist.ID.indexOf("_") + 1));

if (!args[0])
return await message.channel.send({
embeds: [
Expand All @@ -48,6 +53,13 @@ module.exports = {
});

if (args[0] === "add" && args[1] && args[2]) {
if (!args[2].startsWith("https"))
return await message.channel.send({
embeds: [
embedMessage("RED", ` ❌ This is not a valid playlist URL!`),
],
});

await client.db.set(`${message.guildId}_${args[1]}`, args[2]);
return await message.channel.send({
embeds: [
Expand All @@ -66,7 +78,14 @@ module.exports = {

if (!customPlaylist)
return await message.channel.send({
embeds: [embedMessage("RED", `❌ | No Playlist found with this name!`)],
embeds: [
embedMessage(
"RED",
`No Playlist found with this name!\n Available Playlists: \`${filterPlaylists.join(
", "
)}\``
),
],
});

if (!message.member.voice.channelId)
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const { Database } = require("quickmongo");
const { connectDatabase } = require("./modules/DatabaseConnection");
const { commandsHelper } = require("./modules/commandsHelper");

if (!token || !mongourl) return logger("Please add your mongourl and bot token to config.json to start the bot!", "error")

const client = new Client({
intents: [
Intents.FLAGS.GUILD_MEMBERS,
Expand Down

0 comments on commit 6970ea5

Please sign in to comment.