utility.decoration: more info and cleaner layout

This commit is contained in:
Cynthia Foxwell 2024-07-04 19:22:50 -06:00
parent 5a967de4cd
commit 4e6c5b88cd

View file

@ -1055,9 +1055,9 @@ decoration.callback = async function (msg, line, [user]) {
"/users/" + id,
true
);
let decor;
let decor, decorRes;
try {
const decorRes = await fetch(
decorRes = await fetch(
`https://decor.fieryflames.dev/api/users/${id}/decoration`,
{
headers: {
@ -1067,6 +1067,21 @@ decoration.callback = async function (msg, line, [user]) {
}
).then((res) => res.json());
if (decorRes.presetId) {
// horror
const presets = await fetch(
`https://decor.fieryflames.dev/api/decorations/presets`,
{
headers: {
"User-Agent":
"HiddenPhox/decoration (https://gitdab.com/Cynosphere/HiddenPhox)",
},
}
).then((res) => res.json());
decorRes.preset = presets.find((p) => p.id === decorRes.presetId);
}
decor = `https://decorcdn.fieryflames.dev/${decorRes.animated ? "a_" : ""}${
decorRes.hash
}.png`;
@ -1085,17 +1100,42 @@ decoration.callback = async function (msg, line, [user]) {
title: `Decoration for \`${formatUsername(userObj)}\``,
};
baseEmbed.description = (
(normalUrl ? `[Normal decoration](${normalUrl})` : "") +
(decor ? `\n[Decor decoration](${decor})` : "")
).trim();
baseEmbed.fields = [];
if (
userObj.avatar_decoration_data?.asset.startsWith("a_") ||
decor?.indexOf("/a_") > -1
) {
baseEmbed.description += "\n(Animated decoration, open in browser to view)";
baseEmbed.description = baseEmbed.description.trim();
if (normalUrl) {
const listing = await hf.bot.requestHandler
.request(
"GET",
`/store/published-listings/skus/${userObj.avatar_decoration_data.sku_id}`,
true
)
.catch(() => {});
baseEmbed.fields.push({
name: `Discord ${
userObj.avatar_decoration_data.asset.startsWith("a_")
? "(Animated)"
: ""
}`,
value: `**${
listing?.sku
? `[${listing?.sku?.name}](https://discord.com/shop#itemSkuId=${userObj.avatar_decoration_data.sku_id})`
: "Unknown"
}** (\`${
userObj.avatar_decoration_data.sku_id
}\`)\n[Image](${normalUrl})`,
inline: true,
});
}
if (decor) {
baseEmbed.fields.push({
name: `Decor ${decor.indexOf("/a_") > -1 ? "(Animated)" : ""}`,
value: `**${decorRes.alt}**\n${
decorRes.preset ? ` from preset **${decorRes.preset.name}**\n` : ""
}[Image](${decor})`,
inline: true,
});
}
baseEmbed.url = normalUrl || decor;