diff --git a/commands/message/search/anime.js b/commands/message/search/anime.js index 84ec389..2523596 100644 --- a/commands/message/search/anime.js +++ b/commands/message/search/anime.js @@ -10,7 +10,7 @@ const { smallPill, link, pill, stringwrapPreserveWords, timestamp, TIMESTAMP_FLA const { editOrReply } = require('#utils/message'); const { STATIC_ASSETS } = require("#utils/statics"); -function renderAnimeResultsPage(context, res){ +function renderAnimeResultsPage(context, res, includeSupplementalData = true){ let result = createEmbed("default", context, { author: { name: res.title, @@ -30,6 +30,7 @@ function renderAnimeResultsPage(context, res){ // Render Description 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.genres) result.description += res.genres.map((r)=>smallPill(r)).join(" ") + "\n\n"; 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, // allow for fetching extra data related to results. episodes_key: res.supplemental.episodes, characters_key: res.supplemental.characters, + related_key: res.supplemental.related, name: res.title, color: hexToDecimalColor(res.color || COLORS_HEX.embed), cover: res.cover - }); + } : {}); } module.exports = { @@ -190,7 +192,31 @@ module.exports = { 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){