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
1 changed files with 42 additions and 17 deletions

View File

@ -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};