From 8958f9b5f51924e72225a4caabbc007f8b63a665 Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Thu, 15 Sep 2022 17:49:15 +0200 Subject: [PATCH] fix single chunk lyrics --- commands/message/search/lyrics.js | 44 ++++++++++++++++++------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/commands/message/search/lyrics.js b/commands/message/search/lyrics.js index b1460b8..6ba605c 100644 --- a/commands/message/search/lyrics.js +++ b/commands/message/search/lyrics.js @@ -35,27 +35,35 @@ module.exports = { search = search.response if(search.body.status == 2) return editOrReply(context, {embeds:[createEmbed("error", context, search.body.message)]}) - // Split lyrics into field-sizes chunks - let chunks = search.body.lyrics.split(/\[(.*?)\]/) // should give us every chunk let fields = []; - let cur = { - inline: false - }; - let i = 0; - let l = 0; - for(const c of chunks){ - if(c.length == 0) continue; - if(i == 0){ - cur.name = `[${c}]` - i += 1 - continue; - } - cur.value = c.substr(0,1024) + `​` - i = 0 - fields.push(cur) - cur = { + if(search.body.lyrics.includes('[')){ + // Split lyrics into field-sizes chunks if multiple verses are present + let chunks = search.body.lyrics.split(/\[(.*?)\]/) + let cur = { inline: false + }; + let i = 0; + let l = 0; + for(const c of chunks){ + if(c.length == 0) continue; + if(i == 0){ + cur.name = `[${c}]` + i += 1 + continue; + } + cur.value = c.substr(0,1024) + `​` + i = 0 + fields.push(cur) + cur = { + inline: false + } } + } else { // If we have no chunking to do, just use the entire thing + fields.push({ + name: "Lyrics", + value: search.body.lyrics.substr(0,900), + inline: false + }); } if(fields.length > 3){