mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 22:23:03 -04:00
google knowledge graph
This commit is contained in:
parent
f9dfc8fc93
commit
cb83cc9c5d
2 changed files with 44 additions and 14 deletions
|
@ -1,5 +1,5 @@
|
|||
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||
const { link } = require('../../../labscore/utils/markdown')
|
||||
const { createEmbed, formatPaginationEmbeds, page } = require('../../../labscore/utils/embed')
|
||||
const { link, pill, citation } = require('../../../labscore/utils/markdown')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
const { STATICS } = require('../../../labscore/utils/statics')
|
||||
|
||||
|
@ -7,19 +7,38 @@ const { paginator } = require('../../../labscore/client');
|
|||
const { google } = require('../../../labscore/api');
|
||||
|
||||
function createSearchResultPage(context, result){
|
||||
let res = {
|
||||
"embeds": [
|
||||
createEmbed("default", context, {
|
||||
description: `**${link(result.url, result.title)}**\n${result.content}`,
|
||||
footer: {
|
||||
iconUrl: STATICS.google,
|
||||
text: `Google • ${context.application.name}`
|
||||
}
|
||||
})
|
||||
]
|
||||
let res;
|
||||
switch(result.type){
|
||||
case 1: // Search Result Entry
|
||||
res = page(createEmbed("default", context, {
|
||||
description: `**${link(result.url, result.title)}**\n${result.content}`,
|
||||
footer: {
|
||||
iconUrl: STATICS.google,
|
||||
text: `Google • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
if(result.thumbnail) res.embeds[0].thumbnail = { url: result.thumbnail };
|
||||
return res;
|
||||
break;
|
||||
case 2: // Knowledge Graph Entry
|
||||
let header = result.card.title;
|
||||
if(result.card.url) header = link(result.card.url, result.card.title)
|
||||
res = page(createEmbed("default", context, {
|
||||
description: `**${header}**\n*${result.card.description}*\n\n`,
|
||||
footer: {
|
||||
iconUrl: STATICS.google,
|
||||
text: `Google Knowledge Graph • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
if(result.card.image) res.embeds[0].thumbnail = { url: result.card.image };
|
||||
if(result.card.content) res.embeds[0].description += result.card.content.replace(/\n/g, '') + citation(1, result.card.url, "Source")
|
||||
return res;
|
||||
break;
|
||||
default:
|
||||
res = page(createEmbed("error", context, "Unknown GoogleResult Type: " + result.type))
|
||||
return res;
|
||||
break;
|
||||
}
|
||||
if(result.thumbnail) res.embeds[0].thumbnail = { url: result.thumbnail };
|
||||
return res;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -34,4 +34,15 @@ module.exports.smallPill = function(content){
|
|||
module.exports.iconPill = function(icon, content){
|
||||
if(!ICONS[icon]) icon = "question"
|
||||
return ICONS[icon] + " **` " + content + " `**"
|
||||
}
|
||||
|
||||
const SUPERSCRIPT_NUMBERS = ["⁰","¹","²","³","⁴","⁵","⁶","⁷","⁸","⁹"]
|
||||
module.exports.citation = function(number = 1, url, tooltip = ""){
|
||||
let formatted = "";
|
||||
for(const n of number.toString().split('')) formatted += SUPERSCRIPT_NUMBERS[parseInt(n)]
|
||||
if(url){
|
||||
if(tooltip.length) tooltip = ` '${tooltip}'`
|
||||
return `[⁽${formatted}⁾](${url}${tooltip})`
|
||||
}
|
||||
return `⁽${formatted}⁾`
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue