mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Combine percent-diff and text-diff
This commit is contained in:
@@ -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)}%`);
|
||||
}
|
||||
};
|
||||
@@ -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)`);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user