mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-10 07:03:08 -04:00
major cleanup
This commit is contained in:
parent
ddd918470e
commit
a8cf49e31e
60 changed files with 537 additions and 619 deletions
|
@ -8,38 +8,34 @@ const { citation } = require('../../../labscore/utils/markdown');
|
|||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
|
||||
function createWolframPage(context, pod, query, sources){
|
||||
let res = {
|
||||
"embeds": [
|
||||
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;
|
||||
|
||||
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){
|
||||
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 (src.url) res.embeds[0].description += citation(r, src.url, src.title)
|
||||
}
|
||||
}
|
||||
if(pod.image) res.embeds[0].image = { url: pod.image };
|
||||
if (pod.image) res.embeds[0].image = { url: pod.image };
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -57,26 +53,25 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||
try{
|
||||
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, {embeds:[createEmbed("warning", context, search.body.message)]})
|
||||
|
||||
if (search.body.status == 1) return editOrReply(context, createEmbed("warning", context, search.body.message))
|
||||
|
||||
let pages = []
|
||||
for(const res of search.body.data){
|
||||
for (const res of search.body.data) {
|
||||
pages.push(createWolframPage(context, res, args.query, search.body.sources))
|
||||
}
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform Wolfram|Alpha search.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform Wolfram|Alpha search.`))
|
||||
}
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue