From 4bcb64d10401d8fb559485980182261cbc6132b9 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Sun, 24 Apr 2022 12:04:40 -0600 Subject: [PATCH] music: add --offset= for playlists --- src/modules/music.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/modules/music.js b/src/modules/music.js index f6bc05d..6379b29 100644 --- a/src/modules/music.js +++ b/src/modules/music.js @@ -50,7 +50,13 @@ async function getSoundcloudClientID() { return null; } -async function processPlaylist(url, type, shuffle = false, limit = -1) { +async function processPlaylist( + url, + type, + shuffle = false, + limit = -1, + offset = 0 +) { let playlist; if (type === "yt") { @@ -108,6 +114,10 @@ async function processPlaylist(url, type, shuffle = false, limit = -1) { shuffleArray(playlist); } + if (offset > 0) { + playlist = playlist.slice(offset); + } + if (limit > 0) { playlist = playlist.slice(0, limit); } @@ -395,6 +405,12 @@ command.callback = async function (msg, line) { 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 playlist = false; @@ -439,7 +455,8 @@ command.callback = async function (msg, line) { argStr, type, shuffle, - limit + limit, + offset ); await statusMessage.edit({ embeds: [