music: add playlist limiting via --limit=<number>
This commit is contained in:
parent
8c3187584d
commit
64b34c56d6
1 changed files with 20 additions and 5 deletions
|
@ -50,7 +50,7 @@ async function getSoundcloudClientID() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processPlaylist(url, type, shuffle = false) {
|
async function processPlaylist(url, type, shuffle = false, limit = -1) {
|
||||||
let playlist;
|
let playlist;
|
||||||
|
|
||||||
if (type === "yt") {
|
if (type === "yt") {
|
||||||
|
@ -108,6 +108,10 @@ async function processPlaylist(url, type, shuffle = false) {
|
||||||
shuffleArray(playlist);
|
shuffleArray(playlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (limit > 0) {
|
||||||
|
playlist = playlist.slice(0, limit);
|
||||||
|
}
|
||||||
|
|
||||||
return playlist;
|
return playlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,7 +365,7 @@ const command = new Command("music");
|
||||||
command.addAlias("m");
|
command.addAlias("m");
|
||||||
command.category = "misc";
|
command.category = "misc";
|
||||||
command.helpText = "Music";
|
command.helpText = "Music";
|
||||||
command.usage = "[search term]";
|
command.usage = "help";
|
||||||
command.callback = async function (msg, line) {
|
command.callback = async function (msg, line) {
|
||||||
if (!msg.guildID) return "This command can only be used in guilds.";
|
if (!msg.guildID) return "This command can only be used in guilds.";
|
||||||
|
|
||||||
|
@ -380,9 +384,15 @@ command.callback = async function (msg, line) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let shuffle = false;
|
let shuffle = false;
|
||||||
if (argStr.startsWith("--shuffle ")) {
|
if (argStr.includes("--shuffle")) {
|
||||||
shuffle = true;
|
shuffle = true;
|
||||||
argStr = argStr.replace(/^--shuffle /, "");
|
argStr = argStr.replace("--shuffle", "").trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
let limit = -1;
|
||||||
|
if (argStr.match(/--limit=(\d+)/)) {
|
||||||
|
limit = argStr.match(/--limit=(\d+)/)[1];
|
||||||
|
argStr = argStr.replace(/--limit=(\d+)/, "").trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
let type;
|
let type;
|
||||||
|
@ -425,7 +435,12 @@ command.callback = async function (msg, line) {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
const playlist = await processPlaylist(argStr, type, shuffle);
|
const playlist = await processPlaylist(
|
||||||
|
argStr,
|
||||||
|
type,
|
||||||
|
shuffle,
|
||||||
|
limit
|
||||||
|
);
|
||||||
await statusMessage.edit({
|
await statusMessage.edit({
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue