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 { createEmbed, formatPaginationEmbeds, page } = require('../../../labscore/utils/embed')
|
||||||
const { link } = require('../../../labscore/utils/markdown')
|
const { link, pill, citation } = require('../../../labscore/utils/markdown')
|
||||||
const { editOrReply } = require('../../../labscore/utils/message')
|
const { editOrReply } = require('../../../labscore/utils/message')
|
||||||
const { STATICS } = require('../../../labscore/utils/statics')
|
const { STATICS } = require('../../../labscore/utils/statics')
|
||||||
|
|
||||||
|
@ -7,19 +7,38 @@ const { paginator } = require('../../../labscore/client');
|
||||||
const { google } = require('../../../labscore/api');
|
const { google } = require('../../../labscore/api');
|
||||||
|
|
||||||
function createSearchResultPage(context, result){
|
function createSearchResultPage(context, result){
|
||||||
let res = {
|
let res;
|
||||||
"embeds": [
|
switch(result.type){
|
||||||
createEmbed("default", context, {
|
case 1: // Search Result Entry
|
||||||
|
res = page(createEmbed("default", context, {
|
||||||
description: `**${link(result.url, result.title)}**\n${result.content}`,
|
description: `**${link(result.url, result.title)}**\n${result.content}`,
|
||||||
footer: {
|
footer: {
|
||||||
iconUrl: STATICS.google,
|
iconUrl: STATICS.google,
|
||||||
text: `Google • ${context.application.name}`
|
text: `Google • ${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;
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
@ -35,3 +35,14 @@ module.exports.iconPill = function(icon, content){
|
||||||
if(!ICONS[icon]) icon = "question"
|
if(!ICONS[icon]) icon = "question"
|
||||||
return ICONS[icon] + " **` " + content + " `**"
|
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