From 2c6387e7d987700c72f7b234b6b9393e65192d29 Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Thu, 2 Mar 2023 23:28:35 +0100 Subject: [PATCH] new wolfram experience --- commands/message/mod/perspective.js | 37 ------------------------ commands/message/search/wolfram-alpha.js | 25 +++++++++++++--- 2 files changed, 21 insertions(+), 41 deletions(-) diff --git a/commands/message/mod/perspective.js b/commands/message/mod/perspective.js index b18343e..9a1b179 100644 --- a/commands/message/mod/perspective.js +++ b/commands/message/mod/perspective.js @@ -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 OR perspective ' usage: 'perspective ' }, 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) diff --git a/commands/message/search/wolfram-alpha.js b/commands/message/search/wolfram-alpha.js index d6dbbbe..34d6f17 100644 --- a/commands/message/search/wolfram-alpha.js +++ b/commands/message/search/wolfram-alpha.js @@ -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)