[cmd/anime] add related content supplemental

This commit is contained in:
bignutty 2025-02-13 21:24:37 +01:00
parent b4cfcaa211
commit 783e11fa9d

View file

@ -10,7 +10,7 @@ const { smallPill, link, pill, stringwrapPreserveWords, timestamp, TIMESTAMP_FLA
const { editOrReply } = require('#utils/message'); const { editOrReply } = require('#utils/message');
const { STATIC_ASSETS } = require("#utils/statics"); const { STATIC_ASSETS } = require("#utils/statics");
function renderAnimeResultsPage(context, res){ function renderAnimeResultsPage(context, res, includeSupplementalData = true){
let result = createEmbed("default", context, { let result = createEmbed("default", context, {
author: { author: {
name: res.title, name: res.title,
@ -30,6 +30,7 @@ function renderAnimeResultsPage(context, res){
// Render Description // Render Description
if(res.subtitle) result.description += `-# ${res.subtitle}\n\n`; if(res.subtitle) result.description += `-# ${res.subtitle}\n\n`;
if(res.type !== "ANIME") result.description += pill(OMNI_ANIME_FORMAT_TYPES[res.type]) + " "
if(res.subtype) result.description += pill(OMNI_ANIME_FORMAT_TYPES[res.subtype]) + " " if(res.subtype) result.description += pill(OMNI_ANIME_FORMAT_TYPES[res.subtype]) + " "
if(res.genres) result.description += res.genres.map((r)=>smallPill(r)).join(" ") + "\n\n"; if(res.genres) result.description += res.genres.map((r)=>smallPill(r)).join(" ") + "\n\n";
if(res.description) result.description += stringwrapPreserveWords(res.description, 600); if(res.description) result.description += stringwrapPreserveWords(res.description, 600);
@ -59,15 +60,16 @@ function renderAnimeResultsPage(context, res){
}) })
} }
return page(result, {}, { return page(result, {}, includeSupplementalData ? {
// Supplemental keys are provided by the backend, // Supplemental keys are provided by the backend,
// allow for fetching extra data related to results. // allow for fetching extra data related to results.
episodes_key: res.supplemental.episodes, episodes_key: res.supplemental.episodes,
characters_key: res.supplemental.characters, characters_key: res.supplemental.characters,
related_key: res.supplemental.related,
name: res.title, name: res.title,
color: hexToDecimalColor(res.color || COLORS_HEX.embed), color: hexToDecimalColor(res.color || COLORS_HEX.embed),
cover: res.cover cover: res.cover
}); } : {});
} }
module.exports = { module.exports = {
@ -190,7 +192,31 @@ module.exports = {
return formatPaginationEmbeds(cards); return formatPaginationEmbeds(cards);
} }
},
related_button: {
label: "Related",
inline: false,
visible: true,
condition: (page) => {
return (page.getState("related_key") !== null)
},
renderLoadingState: (pg) => {
return createEmbed("default", context, {
description: `-# ${pg.getState("name")} **Related Content**`,
image: {
url: STATIC_ASSETS.card_skeleton
},
color: pg.getState("color")
})
},
resolvePage: async (pg) => {
let episodes = await animeSupplemental(context, pg.getState("related_key"));
let cards = episodes.response.body.relations.map((e) => renderAnimeResultsPage(context, e, false))
return formatPaginationEmbeds(cards);
} }
},
} }
}); });
}catch(e){ }catch(e){