mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-07 13:43:06 -04:00
[nextgen/cardstack] add BUTTON_GENERATOR
- support dynamic button resolving - update all commands using dynstack to latest api - add supplemental to wolfram
This commit is contained in:
parent
3a016dde3d
commit
ecaaba9d3c
10 changed files with 356 additions and 176 deletions
|
@ -2,7 +2,7 @@ const { anime, animeSupplemental} = require('#api');
|
|||
const { PERMISSION_GROUPS, OMNI_ANIME_FORMAT_TYPES, COLORS_HEX} = require('#constants');
|
||||
|
||||
const { createDynamicCardStack } = require("#cardstack/index");
|
||||
const { ResolveCallbackTypes } = require("#cardstack/constants");
|
||||
const { ResolveCallbackTypes, InteractiveComponentTypes} = require("#cardstack/constants");
|
||||
|
||||
const { hexToDecimalColor } = require("#utils/color");
|
||||
const { createEmbed, page } = require('#utils/embed');
|
||||
|
@ -121,6 +121,7 @@ module.exports = {
|
|||
cards: pages,
|
||||
interactive: {
|
||||
episodes_button: {
|
||||
type: InteractiveComponentTypes.BUTTON,
|
||||
label: "Episodes",
|
||||
inline: false,
|
||||
visible: true,
|
||||
|
@ -176,6 +177,7 @@ module.exports = {
|
|||
}
|
||||
},
|
||||
characters_button: {
|
||||
type: InteractiveComponentTypes.BUTTON,
|
||||
label: "Characters",
|
||||
inline: false,
|
||||
visible: true,
|
||||
|
@ -217,6 +219,7 @@ module.exports = {
|
|||
}
|
||||
},
|
||||
related_button: {
|
||||
type: InteractiveComponentTypes.BUTTON,
|
||||
label: "Related",
|
||||
inline: false,
|
||||
visible: true,
|
||||
|
|
|
@ -2,7 +2,7 @@ const { anime, animeSupplemental} = require('#api');
|
|||
const { PERMISSION_GROUPS, OMNI_ANIME_FORMAT_TYPES, COLORS_HEX} = require('#constants');
|
||||
|
||||
const { createDynamicCardStack } = require("#cardstack/index");
|
||||
const { ResolveCallbackTypes } = require("#cardstack/constants");
|
||||
const { ResolveCallbackTypes, InteractiveComponentTypes} = require("#cardstack/constants");
|
||||
|
||||
const { hexToDecimalColor } = require("#utils/color");
|
||||
const { createEmbed, page } = require('#utils/embed');
|
||||
|
@ -110,6 +110,7 @@ module.exports = {
|
|||
cards: pages,
|
||||
interactive: {
|
||||
episodes_button: {
|
||||
type: InteractiveComponentTypes.BUTTON,
|
||||
label: "Episodes",
|
||||
inline: false,
|
||||
visible: true,
|
||||
|
@ -165,6 +166,7 @@ module.exports = {
|
|||
}
|
||||
},
|
||||
characters_button: {
|
||||
type: InteractiveComponentTypes.BUTTON,
|
||||
label: "Characters",
|
||||
inline: false,
|
||||
visible: true,
|
||||
|
@ -206,6 +208,7 @@ module.exports = {
|
|||
}
|
||||
},
|
||||
related_button: {
|
||||
type: InteractiveComponentTypes.BUTTON,
|
||||
label: "Related",
|
||||
inline: false,
|
||||
visible: true,
|
||||
|
|
|
@ -2,11 +2,10 @@ const { googleNews, googleNewsSupplemental} = require('#api');
|
|||
const { PERMISSION_GROUPS } = require('#constants');
|
||||
|
||||
const { createDynamicCardStack } = require("#cardstack/index");
|
||||
const { ResolveCallbackTypes } = require("#cardstack/constants");
|
||||
const { ResolveCallbackTypes, InteractiveComponentTypes} = require("#cardstack/constants");
|
||||
|
||||
const { createEmbed, page } = require('#utils/embed');
|
||||
const { acknowledge } = require('#utils/interactions');
|
||||
const { link } = require('#utils/markdown');
|
||||
const { editOrReply } = require('#utils/message');
|
||||
const { STATIC_ASSETS, STATIC_ICONS, STATICS} = require("#utils/statics");
|
||||
|
||||
|
@ -76,6 +75,7 @@ module.exports = {
|
|||
cards: pages,
|
||||
interactive: {
|
||||
full_coverage_button: {
|
||||
type: InteractiveComponentTypes.BUTTON,
|
||||
label: "Full Coverage",
|
||||
icon: "button_full_coverage",
|
||||
inline: true,
|
||||
|
@ -83,7 +83,7 @@ module.exports = {
|
|||
return (pg.getState("full_coverage_key") !== null)
|
||||
},
|
||||
condition: true,
|
||||
renderLoadingState: (pg) => {
|
||||
renderLoadingState: () => {
|
||||
return createEmbed("default", context, {
|
||||
author: {
|
||||
name: "Full Coverage",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const {wolframAlpha} = require("#api");
|
||||
const { wolframAlpha, wolframSupplemental} = require("#api");
|
||||
const { paginator } = require('#client');
|
||||
const { PERMISSION_GROUPS } = require('#constants');
|
||||
|
||||
|
@ -6,10 +6,12 @@ const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed');
|
|||
const { acknowledge } = require('#utils/interactions');
|
||||
const { citation, smallIconPill } = require('#utils/markdown');
|
||||
const { editOrReply } = require('#utils/message')
|
||||
const { STATICS } = require('#utils/statics')
|
||||
const { STATICS, STATIC_ASSETS} = require('#utils/statics')
|
||||
const {createDynamicCardStack} = require("#cardstack/index");
|
||||
const {InteractiveComponentTypes, ResolveCallbackTypes} = require("#cardstack/constants");
|
||||
|
||||
function createWolframPage(context, pod, query, sources) {
|
||||
let res = page(createEmbed("default", context, {
|
||||
let res = createEmbed("default", context, {
|
||||
author: {
|
||||
name: pod.title,
|
||||
url: `https://www.wolframalpha.com/input?i=${encodeURIComponent(query)}`
|
||||
|
@ -19,24 +21,28 @@ function createWolframPage(context, pod, query, sources) {
|
|||
iconUrl: STATICS.wolframalpha,
|
||||
text: `Wolfram|Alpha • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
if (pod.icon) res.embeds[0].author.iconUrl = pod.icon
|
||||
if (pod.value) res.embeds[0].description = pod.value.substr(0, 1000)
|
||||
})
|
||||
if (pod.icon) res.author.iconUrl = pod.icon
|
||||
if (pod.value) res.description = pod.value.substr(0, 1000)
|
||||
if (pod.value && pod.refs) {
|
||||
for (const r of pod.refs) {
|
||||
let src = Object.values(sources).filter((s) => s.ref == r)[0]
|
||||
let src = Object.values(sources).filter((s) => s.ref === r)[0]
|
||||
if (!src) continue;
|
||||
|
||||
// Only add a direct source if one is available
|
||||
if (src.collections) {
|
||||
res.embeds[0].description += citation(r, src.url, src.title + ' | ' + src.collections[0].text)
|
||||
res.description += citation(r, src.url, src.title + ' | ' + src.collections[0].text)
|
||||
continue;
|
||||
}
|
||||
if (src.url) res.embeds[0].description += citation(r, src.url, src.title)
|
||||
if (src.url) res.description += citation(r, src.url, src.title)
|
||||
}
|
||||
}
|
||||
if (pod.image) res.embeds[0].image = { url: pod.image };
|
||||
return res;
|
||||
if (pod.image) res.image = { url: pod.image };
|
||||
return page(res, {}, {
|
||||
supplemental: pod.states,
|
||||
pod_icon: pod.icon,
|
||||
pod_title: pod.title
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -54,7 +60,6 @@ module.exports = {
|
|||
permissionsClient: [...PERMISSION_GROUPS.baseline],
|
||||
run: async (context, args) => {
|
||||
await acknowledge(context);
|
||||
|
||||
|
||||
if(context.message.messageReference) {
|
||||
let msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId);
|
||||
|
@ -67,16 +72,54 @@ module.exports = {
|
|||
let search = await wolframAlpha(context, args.query)
|
||||
search = search.response
|
||||
|
||||
if (search.body.status == 1) return editOrReply(context, createEmbed("warning", context, search.body.message))
|
||||
if (search.body.status === 1) return editOrReply(context, createEmbed("warning", context, search.body.message))
|
||||
|
||||
let pages = []
|
||||
for (const res of search.body.data) {
|
||||
pages.push(createWolframPage(context, res, args.query, search.body.sources))
|
||||
}
|
||||
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
|
||||
return await createDynamicCardStack(context, {
|
||||
cards: pages,
|
||||
interactive: {
|
||||
state_buttons: {
|
||||
type: InteractiveComponentTypes.BUTTON_GENERATOR,
|
||||
inline: true,
|
||||
// Resolve Components
|
||||
resolveComponents: (pg)=>{
|
||||
if(!pg.getState("supplemental") || pg.getState("supplemental").length === 0) return [];
|
||||
return pg.getState("supplemental").map((b)=>{
|
||||
return {
|
||||
label: b.label,
|
||||
visible: true,
|
||||
condition: true,
|
||||
customId: b.supplemental_key,
|
||||
icon: "button_wolfram_compute",
|
||||
renderLoadingState: (pg, component) => {
|
||||
return createEmbed("default", context, {
|
||||
author: {
|
||||
name: `${pg.getState("pod_title")} › ${component.label}`,
|
||||
iconUrl: pg.getState("pod_icon")
|
||||
},
|
||||
image: {
|
||||
url: STATIC_ASSETS.chat_loading
|
||||
}
|
||||
})
|
||||
},
|
||||
resolvePage: async (pg, component)=>{
|
||||
let sup = await wolframSupplemental(context, component.customId);
|
||||
|
||||
return {
|
||||
type: ResolveCallbackTypes.REPLACE_PARENT_CARD,
|
||||
card: createWolframPage(context, sup.response.body.pod_supplemental, args.query, sup.response.body.sources)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
if(e.response.body?.error) return editOrReply(context, createEmbed("warning", context, e.response.body.error.message))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue