From c6150d20ed0f0bfb6566e3f4c9f412b8024a57bc Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Wed, 20 Mar 2024 18:53:25 -0400 Subject: [PATCH] Combine percent-diff and text-diff --- commands/analyze/percent-diff.js | 31 ------------------------------- commands/analyze/text-diff.js | 6 ++++-- 2 files changed, 4 insertions(+), 33 deletions(-) delete mode 100644 commands/analyze/percent-diff.js diff --git a/commands/analyze/percent-diff.js b/commands/analyze/percent-diff.js deleted file mode 100644 index 699d202e..00000000 --- a/commands/analyze/percent-diff.js +++ /dev/null @@ -1,31 +0,0 @@ -const Command = require('../../framework/Command'); -const wuzzy = require('wuzzy'); - -module.exports = class PercentDiffCommand extends Command { - constructor(client) { - super(client, { - name: 'percent-diff', - aliases: ['name-diff'], - group: 'analyze', - memberName: 'percent-diff', - description: 'Determines the percentage of difference between two strings.', - args: [ - { - key: 'text1', - prompt: 'What is the first text you would like to compare?', - type: 'string' - }, - { - key: 'text2', - prompt: 'What is the second text you would like to compare?', - type: 'string' - } - ] - }); - } - - run(msg, { text1, text2 }) { - const diff = wuzzy.jaccard(text1.toLowerCase(), text2.toLowerCase()); - return msg.reply(`${Math.round(diff * 100)}%`); - } -}; diff --git a/commands/analyze/text-diff.js b/commands/analyze/text-diff.js index 3c37519a..5c8c8d89 100644 --- a/commands/analyze/text-diff.js +++ b/commands/analyze/text-diff.js @@ -1,11 +1,12 @@ const Command = require('../../framework/Command'); const Diff = require('text-diff'); +const wuzzy = require('wuzzy'); module.exports = class TextDiffCommand extends Command { constructor(client) { super(client, { name: 'text-diff', - aliases: ['diff'], + aliases: ['diff', 'percent-diff', 'name-diff'], group: 'analyze', memberName: 'text-diff', description: 'Compares two different bits of text.', @@ -27,6 +28,7 @@ module.exports = class TextDiffCommand extends Command { run(msg, { text1, text2 }) { const diff = new Diff(); const textDiff = diff.main(text1, text2); + const wuzzyDiff = wuzzy.jaccard(text1.toLowerCase(), text2.toLowerCase()); diff.cleanupSemantic(textDiff); const formatted = textDiff.map(change => { if (change[0] === 1) return `**${change[1]}**`; @@ -34,6 +36,6 @@ module.exports = class TextDiffCommand extends Command { if (change[0] === -1) return `~~${change[1]}~~`; return ''; }).join(''); - return msg.reply(formatted); + return msg.reply(`${formatted} (${Math.round(diff * 100)}% similarity)`); } };