mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 22:23:03 -04:00
bing knowledge graph
This commit is contained in:
parent
6ef4cf40c9
commit
5e67ab43af
1 changed files with 42 additions and 7 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, citation } = require('../../../labscore/utils/markdown')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
const { STATICS } = require('../../../labscore/utils/statics')
|
||||
|
||||
|
@ -7,17 +7,52 @@ const { paginator } = require('../../../labscore/client');
|
|||
const { bing } = require('../../../labscore/api');
|
||||
|
||||
function createSearchResultPage(context, result){
|
||||
let res = {
|
||||
"embeds": [
|
||||
createEmbed("default", context, {
|
||||
let res;
|
||||
switch(result.type){
|
||||
case 1:
|
||||
res = page(createEmbed("default", context, {
|
||||
description: `**${link(result.url, result.title)}**\n${result.snippet}`,
|
||||
footer: {
|
||||
iconUrl: STATICS.bing,
|
||||
text: `Microsoft Bing • ${context.application.name}`
|
||||
}
|
||||
})
|
||||
]
|
||||
}))
|
||||
break;
|
||||
case 2:
|
||||
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\n${result.card.description}`,
|
||||
fields: [],
|
||||
footer: {
|
||||
iconUrl: STATICS.bing,
|
||||
text: `Microsoft Bing Knowledge Graph • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
if(result.card.sources.description) res.embeds[0].description += citation(1, result.card.sources.description.url, `Source: ${result.card.sources.description.title}`)
|
||||
if(result.card.image) res.embeds[0].thumbnail = { url: result.card.image }
|
||||
if(result.card.fields){
|
||||
// only up to 6 fields
|
||||
for(const f of result.card.fields.splice(0, 6)){
|
||||
if(f.url){
|
||||
res.embeds[0].fields.push({
|
||||
name: f.title,
|
||||
value: f.value,
|
||||
inline: true
|
||||
})
|
||||
continue;
|
||||
}
|
||||
res.embeds[0].fields.push({
|
||||
name: f.title,
|
||||
value: f.value,
|
||||
inline: true
|
||||
})
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(result.image) res.embeds[0].thumbnail = { url: result.image }
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue