Combine percent-diff and text-diff

This commit is contained in:
Dragon Fire
2024-03-20 18:53:25 -04:00
parent 5186dd129c
commit c6150d20ed
2 changed files with 4 additions and 33 deletions
-31
View File
@@ -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)}%`);
}
};
+4 -2
View File
@@ -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)`);
}
};