utility.appinfo: fix assets exceeding 1024 chars

This commit is contained in:
Cynthia Foxwell 2023-10-07 22:38:14 -06:00
parent b9e5228626
commit 9e4d458b0d

View file

@ -1621,6 +1621,11 @@ appinfo.callback = async function (msg, line) {
if (app.privacy_policy_url) { if (app.privacy_policy_url) {
links.push(`[Privacy Policy](${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) { if (images.length > 0 || links.length > 0) {
embed.fields.push({ embed.fields.push({
@ -1640,28 +1645,48 @@ appinfo.callback = async function (msg, line) {
} }
const mappedAssets = assets.map( 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({ const left =
name: "Assets", "- " +
value: mappedAssets.slice(0, Math.ceil(mappedAssets.length / 2)).join("\n- ");
const right =
"- " + "- " +
mappedAssets mappedAssets
.slice(0, Math.ceil(mappedAssets.length / 2)) .slice(Math.ceil(mappedAssets.length / 2), mappedAssets.length)
.join("\n- "), .join("\n- ");
if (left.length < 1024 && right.length < 1024) {
embed.fields.push({
name: "Assets",
value: left,
inline: true, inline: true,
}); });
if (mappedAssets.length > 1) if (mappedAssets.length > 1)
embed.fields.push({ embed.fields.push({
name: "\u200b", name: "\u200b",
value: value: right,
"- " +
mappedAssets
.slice(Math.ceil(mappedAssets.length / 2), mappedAssets.length)
.join("\n- "),
inline: true, 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}; return {embed};