mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 06:03:04 -04:00
new wolfram experience
This commit is contained in:
parent
2380ac41d8
commit
2c6387e7d9
2 changed files with 21 additions and 41 deletions
|
@ -35,13 +35,10 @@ module.exports = {
|
||||||
label: "input",
|
label: "input",
|
||||||
name: "perspective",
|
name: "perspective",
|
||||||
metadata: {
|
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: `Uses Perspective to judge the toxicity of a prompt.`,
|
||||||
description_short: `Toxicity scores for prompts.`,
|
description_short: `Toxicity scores for prompts.`,
|
||||||
examples: ['perspective I hate otters.'],
|
examples: ['perspective I hate otters.'],
|
||||||
category: 'mod',
|
category: 'mod',
|
||||||
// usage: 'perspective <user> OR perspective <prompt>'
|
|
||||||
usage: 'perspective <prompt>'
|
usage: 'perspective <prompt>'
|
||||||
},
|
},
|
||||||
ratelimit: {
|
ratelimit: {
|
||||||
|
@ -54,10 +51,6 @@ module.exports = {
|
||||||
await context.triggerTyping();
|
await context.triggerTyping();
|
||||||
|
|
||||||
try{
|
try{
|
||||||
// The per-user scanning is coming soon ;)
|
|
||||||
|
|
||||||
// let u = await getMember(context, args.input)
|
|
||||||
// if(!u){ // Assume its a prompt
|
|
||||||
let msg = '';
|
let msg = '';
|
||||||
if (context.message.messageReference) {
|
if (context.message.messageReference) {
|
||||||
msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId)
|
msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId)
|
||||||
|
@ -74,36 +67,6 @@ module.exports = {
|
||||||
text: `Perspective • ${context.application.name}`
|
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){
|
}catch(e){
|
||||||
await editOrReply(context, { embeds: [createEmbed("error", context, `Something went wrong.`)] })
|
await editOrReply(context, { embeds: [createEmbed("error", context, `Something went wrong.`)] })
|
||||||
console.log(e)
|
console.log(e)
|
||||||
|
|
|
@ -4,12 +4,23 @@ const { STATICS } = require('../../../labscore/utils/statics')
|
||||||
|
|
||||||
const { paginator } = require('../../../labscore/client');
|
const { paginator } = require('../../../labscore/client');
|
||||||
const { wolframAlpha } = require('../../../labscore/api');
|
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 = {
|
let res = {
|
||||||
"embeds": [
|
"embeds": [
|
||||||
createEmbed("default", context, {
|
createEmbed("default", context, {
|
||||||
description: `**${pod.title}**`,
|
author: {
|
||||||
|
name: pod.title,
|
||||||
|
url: `https://www.wolframalpha.com/input?i=${encodeURIComponent(query)}`
|
||||||
|
},
|
||||||
|
description: undefined,
|
||||||
footer: {
|
footer: {
|
||||||
iconUrl: STATICS.wolframalpha,
|
iconUrl: STATICS.wolframalpha,
|
||||||
text: `Wolfram|Alpha • ${context.application.name}`
|
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 };
|
if(pod.image) res.embeds[0].image = { url: pod.image };
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +61,7 @@ module.exports = {
|
||||||
|
|
||||||
let pages = []
|
let pages = []
|
||||||
for(const res of search.body.data){
|
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)
|
pages = formatPaginationEmbeds(pages)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue