From 9e4d458b0d43ae6eed3968749f09ec4a392c7ede Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Sat, 7 Oct 2023 22:38:14 -0600 Subject: [PATCH] utility.appinfo: fix assets exceeding 1024 chars --- src/modules/utility.js | 59 ++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/src/modules/utility.js b/src/modules/utility.js index 311e13d..39f5be9 100644 --- a/src/modules/utility.js +++ b/src/modules/utility.js @@ -1621,6 +1621,11 @@ appinfo.callback = async function (msg, line) { if (app.privacy_policy_url) { links.push(`[Privacy Policy](${app.privacy_policy_url})`); } + if (assets.length > 0) { + links.push( + `[Assets](https://discord.com/api/v10/oauth2/applications/${app.id}/assets)` + ); + } if (images.length > 0 || links.length > 0) { embed.fields.push({ @@ -1640,28 +1645,48 @@ appinfo.callback = async function (msg, line) { } const mappedAssets = assets.map( - (asset) => `[${asset.name}](${APP_ASSET_BASE}${app.id}/${asset.id}.png)` + (asset) => + `[${ + asset.name.length > 32 + ? asset.name.substring(0, 32) + "\u2026" + : asset.name + }](${APP_ASSET_BASE}${app.id}/${asset.id}.png)` ); - embed.fields.push({ - name: "Assets", - value: - "- " + - mappedAssets - .slice(0, Math.ceil(mappedAssets.length / 2)) - .join("\n- "), - inline: true, - }); - if (mappedAssets.length > 1) + const left = + "- " + + mappedAssets.slice(0, Math.ceil(mappedAssets.length / 2)).join("\n- "); + const right = + "- " + + mappedAssets + .slice(Math.ceil(mappedAssets.length / 2), mappedAssets.length) + .join("\n- "); + + if (left.length < 1024 && right.length < 1024) { embed.fields.push({ - name: "\u200b", - value: - "- " + - mappedAssets - .slice(Math.ceil(mappedAssets.length / 2), mappedAssets.length) - .join("\n- "), + name: "Assets", + value: left, inline: true, }); + if (mappedAssets.length > 1) + embed.fields.push({ + name: "\u200b", + value: right, + inline: true, + }); + } else { + embed.fields.push({ + name: "Assets", + value: assets + .map((asset) => + asset.name.length > 32 + ? asset.name.substring(0, 32) + "\u2026" + : asset.name + ) + .join(", "), + inline: false, + }); + } } return {embed};