mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-18 21:40:49 +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 Command = require('../../framework/Command');
|
||||||
const Diff = require('text-diff');
|
const Diff = require('text-diff');
|
||||||
|
const wuzzy = require('wuzzy');
|
||||||
|
|
||||||
module.exports = class TextDiffCommand extends Command {
|
module.exports = class TextDiffCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: 'text-diff',
|
name: 'text-diff',
|
||||||
aliases: ['diff'],
|
aliases: ['diff', 'percent-diff', 'name-diff'],
|
||||||
group: 'analyze',
|
group: 'analyze',
|
||||||
memberName: 'text-diff',
|
memberName: 'text-diff',
|
||||||
description: 'Compares two different bits of text.',
|
description: 'Compares two different bits of text.',
|
||||||
@@ -27,6 +28,7 @@ module.exports = class TextDiffCommand extends Command {
|
|||||||
run(msg, { text1, text2 }) {
|
run(msg, { text1, text2 }) {
|
||||||
const diff = new Diff();
|
const diff = new Diff();
|
||||||
const textDiff = diff.main(text1, text2);
|
const textDiff = diff.main(text1, text2);
|
||||||
|
const wuzzyDiff = wuzzy.jaccard(text1.toLowerCase(), text2.toLowerCase());
|
||||||
diff.cleanupSemantic(textDiff);
|
diff.cleanupSemantic(textDiff);
|
||||||
const formatted = textDiff.map(change => {
|
const formatted = textDiff.map(change => {
|
||||||
if (change[0] === 1) return `**${change[1]}**`;
|
if (change[0] === 1) return `**${change[1]}**`;
|
||||||
@@ -34,6 +36,6 @@ module.exports = class TextDiffCommand extends Command {
|
|||||||
if (change[0] === -1) return `~~${change[1]}~~`;
|
if (change[0] === -1) return `~~${change[1]}~~`;
|
||||||
return '';
|
return '';
|
||||||
}).join('');
|
}).join('');
|
||||||
return msg.reply(formatted);
|
return msg.reply(`${formatted} (${Math.round(diff * 100)}% similarity)`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user