diff --git a/commands/analyze/levenshtein.js b/commands/analyze/levenshtein.js index b52be2d8..6c51ce21 100644 --- a/commands/analyze/levenshtein.js +++ b/commands/analyze/levenshtein.js @@ -26,6 +26,6 @@ module.exports = class LevenshteinCommand extends Command { run(msg, { text1, text2 }) { const distance = wuzzy.levenshtein(text1, text2); - return msg.reply(distance); + return msg.reply(distance.toString()); } }; diff --git a/commands/analyze/severe-toxicity.js b/commands/analyze/severe-toxicity.js deleted file mode 100644 index d2ce25ac..00000000 --- a/commands/analyze/severe-toxicity.js +++ /dev/null @@ -1,50 +0,0 @@ -const Command = require('../../framework/Command'); -const request = require('node-superfetch'); -const { Message } = require('discord.js'); -const { GOOGLE_KEY } = process.env; - -module.exports = class SevereToxicityCommand extends Command { - constructor(client) { - super(client, { - name: 'severe-toxicity', - aliases: ['severe-perspective', 'severe-comment-toxicity', 'severe-toxic'], - group: 'analyze', - memberName: 'severe-toxicity', - description: 'Determines the toxicity of text, but less sensitive to milder language.', - credit: [ - { - name: 'Perspective API', - url: 'https://www.perspectiveapi.com/#/', - reason: 'API' - } - ], - args: [ - { - key: 'text', - prompt: 'What text do you want to test the toxicity of?', - type: 'message|string' - } - ] - }); - } - - async run(msg, { text }) { - if (text instanceof Message) text = text.content; - try { - const { body } = await request - .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.reply(`Likely to be perceived as toxic. (${toxicity}%)`); - if (toxicity >= 40) return msg.reply(`Unsure if this will be perceived as toxic. (${toxicity}%)`); - return msg.reply(`Unlikely to be perceived as toxic. (${toxicity}%)`); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } - } -}; diff --git a/commands/analyze/toxicity.js b/commands/analyze/toxicity.js index 2c2a57d2..b9cbdcb0 100644 --- a/commands/analyze/toxicity.js +++ b/commands/analyze/toxicity.js @@ -11,6 +11,12 @@ module.exports = class ToxicityCommand extends Command { group: 'analyze', memberName: 'toxicity', description: 'Determines the toxicity of text.', + flags: [ + { + key: 'severe', + description: 'Makes the check much less vulnerable to basic swearing.' + } + ], credit: [ { name: 'Perspective API', @@ -28,7 +34,7 @@ module.exports = class ToxicityCommand extends Command { }); } - async run(msg, { text }) { + async run(msg, { text, flags: { severe } }) { if (text instanceof Message) text = text.content; try { const { body } = await request @@ -37,9 +43,10 @@ module.exports = class ToxicityCommand extends Command { .send({ comment: { text }, languages: ['en'], - requestedAttributes: { TOXICITY: {} } + requestedAttributes: severe ? { SEVERE_TOXICITY: {} } : { TOXICITY: {} } }); - const toxicity = Math.round(body.attributeScores.TOXICITY.summaryScore.value * 100); + const score = severe ? body.body.attributeScores.SEVERE_TOXICITY : body.attributeScores.TOXICITY; + const toxicity = Math.round(score.summaryScore.value * 100); if (toxicity >= 70) return msg.reply(`Likely to be perceived as toxic. (${toxicity}%)`); if (toxicity >= 40) return msg.reply(`Unsure if this will be perceived as toxic. (${toxicity}%)`); return msg.reply(`Unlikely to be perceived as toxic. (${toxicity}%)`); diff --git a/commands/util-public/help.js b/commands/util-public/help.js index 0167a82a..08f107ec 100644 --- a/commands/util-public/help.js +++ b/commands/util-public/help.js @@ -76,6 +76,9 @@ module.exports = class HelpCommand extends Command { __Command **${command.name}**__${command.guildOnly ? ' (Usable only in servers)' : ''} ${command.description}${command.details ? `\n${command.details}` : ''} + **Flags:** + ${command.flags.length ? command.flags.map(flag => `--${flag.key} (${flag.description})`).join('\n') : 'None'} + **Format:** ${command.usage(command.format || '')} **Aliases:** ${command.aliases.join(', ') || 'None'} **Group:** ${command.group.name} (\`${command.groupID}:${command.memberName}\`) diff --git a/framework/Command.js b/framework/Command.js index 03d3bdc6..5e0f5286 100644 --- a/framework/Command.js +++ b/framework/Command.js @@ -10,6 +10,7 @@ module.exports = class Command { this.memberName = options.memberName.toLowerCase(); this.description = options.description; this.details = options.details || null; + this.flags = options.flags || []; this.args = options.args ? options.args.map(arg => new Argument(client, arg)) : []; this.clientPermissions = options.clientPermissions || []; this.userPermissions = options.userPermissions || [];