mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-09 06:33:05 -04:00
rm
This commit is contained in:
parent
93c7599b15
commit
71384124e6
4 changed files with 0 additions and 377 deletions
|
@ -1,139 +0,0 @@
|
|||
const { Constants } = require('detritus-client');
|
||||
const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = Constants;
|
||||
|
||||
const { createEmbed, page, formatPaginationEmbeds } = require('../../../../labscore/utils/embed');
|
||||
|
||||
const { paginator } = require('../../../../labscore/client');
|
||||
const { STATICS } = require('../../../../labscore/utils/statics');
|
||||
const { bing } = require('../../../../labscore/api');
|
||||
const { link, citation, codeblock } = require('../../../../labscore/utils/markdown');
|
||||
const { editOrReply } = require('../../../../labscore/utils/message');
|
||||
|
||||
|
||||
|
||||
function createSearchResultPage(context, entry){
|
||||
let res;
|
||||
switch(entry.type){
|
||||
case 1: // WebPage
|
||||
res = page(createEmbed("default", context, {
|
||||
author: {
|
||||
iconUrl: `https://www.google.com/s2/favicons?domain=${encodeURIComponent(entry.result.url)}&sz=256`,
|
||||
name: entry.result.title,
|
||||
url: entry.result.url
|
||||
},
|
||||
fields: [],
|
||||
description: `${entry.result.snippet}`,
|
||||
footer: {
|
||||
iconUrl: STATICS.bing,
|
||||
text: `Microsoft Bing • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
if(entry.result.image) res.embeds[0].thumbnail = { url: entry.result.image }
|
||||
if(entry.result.deepLinks) {
|
||||
let fl = entry.result.deepLinks;
|
||||
while(fl.length >= 1){
|
||||
fields = fl.splice(0, 4)
|
||||
fields = fields.map((f)=>link(f.url, f.title))
|
||||
res.embeds[0].fields.push({
|
||||
name: "",
|
||||
value: fields.join('\n'),
|
||||
inline: true
|
||||
})
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2: // Entity
|
||||
res = page(createEmbed("default", context, {
|
||||
author: {
|
||||
name: entry.result.title,
|
||||
url: entry.result.url
|
||||
},
|
||||
description: `${entry.result.description}`,
|
||||
fields: [],
|
||||
footer: {
|
||||
iconUrl: STATICS.bing,
|
||||
text: `Microsoft Bing • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
if(entry.result.sources.description) res.embeds[0].description += citation(1, entry.result.sources.description.url, `Source: ${entry.result.sources.description.title}`)
|
||||
if(entry.result.image) res.embeds[0].thumbnail = { url: entry.result.image }
|
||||
if(entry.result.fields){
|
||||
// only up to 6 fields
|
||||
for(const f of entry.result.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;
|
||||
case 6: // Computation
|
||||
res = page(createEmbed("default", context, {
|
||||
author: {
|
||||
iconUrl: `https://www.google.com/s2/favicons?domain=${encodeURIComponent("bing.com")}&sz=256`,
|
||||
name: entry.result.expression
|
||||
},
|
||||
description: `${codeblock("python", [entry.result.value])}`,
|
||||
fields: [],
|
||||
footer: {
|
||||
iconUrl: STATICS.bing,
|
||||
text: `Microsoft Bing • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
module.exports = {
|
||||
description: 'Search on Bing.',
|
||||
name: 'bing',
|
||||
options: [
|
||||
{
|
||||
name: 'query',
|
||||
description: 'Search query',
|
||||
type: ApplicationCommandOptionTypes.STRING,
|
||||
required: true
|
||||
}
|
||||
],
|
||||
run: async (context, args) => {
|
||||
await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE})
|
||||
|
||||
try{
|
||||
let search = await bing(context, args.query, context.channel.nsfw)
|
||||
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){
|
||||
let sp = createSearchResultPage(context, res)
|
||||
if(sp) pages.push(sp)
|
||||
}
|
||||
|
||||
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 bing search.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,66 +0,0 @@
|
|||
const { Constants } = require('detritus-client');
|
||||
const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = Constants;
|
||||
|
||||
const { createEmbed, page, formatPaginationEmbeds } = require('../../../../labscore/utils/embed');
|
||||
|
||||
const { paginator } = require('../../../../labscore/client');
|
||||
const { STATICS } = require('../../../../labscore/utils/statics');
|
||||
const { google, googleImages } = require('../../../../labscore/api');
|
||||
const { editOrReply } = require('../../../../labscore/utils/message');
|
||||
|
||||
function createImageResultPage(context, result) {
|
||||
let res = page(createEmbed("default", context, {
|
||||
author: {
|
||||
iconUrl: `https://www.google.com/s2/favicons?domain=${encodeURIComponent(result.url)}&sz=256`,
|
||||
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 = {
|
||||
description: 'Search on Google Images.',
|
||||
name: 'google-images',
|
||||
options: [
|
||||
{
|
||||
name: 'query',
|
||||
description: 'Search query',
|
||||
type: ApplicationCommandOptionTypes.STRING,
|
||||
required: true
|
||||
}
|
||||
],
|
||||
run: async (context, args) => {
|
||||
await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE})
|
||||
|
||||
try {
|
||||
let search = await googleImages(context, args.query, context.channel.nsfw)
|
||||
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.`))
|
||||
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform google search.`))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -1,96 +0,0 @@
|
|||
const { Constants } = require('detritus-client');
|
||||
const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = Constants;
|
||||
|
||||
const { createEmbed, page, formatPaginationEmbeds } = require('../../../../labscore/utils/embed');
|
||||
|
||||
const { paginator } = require('../../../../labscore/client');
|
||||
const { STATICS } = require('../../../../labscore/utils/statics');
|
||||
const { google } = require('../../../../labscore/api');
|
||||
const { link, citation } = require('../../../../labscore/utils/markdown');
|
||||
const { editOrReply } = require('../../../../labscore/utils/message');
|
||||
|
||||
|
||||
function createSearchResultPage(context, result){
|
||||
let res;
|
||||
switch(result.type){
|
||||
case 1: // Search Result Entry
|
||||
res = page(createEmbed("default", context, {
|
||||
author: {
|
||||
iconUrl: `https://www.google.com/s2/favicons?domain=${encodeURIComponent(result.url)}&sz=256`,
|
||||
name: result.title,
|
||||
url: result.url
|
||||
},
|
||||
description: result.content,
|
||||
footer: {
|
||||
iconUrl: STATICS.google,
|
||||
text: `Google • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
|
||||
if(result.thumbnail) res.embeds[0].thumbnail = { url: result.thumbnail };
|
||||
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`,
|
||||
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.description) res.embeds[0].description += `*${result.card.description}*\n`
|
||||
if(result.card.content){
|
||||
let cnt = result.card.content.replace(/\n/g, '')
|
||||
if(cnt.endsWith(" ")) cnt = cnt.substr(0,cnt.length - 1)
|
||||
res.embeds[0].description += "\n" + cnt + citation(1, result.card.url, "Source")
|
||||
}
|
||||
break;
|
||||
default:
|
||||
res = page(createEmbed("error", context, "Unknown GoogleResult Type: " + result.type))
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
description: 'Search on Google.',
|
||||
name: 'google',
|
||||
options: [
|
||||
{
|
||||
name: 'query',
|
||||
description: 'Search query',
|
||||
type: ApplicationCommandOptionTypes.STRING,
|
||||
required: true
|
||||
}
|
||||
],
|
||||
run: async (context, args) => {
|
||||
await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE})
|
||||
|
||||
if(!args.query) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (query).`))
|
||||
try{
|
||||
let search = await google(context, args.query, context.channel.nsfw)
|
||||
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(createSearchResultPage(context, res))
|
||||
}
|
||||
|
||||
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.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,76 +0,0 @@
|
|||
const { createEmbed, formatPaginationEmbeds, page } = require('../../../../labscore/utils/embed')
|
||||
const { editOrReply } = require('../../../../labscore/utils/message')
|
||||
const { STATICS } = require('../../../../labscore/utils/statics')
|
||||
|
||||
const { paginator } = require('../../../../labscore/client');
|
||||
const { wolframAlpha } = require('../../../../labscore/api');
|
||||
const { citation } = require('../../../../labscore/utils/markdown');
|
||||
const { ApplicationCommandTypes, InteractionCallbackTypes } = require('detritus-client/lib/constants');
|
||||
|
||||
function createWolframPage(context, pod, query, sources) {
|
||||
let res = page(createEmbed("default", context, {
|
||||
author: {
|
||||
name: pod.title,
|
||||
url: `https://www.wolframalpha.com/input?i=${encodeURIComponent(query)}`
|
||||
},
|
||||
description: undefined,
|
||||
footer: {
|
||||
iconUrl: STATICS.wolframalpha,
|
||||
text: `Wolfram|Alpha • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
if (pod.icon) res.embeds[0].author.iconUrl = pod.icon
|
||||
if (pod.value) res.embeds[0].description = pod.value.substr(0, 1000)
|
||||
if (pod.value && pod.refs) {
|
||||
for (const r of pod.refs) {
|
||||
let src = Object.values(sources).filter((s) => s.ref == r)[0]
|
||||
if (!src) continue;
|
||||
|
||||
// Only add a direct source if one is available
|
||||
if (src.collections) {
|
||||
res.embeds[0].description += citation(r, src.url, src.title + ' | ' + src.collections[0].text)
|
||||
continue;
|
||||
}
|
||||
if (src.url) res.embeds[0].description += citation(r, src.url, src.title)
|
||||
}
|
||||
}
|
||||
if (pod.image) res.embeds[0].image = { url: pod.image };
|
||||
return res;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
description: 'Compute with Wolfram|Alpha.',
|
||||
name: 'wolfram-alpha',
|
||||
options: [
|
||||
{
|
||||
name: 'query',
|
||||
description: 'Computational query',
|
||||
type: ApplicationCommandTypes.STRING,
|
||||
required: true
|
||||
}
|
||||
],
|
||||
run: async (context, args) => {
|
||||
await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE})
|
||||
|
||||
if (!args.query) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (query).`))
|
||||
try {
|
||||
let search = await wolframAlpha(context, args.query)
|
||||
search = search.response
|
||||
|
||||
if (search.body.status == 1) return editOrReply(context, createEmbed("warning", context, search.body.message))
|
||||
|
||||
let pages = []
|
||||
for (const res of search.body.data) {
|
||||
pages.push(createWolframPage(context, res, args.query, search.body.sources))
|
||||
}
|
||||
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform Wolfram|Alpha search.`))
|
||||
}
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue