music: add --offset=<number> for playlists

This commit is contained in:
Cynthia Foxwell 2022-04-24 12:04:40 -06:00
parent c118a66858
commit 4bcb64d104

View file

@ -50,7 +50,13 @@ async function getSoundcloudClientID() {
return null; return null;
} }
async function processPlaylist(url, type, shuffle = false, limit = -1) { async function processPlaylist(
url,
type,
shuffle = false,
limit = -1,
offset = 0
) {
let playlist; let playlist;
if (type === "yt") { if (type === "yt") {
@ -108,6 +114,10 @@ async function processPlaylist(url, type, shuffle = false, limit = -1) {
shuffleArray(playlist); shuffleArray(playlist);
} }
if (offset > 0) {
playlist = playlist.slice(offset);
}
if (limit > 0) { if (limit > 0) {
playlist = playlist.slice(0, limit); playlist = playlist.slice(0, limit);
} }
@ -395,6 +405,12 @@ command.callback = async function (msg, line) {
argStr = argStr.replace(/--limit=(\d+)/, "").trim(); argStr = argStr.replace(/--limit=(\d+)/, "").trim();
} }
let offset = 0;
if (argStr.match(/--offset=(\d+)/)) {
offset = argStr.match(/--offset=(\d+)/)[1];
argStr = argStr.replace(/--offset=(\d+)/, "").trim();
}
let type; let type;
let playlist = false; let playlist = false;
@ -439,7 +455,8 @@ command.callback = async function (msg, line) {
argStr, argStr,
type, type,
shuffle, shuffle,
limit limit,
offset
); );
await statusMessage.edit({ await statusMessage.edit({
embeds: [ embeds: [