new wolfram experience

This commit is contained in:
derpystuff 2023-03-02 23:28:35 +01:00
parent 2380ac41d8
commit 2c6387e7d9
2 changed files with 21 additions and 41 deletions

View file

@ -35,13 +35,10 @@ module.exports = {
label: "input",
name: "perspective",
metadata: {
// description: `Uses PerspectiveAPI to grade the toxicity of a prompt or user.`,
// description_short: 'Toxicity scores for prompts or users.',
description: `Uses Perspective to judge the toxicity of a prompt.`,
description_short: `Toxicity scores for prompts.`,
examples: ['perspective I hate otters.'],
category: 'mod',
// usage: 'perspective <user> OR perspective <prompt>'
usage: 'perspective <prompt>'
},
ratelimit: {
@ -54,10 +51,6 @@ module.exports = {
await context.triggerTyping();
try{
// The per-user scanning is coming soon ;)
// let u = await getMember(context, args.input)
// if(!u){ // Assume its a prompt
let msg = '';
if (context.message.messageReference) {
msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId)
@ -74,36 +67,6 @@ module.exports = {
text: `Perspective • ${context.application.name}`
}
})] })
// }
// let response = await editOrReply(context, { embeds: [createEmbed("loading", context, `Collecting messages...`)] })
// const messages = await context.message.channel.fetchMessages({limit: args.amount});
//
// await response.edit({ embeds: [createEmbed("loading", context, `Analyzing messages...`)] })
//
// let messageContent = [];
// for(const m of messages){
// // User limit
// if(m[1].author.id == u.id && m[1].content.length >= 1) messageContent.push(m[1].content)
// }
// console.log(messageContent)
// if(messageContent.length == 0){
// return await response.edit({ embeds: [createEmbed("warning", context, `No content found that could be analyzed.`)] })
// }
// let perspectiveApi = await perspective(context, messageContent)
// return await editOrReply(context, { embeds: [createEmbed("default", context, {
// description: `Analyzed ${iconPill("analytics", `${messageContent.length} Messages`)} by <@${u.id}>.\n\n${formatPerspectiveScores(perspectiveApi.response.body).join('\n')}`,
// footer: {
// iconUrl: STATICS.perspectiveapi,
// text: `Perspective • ${context.application.name}`
// }
// })] })
}catch(e){
await editOrReply(context, { embeds: [createEmbed("error", context, `Something went wrong.`)] })
console.log(e)

View file

@ -4,12 +4,23 @@ const { STATICS } = require('../../../labscore/utils/statics')
const { paginator } = require('../../../labscore/client');
const { wolframAlpha } = require('../../../labscore/api');
const { citation } = require('../../../labscore/utils/markdown');
function createWolframPage(context, pod){
function getWolframSource(ref, sources){
for(const s of Object.values(sources)){
if(s.ref == ref) return s
}
}
function createWolframPage(context, pod, query, sources){
let res = {
"embeds": [
createEmbed("default", context, {
description: `**${pod.title}**`,
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}`
@ -17,7 +28,13 @@ function createWolframPage(context, pod){
})
]
}
if(pod.value) res.embeds[0].description = res.embeds[0].description + `\n${pod.value}`
if(pod.value) res.embeds[0].description = pod.value
if(pod.value && pod.refs) {
for(const r of pod.refs){
let src = getWolframSource(r, sources)
res.embeds[0].description += citation(r, src.url, src.title)
}
}
if(pod.image) res.embeds[0].image = { url: pod.image };
return res;
}
@ -44,7 +61,7 @@ module.exports = {
let pages = []
for(const res of search.body.data){
pages.push(createWolframPage(context, res))
pages.push(createWolframPage(context, res, args.query, search.body.sources))
}
pages = formatPaginationEmbeds(pages)