mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-07 13:43:06 -04:00
[nextgen/cardstack] migrate google, google images to cardstack
This commit is contained in:
parent
ba7c76ff04
commit
0433c3a785
6 changed files with 95 additions and 91 deletions
|
@ -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}`
|
||||
|
||||
|
|
|
@ -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.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue