mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-09 06:33:05 -04:00
improve analyze
This commit is contained in:
parent
3f776872f0
commit
a5f13d6c70
1 changed files with 19 additions and 11 deletions
|
@ -4,7 +4,7 @@ const { PERMISSION_GROUPS } = require("#constants");
|
|||
const { format } = require("#utils/ansi");
|
||||
const { createEmbed } = require("#utils/embed");
|
||||
const { acknowledge } = require("#utils/interactions");
|
||||
const { icon, codeblock, iconPill, smallPill, stringwrap } = require("#utils/markdown");
|
||||
const { codeblock, iconPill, smallPill, stringwrap } = require("#utils/markdown");
|
||||
const { editOrReply } = require("#utils/message");
|
||||
const { STATICS } = require("#utils/statics");
|
||||
|
||||
|
@ -45,7 +45,7 @@ function perspectiveAnalysisEmbed(context, payload, input, type){
|
|||
let score = payload.scores[type];
|
||||
return createEmbed("default", context, {
|
||||
// the 1000 chars length limit is stupid, blame discord
|
||||
description: `${iconPill("agreements", `${type.substr(0, 1).toUpperCase()}${type.substr(1, type.length).toLowerCase().replace(/_/g, ' ')}`)} ${smallPill(`${score.toString().substr(2, 2)}.${score.toString().substr(3, 1)}%`)} ${codeblock("ansi", [stringwrap(renderPerspectiveAnalysis(payload,input,type), 1000)])}`,
|
||||
description: `${iconPill("agreements", `${type.substr(0, 1).toUpperCase()}${type.substr(1, type.length).toLowerCase().replace(/_/g, ' ')}`)} ${smallPill(`${(score * 100).toFixed(2)}%`)} ${codeblock("ansi", [stringwrap(renderPerspectiveAnalysis(payload,input,type), 1000)])}`,
|
||||
footer: {
|
||||
iconUrl: STATICS.perspectiveapi,
|
||||
text: `Perspective • ${context.application.name}`
|
||||
|
@ -68,16 +68,14 @@ module.exports = {
|
|||
await acknowledge(context);
|
||||
|
||||
try {
|
||||
let msg = '';
|
||||
if (context.message.messageReference) {
|
||||
msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId)
|
||||
let msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId)
|
||||
args.input = msg.content
|
||||
msg = `${icon("robot")} <@${msg.author.id}> (${msg.author.id})\n${codeblock("ansi", [msg.content])}\n`
|
||||
}
|
||||
|
||||
let perspectiveApi = await perspective(context, [args.input])
|
||||
|
||||
let currentView = perspectiveAnalysisEmbed(context, perspectiveApi.response.body, args.input, Object.keys(perspectiveApi.response.body.annotations)[0]);
|
||||
let currentView;
|
||||
|
||||
const components = new Components({
|
||||
timeout: 100000,
|
||||
|
@ -86,7 +84,7 @@ module.exports = {
|
|||
|
||||
// this sucks but works, ensures the newly selected option stays selected
|
||||
for (let i = 0; i < components.components[0].components[0].options.length; i++) {
|
||||
components.components[0].components[0].options[i].default = (components.components[0].components[0].options[i].value == ctx.data.values[0])
|
||||
components.components[0].components[0].options[i].default = (components.components[0].components[0].options[i].value === ctx.data.values[0])
|
||||
}
|
||||
|
||||
currentView = perspectiveAnalysisEmbed(context, perspectiveApi.response.body, args.input, ctx.data.values[0])
|
||||
|
@ -94,11 +92,18 @@ module.exports = {
|
|||
},
|
||||
});
|
||||
|
||||
let selectOptions = Object.keys(perspectiveApi.response.body.annotations).map((r) => {
|
||||
let options = Object.keys(perspectiveApi.response.body.annotations).map((r)=>{
|
||||
return {
|
||||
label: `${r.substr(0, 1).toUpperCase()}${r.substr(1, r.length).toLowerCase().replace(/_/g, ' ')}`,
|
||||
value: r,
|
||||
default: (r == Object.keys(perspectiveApi.response.body.annotations)[0])
|
||||
k: r,
|
||||
v: perspectiveApi.response.body.scores[r]
|
||||
};
|
||||
}).sort((a,b)=>b.v - a.v);
|
||||
|
||||
let selectOptions = options.map(({k, v}) => {
|
||||
return {
|
||||
label: `${(v * 100).toFixed(2)}% • ${k.substr(0, 1).toUpperCase()}${k.substr(1, k.length).toLowerCase().replace(/_/g, ' ')}`,
|
||||
value: k,
|
||||
default: (k === options[0].k)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -109,6 +114,9 @@ module.exports = {
|
|||
options: selectOptions
|
||||
})
|
||||
|
||||
currentView = perspectiveAnalysisEmbed(context, perspectiveApi.response.body, args.input, options[0].k);
|
||||
|
||||
|
||||
setTimeout(()=>{
|
||||
editOrReply(context, {
|
||||
embeds:[currentView],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue