mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 14:13:02 -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]) + " "
|
if(res.subtype) result.description += pill(OMNI_ANIME_FORMAT_TYPES[res.subtype]) + " "
|
||||||
else result.description += pill(OMNI_ANIME_FORMAT_TYPES[res.type]) + " "
|
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.genres?.length) 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.tags?.length) result.description += "-# " + res.tags.map((t)=>smallPill(t)).join(" ") + "\n\n";
|
||||||
if(res.description) result.description += stringwrapPreserveWords(res.description, 600);
|
if(res.description) result.description += stringwrapPreserveWords(res.description, 600);
|
||||||
if(res.attribution?.description) result.description += `\n\n-# Source • ${res.attribution.description}`
|
if(res.attribution?.description) result.description += `\n\n-# Source • ${res.attribution.description}`
|
||||||
|
|
||||||
|
|
|
@ -1,84 +1,89 @@
|
||||||
const { googleImages } = require('#api');
|
const {googleImages} = require('#api');
|
||||||
const { paginator } = require('#client');
|
const {paginator} = require('#client');
|
||||||
const { PERMISSION_GROUPS } = require('#constants');
|
const {PERMISSION_GROUPS} = require('#constants');
|
||||||
|
|
||||||
const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed');
|
const {createEmbed, formatPaginationEmbeds, page} = require('#utils/embed');
|
||||||
const { acknowledge } = require('#utils/interactions');
|
const {acknowledge} = require('#utils/interactions');
|
||||||
const { favicon } = require("#utils/markdown");
|
const {favicon} = require("#utils/markdown");
|
||||||
const { editOrReply } = require('#utils/message')
|
const {editOrReply} = require('#utils/message')
|
||||||
const { STATICS } = require('#utils/statics')
|
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) {
|
function createImageResultPage(context, result) {
|
||||||
let res = page(createEmbed("default", context, {
|
let res = page(createEmbed("default", context, {
|
||||||
author: {
|
author: {
|
||||||
iconUrl: favicon(result.url),
|
iconUrl: favicon(result.url),
|
||||||
name: result.title,
|
name: result.title,
|
||||||
url: result.url
|
url: result.url
|
||||||
},
|
},
|
||||||
image: {
|
image: {
|
||||||
url: result.image
|
url: result.image
|
||||||
},
|
},
|
||||||
footer: {
|
footer: {
|
||||||
iconUrl: STATICS.google,
|
iconUrl: STATICS.google,
|
||||||
text: `Google Images • ${context.application.name}`
|
text: `Google Images • ${context.application.name}`
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
if (result.thumbnail) res.embeds[0].thumbnail = { url: result.thumbnail };
|
if (result.thumbnail) res.embeds[0].thumbnail = {url: result.thumbnail};
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'image',
|
name: 'image',
|
||||||
label: 'query',
|
label: 'query',
|
||||||
aliases: ['i', 'img'],
|
aliases: ['i', 'img'],
|
||||||
description: 'Search the web for images on Google.',
|
description: 'Search the web for images on Google.',
|
||||||
contexts: [
|
contexts: [
|
||||||
InteractionContextTypes.GUILD,
|
InteractionContextTypes.GUILD,
|
||||||
InteractionContextTypes.PRIVATE_CHANNEL,
|
InteractionContextTypes.PRIVATE_CHANNEL,
|
||||||
InteractionContextTypes.BOT_DM
|
InteractionContextTypes.BOT_DM
|
||||||
],
|
],
|
||||||
integrationTypes: [
|
integrationTypes: [
|
||||||
ApplicationIntegrationTypes.USER_INSTALL
|
ApplicationIntegrationTypes.USER_INSTALL
|
||||||
],
|
],
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'query',
|
name: 'query',
|
||||||
description: 'Image search query.',
|
description: 'Image search query.',
|
||||||
type: ApplicationCommandOptionTypes.TEXT,
|
type: ApplicationCommandOptionTypes.TEXT,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'incognito',
|
name: 'incognito',
|
||||||
description: 'Makes the response only visible to you.',
|
description: 'Makes the response only visible to you.',
|
||||||
type: ApplicationCommandOptionTypes.BOOLEAN,
|
type: ApplicationCommandOptionTypes.BOOLEAN,
|
||||||
required: false,
|
required: false,
|
||||||
default: 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))
|
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
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.`))
|
try {
|
||||||
await paginator.createPaginator({
|
let search = await googleImages(context, args.query, false) //safesearch is always on
|
||||||
context,
|
search = search.response
|
||||||
pages: formatPaginationEmbeds(pages)
|
|
||||||
});
|
if (search.body.status == 2) return editOrReply(context, createEmbed("error", context, search.body.message))
|
||||||
} catch (e) {
|
|
||||||
console.log(e)
|
let pages = []
|
||||||
return editOrReply(context, createEmbed("error", context, `Unable to perform google search.`))
|
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 { 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 renderFooter(context, doodle){
|
function renderFooter(context, doodle){
|
||||||
if(doodle.super_g) return {
|
if(doodle.super_g) return {
|
||||||
|
@ -291,10 +292,9 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`))
|
if(!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`))
|
||||||
|
|
||||||
await paginator.createPaginator({
|
return await createDynamicCardStack(context, {
|
||||||
context,
|
cards: pages
|
||||||
pages: formatPaginationEmbeds(pages)
|
|
||||||
});
|
});
|
||||||
}catch(e){
|
}catch(e){
|
||||||
console.log(e)
|
console.log(e)
|
||||||
|
|
|
@ -36,8 +36,8 @@ function renderAnimeResultsPage(context, res, includeSupplementalData = true){
|
||||||
if(res.subtype) result.description += pill(OMNI_ANIME_FORMAT_TYPES[res.subtype]) + " "
|
if(res.subtype) result.description += pill(OMNI_ANIME_FORMAT_TYPES[res.subtype]) + " "
|
||||||
else result.description += pill(OMNI_ANIME_FORMAT_TYPES[res.type]) + " "
|
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.genres?.length) 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.tags?.length) result.description += "-# " + res.tags.map((t)=>smallPill(t)).join(" ") + "\n\n";
|
||||||
if(res.description) result.description += stringwrapPreserveWords(res.description, 600);
|
if(res.description) result.description += stringwrapPreserveWords(res.description, 600);
|
||||||
if(res.attribution?.description) result.description += `\n\n-# Source • ${res.attribution.description}`
|
if(res.attribution?.description) result.description += `\n\n-# Source • ${res.attribution.description}`
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
const { googleImages } = require('#api');
|
const { googleImages } = require('#api');
|
||||||
const { paginator } = require('#client');
|
const {createDynamicCardStack} = require("#cardstack/index");
|
||||||
const { PERMISSION_GROUPS } = require('#constants');
|
const { PERMISSION_GROUPS } = require('#constants');
|
||||||
|
|
||||||
const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed');
|
const { createEmbed, page } = require('#utils/embed');
|
||||||
const { acknowledge } = require('#utils/interactions');
|
const { acknowledge } = require('#utils/interactions');
|
||||||
const { favicon } = require("#utils/markdown");
|
const { favicon } = require("#utils/markdown");
|
||||||
const { editOrReply } = require('#utils/message')
|
const { editOrReply } = require('#utils/message')
|
||||||
|
@ -57,9 +57,8 @@ module.exports = {
|
||||||
|
|
||||||
if (!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`))
|
if (!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`))
|
||||||
|
|
||||||
await paginator.createPaginator({
|
return await createDynamicCardStack(context, {
|
||||||
context,
|
cards: pages
|
||||||
pages: formatPaginationEmbeds(pages)
|
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
|
|
|
@ -8,6 +8,7 @@ const { acknowledge } = require('#utils/interactions');
|
||||||
const { link, citation, icon, codeblock, pill, smallPill, favicon} = require('#utils/markdown')
|
const { link, citation, icon, codeblock, pill, smallPill, favicon} = require('#utils/markdown')
|
||||||
const { editOrReply } = require('#utils/message')
|
const { editOrReply } = require('#utils/message')
|
||||||
const { STATICS } = require('#utils/statics')
|
const { STATICS } = require('#utils/statics')
|
||||||
|
const {createDynamicCardStack} = require("#cardstack/index");
|
||||||
|
|
||||||
function renderFooter(context, doodle){
|
function renderFooter(context, doodle){
|
||||||
if(doodle?.super_g) return {
|
if(doodle?.super_g) return {
|
||||||
|
@ -282,10 +283,9 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`))
|
if(!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`))
|
||||||
|
|
||||||
await paginator.createPaginator({
|
return await createDynamicCardStack(context, {
|
||||||
context,
|
cards: pages
|
||||||
pages: formatPaginationEmbeds(pages)
|
|
||||||
});
|
});
|
||||||
}catch(e){
|
}catch(e){
|
||||||
console.log(e)
|
console.log(e)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue