mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-09 06:33:05 -04:00
perspective command v0
This commit is contained in:
parent
4242794942
commit
2b899daf16
4 changed files with 117 additions and 0 deletions
105
commands/message/mod/perspective.js
Normal file
105
commands/message/mod/perspective.js
Normal file
|
@ -0,0 +1,105 @@
|
|||
const { Constants } = require("detritus-client");
|
||||
const { perspective } = require("../../../labscore/api");
|
||||
const { format } = require("../../../labscore/utils/ansi");
|
||||
const { createEmbed } = require("../../../labscore/utils/embed");
|
||||
const Permissions = Constants.Permissions;
|
||||
|
||||
const { icon, pill, codeblock, iconPill, highlight } = require("../../../labscore/utils/markdown");
|
||||
const { editOrReply } = require("../../../labscore/utils/message");
|
||||
const { STATICS } = require("../../../labscore/utils/statics");
|
||||
const { getMember } = require("../../../labscore/utils/users");
|
||||
|
||||
|
||||
function getPerspectiveColor(score){
|
||||
if(score >= 0.8) return "r"
|
||||
if(score >= 0.3) return "y"
|
||||
return "g"
|
||||
}
|
||||
|
||||
function formatPerspectiveScores(data){
|
||||
let entries = [];
|
||||
let srt = [];
|
||||
let len = Math.max(...(Object.keys(data.scores).map(el => el.length))) + 3;
|
||||
|
||||
for(const scr of Object.keys(data.scores)){
|
||||
let score = data.scores[scr];
|
||||
perc = `${score.toString().substr(2,2)}.${score.toString().substr(3,1)}`
|
||||
if(perc.startsWith('0')) perc = ` ${perc.substr(1, perc.length)}`
|
||||
srt.push(`${data.scores[scr]}|${format(perc + '%', getPerspectiveColor(score))} ${scr.substr(0,1).toUpperCase()}${scr.substr(1,scr.length).toLowerCase().replace(/_/g, ' ')}`)
|
||||
}
|
||||
for(const i of srt.sort().reverse()) entries.push(i.split('|')[1])
|
||||
return entries
|
||||
}
|
||||
|
||||
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: {
|
||||
type: 'guild',
|
||||
limit: 1,
|
||||
duration: 5000
|
||||
},
|
||||
permissionsClient: [Permissions.MANAGE_MESSAGES],
|
||||
run: async (context, args) => {
|
||||
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 perspectiveApi = await perspective(context, [ args.input ])
|
||||
|
||||
return await editOrReply(context, { embeds: [createEmbed("default", context, {
|
||||
description: `${iconPill("rules", "Scores")} ${codeblock("ansi", formatPerspectiveScores(perspectiveApi.response.body))}`,
|
||||
footer: {
|
||||
iconUrl: STATICS.perspectiveapi,
|
||||
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)
|
||||
}
|
||||
}
|
||||
};
|
|
@ -50,6 +50,7 @@ const Api = Object.freeze({
|
|||
|
||||
UTILS_EMOJIPEDIA: '/utils/emojipedia',
|
||||
UTILS_INFERKIT: '/utils/inferkit',
|
||||
UTILS_PERSPECTIVE: '/utils/perspective',
|
||||
UTILS_SCREENSHOT: '/utils/screenshot',
|
||||
})
|
||||
|
||||
|
|
|
@ -287,6 +287,12 @@ module.exports.inferkit = async function(context, input){
|
|||
})
|
||||
}
|
||||
|
||||
module.exports.perspective = async function(context, content = []){
|
||||
return await request(Api.UTILS_PERSPECTIVE, "GET", {}, {
|
||||
input: content.join('\n\n')
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.screenshot = async function(context, url, nsfw){
|
||||
return await request(Api.UTILS_SCREENSHOT, "GET", {}, {
|
||||
url: url,
|
||||
|
|
|
@ -32,6 +32,10 @@ const Statics = Object.freeze({
|
|||
file: "brands/openweathermap.png",
|
||||
revision: 0
|
||||
},
|
||||
perspectiveapi: {
|
||||
file: "brands/perspectiveapi.png",
|
||||
revision: 0
|
||||
},
|
||||
photofunia: {
|
||||
file: "brands/photofunia.png",
|
||||
revision: 1
|
||||
|
@ -97,6 +101,7 @@ module.exports.STATICS = Object.freeze({
|
|||
inferkit: staticAsset(Statics.brands.inferkit),
|
||||
makesweet: staticAsset(Statics.brands.makesweet),
|
||||
openweathermap: staticAsset(Statics.brands.openweathermap),
|
||||
perspectiveapi: staticAsset(Statics.brands.perspectiveapi),
|
||||
photofunia: staticAsset(Statics.brands.photofunia),
|
||||
quora: staticAsset(Statics.brands.quora),
|
||||
reddit: staticAsset(Statics.brands.reddit),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue