mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-09 22:53:06 -04:00
change paths for cardstack types
This commit is contained in:
parent
1afe082d92
commit
17964ce5cb
7 changed files with 81 additions and 38 deletions
|
@ -1,17 +1,18 @@
|
|||
const { anime, animeSupplemental} = require('#api');
|
||||
const { PERMISSION_GROUPS, OMNI_ANIME_FORMAT_TYPES, COLORS_HEX} = require('#constants');
|
||||
|
||||
const { createDynamicCardStack } = require("#cardstack");
|
||||
const { createDynamicCardStack } = require("#cardstack/index");
|
||||
const { ResolveCallbackTypes } = require("#cardstack/constants");
|
||||
|
||||
const { hexToDecimalColor } = require("#utils/color");
|
||||
const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed');
|
||||
const { createEmbed, page } = require('#utils/embed');
|
||||
const { acknowledge } = require('#utils/interactions');
|
||||
const { smallPill, link, pill, stringwrapPreserveWords, timestamp, TIMESTAMP_FLAGS} = require('#utils/markdown');
|
||||
const { editOrReply } = require('#utils/message');
|
||||
const { InteractionContextTypes, ApplicationIntegrationTypes, ApplicationCommandOptionTypes } = require('detritus-client/lib/constants');
|
||||
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,
|
||||
|
@ -31,6 +32,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);
|
||||
|
@ -39,7 +41,7 @@ function renderAnimeResultsPage(context, res){
|
|||
// Render Images
|
||||
if(res.cover) result.thumbnail = { url: res.cover };
|
||||
if(res.image) result.image = { url: res.image };
|
||||
|
||||
|
||||
// Render Color
|
||||
if(res.color) result.color = hexToDecimalColor(res.color);
|
||||
|
||||
|
@ -60,18 +62,18 @@ 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 = {
|
||||
name: 'anime',
|
||||
description: 'Search for Anime.',
|
||||
|
@ -116,7 +118,7 @@ module.exports = {
|
|||
if(!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`))
|
||||
|
||||
createDynamicCardStack(context, {
|
||||
cards: formatPaginationEmbeds(pages),
|
||||
cards: pages,
|
||||
interactive: {
|
||||
episodes_button: {
|
||||
label: "Episodes",
|
||||
|
@ -162,7 +164,15 @@ module.exports = {
|
|||
return page(card)
|
||||
})
|
||||
|
||||
return formatPaginationEmbeds(cards);
|
||||
return {
|
||||
type: ResolveCallbackTypes.SUBSTACK,
|
||||
cards: cards.length >= 1 ? cards : [
|
||||
// This happens if the episode metadata resolver fails.
|
||||
page(createEmbed("defaultNoFooter", context, {
|
||||
description: `-# ${pg.getState("name")} › **Episodes**\n## Episodes Unavailable\n\nWe're unable to display episode details for this content.`
|
||||
}))
|
||||
],
|
||||
};
|
||||
}
|
||||
},
|
||||
characters_button: {
|
||||
|
@ -200,7 +210,37 @@ module.exports = {
|
|||
return page(card)
|
||||
})
|
||||
|
||||
return formatPaginationEmbeds(cards);
|
||||
return {
|
||||
type: ResolveCallbackTypes.SUBSTACK,
|
||||
cards: 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 {
|
||||
type: ResolveCallbackTypes.SUBSTACK,
|
||||
cards: cards
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue