mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-19 13:56:43 +02:00
Severe Toxicity
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
const { Command } = require('discord.js-commando');
|
||||||
|
const snekfetch = require('snekfetch');
|
||||||
|
const { GOOGLE_KEY } = process.env;
|
||||||
|
|
||||||
|
module.exports = class SevereToxicityCommand extends Command {
|
||||||
|
constructor(client) {
|
||||||
|
super(client, {
|
||||||
|
name: 'severe-toxicity',
|
||||||
|
aliases: ['severe-perspective', 'severe-comment-toxicity'],
|
||||||
|
group: 'other',
|
||||||
|
memberName: 'severe-toxicity',
|
||||||
|
description: 'Determines the toxicity of text, but less sensitive to milder language.',
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
key: 'text',
|
||||||
|
prompt: 'What text do you want to test the toxicity of?',
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(msg, { text }) {
|
||||||
|
try {
|
||||||
|
const { body } = await snekfetch
|
||||||
|
.post('https://commentanalyzer.googleapis.com/v1alpha1/comments:analyze')
|
||||||
|
.query({ key: GOOGLE_KEY })
|
||||||
|
.send({
|
||||||
|
comment: { text },
|
||||||
|
languages: ['en'],
|
||||||
|
requestedAttributes: { SEVERE_TOXICITY: {} }
|
||||||
|
});
|
||||||
|
const toxicity = Math.round(body.attributeScores.SEVERE_TOXICITY.summaryScore.value * 100);
|
||||||
|
if (toxicity >= 70) return msg.say(`Likely to be perceived as toxic. (${toxicity}%)`);
|
||||||
|
if (toxicity >= 40) return msg.say(`Unsure if this will be perceived as toxic. (${toxicity}%)`);
|
||||||
|
return msg.say(`Unlikely to be perceived as toxic. (${toxicity}%)`);
|
||||||
|
} catch (err) {
|
||||||
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "66.6.1",
|
"version": "66.7.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user