diff --git a/commands/interaction/slash/search/anime.js b/commands/interaction/slash/search/anime.js index 08a0176..85f8957 100644 --- a/commands/interaction/slash/search/anime.js +++ b/commands/interaction/slash/search/anime.js @@ -37,8 +37,8 @@ function renderAnimeResultsPage(context, res, includeSupplementalData = true){ if(res.subtype) result.description += pill(OMNI_ANIME_FORMAT_TYPES[res.subtype]) + " " else result.description += pill(OMNI_ANIME_FORMAT_TYPES[res.type]) + " " } - if(res.genres) result.description += res.genres.map((r)=>smallPill(r)).join(" ") + "\n"; - if(res.tags) result.description += "-# " + res.tags.map((t)=>smallPill(t)).join(" ") + "\n\n"; + if(res.genres?.length) result.description += res.genres.splice(0,3).map((r)=>smallPill(r)).join(" ") + "\n"; + if(res.tags?.length) result.description += "-# " + res.tags.map((t)=>smallPill(t)).join(" ") + "\n\n"; if(res.description) result.description += stringwrapPreserveWords(res.description, 600); if(res.attribution?.description) result.description += `\n\n-# Source • ${res.attribution.description}` diff --git a/commands/interaction/slash/search/google-images.js b/commands/interaction/slash/search/google-images.js index e5d45c8..aea49ea 100644 --- a/commands/interaction/slash/search/google-images.js +++ b/commands/interaction/slash/search/google-images.js @@ -1,84 +1,89 @@ -const { googleImages } = require('#api'); -const { paginator } = require('#client'); -const { PERMISSION_GROUPS } = require('#constants'); +const {googleImages} = require('#api'); +const {paginator} = require('#client'); +const {PERMISSION_GROUPS} = require('#constants'); -const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed'); -const { acknowledge } = require('#utils/interactions'); -const { favicon } = require("#utils/markdown"); -const { editOrReply } = require('#utils/message') -const { STATICS } = require('#utils/statics') +const {createEmbed, formatPaginationEmbeds, page} = require('#utils/embed'); +const {acknowledge} = require('#utils/interactions'); +const {favicon} = require("#utils/markdown"); +const {editOrReply} = require('#utils/message') +const {STATICS} = require('#utils/statics') -const { ApplicationCommandOptionTypes, InteractionContextTypes, ApplicationIntegrationTypes } = require('detritus-client/lib/constants'); +const { + ApplicationCommandOptionTypes, + InteractionContextTypes, + ApplicationIntegrationTypes +} = require('detritus-client/lib/constants'); +const {createDynamicCardStack} = require("#cardstack/index"); function createImageResultPage(context, result) { - let res = page(createEmbed("default", context, { - author: { - iconUrl: favicon(result.url), - name: result.title, - url: result.url - }, - image: { - url: result.image - }, - footer: { - iconUrl: STATICS.google, - text: `Google Images • ${context.application.name}` - } - })) - if (result.thumbnail) res.embeds[0].thumbnail = { url: result.thumbnail }; - return res; + let res = page(createEmbed("default", context, { + author: { + iconUrl: favicon(result.url), + name: result.title, + url: result.url + }, + image: { + url: result.image + }, + footer: { + iconUrl: STATICS.google, + text: `Google Images • ${context.application.name}` + } + })) + if (result.thumbnail) res.embeds[0].thumbnail = {url: result.thumbnail}; + return res; } module.exports = { - name: 'image', - label: 'query', - aliases: ['i', 'img'], - description: 'Search the web for images on Google.', - contexts: [ - InteractionContextTypes.GUILD, - InteractionContextTypes.PRIVATE_CHANNEL, - InteractionContextTypes.BOT_DM - ], - integrationTypes: [ - ApplicationIntegrationTypes.USER_INSTALL - ], - options: [ - { - name: 'query', - description: 'Image search query.', - type: ApplicationCommandOptionTypes.TEXT, - required: true - }, - { - name: 'incognito', - description: 'Makes the response only visible to you.', - type: ApplicationCommandOptionTypes.BOOLEAN, - required: false, - default: false - } - ], - run: async (context, args) => { - await acknowledge(context, args.incognito, [...PERMISSION_GROUPS.baseline_slash]); - - try { - let search = await googleImages(context, args.query, false) //safesearch is always on - search = search.response - - if (search.body.status == 2) return editOrReply(context, createEmbed("error", context, search.body.message)) - - let pages = [] - for (const res of search.body.results) { - pages.push(createImageResultPage(context, res)) + name: 'image', + label: 'query', + aliases: ['i', 'img'], + description: 'Search the web for images on Google.', + contexts: [ + InteractionContextTypes.GUILD, + InteractionContextTypes.PRIVATE_CHANNEL, + InteractionContextTypes.BOT_DM + ], + integrationTypes: [ + ApplicationIntegrationTypes.USER_INSTALL + ], + options: [ + { + name: 'query', + description: 'Image search query.', + type: ApplicationCommandOptionTypes.TEXT, + required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } + ], + run: async (context, args) => { + await acknowledge(context, args.incognito, [...PERMISSION_GROUPS.baseline_slash]); - if (!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`)) - await paginator.createPaginator({ - context, - pages: formatPaginationEmbeds(pages) - }); - } catch (e) { - console.log(e) - return editOrReply(context, createEmbed("error", context, `Unable to perform google search.`)) - } - }, + try { + let search = await googleImages(context, args.query, false) //safesearch is always on + search = search.response + + if (search.body.status == 2) return editOrReply(context, createEmbed("error", context, search.body.message)) + + let pages = [] + for (const res of search.body.results) { + pages.push(createImageResultPage(context, res)) + } + + if (!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`)) + + return await createDynamicCardStack(context, { + cards: pages + }); + } catch (e) { + console.log(e) + return editOrReply(context, createEmbed("error", context, `Unable to perform google search.`)) + } + }, }; \ No newline at end of file diff --git a/commands/interaction/slash/search/google.js b/commands/interaction/slash/search/google.js index 363c1f1..4215459 100644 --- a/commands/interaction/slash/search/google.js +++ b/commands/interaction/slash/search/google.js @@ -10,6 +10,7 @@ const { editOrReply } = require('#utils/message') const { STATICS } = require('#utils/statics') const { ApplicationCommandOptionTypes, InteractionContextTypes, ApplicationIntegrationTypes } = require('detritus-client/lib/constants'); +const {createDynamicCardStack} = require("#cardstack/index"); function renderFooter(context, doodle){ if(doodle.super_g) return { @@ -291,10 +292,9 @@ module.exports = { } if(!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`)) - - await paginator.createPaginator({ - context, - pages: formatPaginationEmbeds(pages) + + return await createDynamicCardStack(context, { + cards: pages }); }catch(e){ console.log(e) diff --git a/commands/message/search/anime.js b/commands/message/search/anime.js index 4b9d99d..0b3fb18 100644 --- a/commands/message/search/anime.js +++ b/commands/message/search/anime.js @@ -36,8 +36,8 @@ function renderAnimeResultsPage(context, res, includeSupplementalData = true){ if(res.subtype) result.description += pill(OMNI_ANIME_FORMAT_TYPES[res.subtype]) + " " else result.description += pill(OMNI_ANIME_FORMAT_TYPES[res.type]) + " " } - if(res.genres) result.description += res.genres.splice(0,3).map((r)=>smallPill(r)).join(" ") + "\n"; - if(res.tags) result.description += "-# " + res.tags.map((t)=>smallPill(t)).join(" ") + "\n\n"; + if(res.genres?.length) result.description += res.genres.splice(0,3).map((r)=>smallPill(r)).join(" ") + "\n"; + if(res.tags?.length) result.description += "-# " + res.tags.map((t)=>smallPill(t)).join(" ") + "\n\n"; if(res.description) result.description += stringwrapPreserveWords(res.description, 600); if(res.attribution?.description) result.description += `\n\n-# Source • ${res.attribution.description}` diff --git a/commands/message/search/google-images.js b/commands/message/search/google-images.js index ec3bf8f..5fa5722 100644 --- a/commands/message/search/google-images.js +++ b/commands/message/search/google-images.js @@ -1,8 +1,8 @@ const { googleImages } = require('#api'); -const { paginator } = require('#client'); +const {createDynamicCardStack} = require("#cardstack/index"); const { PERMISSION_GROUPS } = require('#constants'); -const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed'); +const { createEmbed, page } = require('#utils/embed'); const { acknowledge } = require('#utils/interactions'); const { favicon } = require("#utils/markdown"); const { editOrReply } = require('#utils/message') @@ -57,9 +57,8 @@ module.exports = { if (!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`)) - await paginator.createPaginator({ - context, - pages: formatPaginationEmbeds(pages) + return await createDynamicCardStack(context, { + cards: pages }); } catch (e) { console.log(e) diff --git a/commands/message/search/google.js b/commands/message/search/google.js index 72034b0..e145b2a 100644 --- a/commands/message/search/google.js +++ b/commands/message/search/google.js @@ -8,6 +8,7 @@ const { acknowledge } = require('#utils/interactions'); const { link, citation, icon, codeblock, pill, smallPill, favicon} = require('#utils/markdown') const { editOrReply } = require('#utils/message') const { STATICS } = require('#utils/statics') +const {createDynamicCardStack} = require("#cardstack/index"); function renderFooter(context, doodle){ if(doodle?.super_g) return { @@ -282,10 +283,9 @@ module.exports = { } if(!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`)) - - await paginator.createPaginator({ - context, - pages: formatPaginationEmbeds(pages) + + return await createDynamicCardStack(context, { + cards: pages }); }catch(e){ console.log(e)