Leven Commands

This commit is contained in:
Dragon Fire
2021-05-10 19:40:42 -04:00
parent a0f63a23cb
commit de532e9440
3 changed files with 66 additions and 1 deletions
+31
View File
@@ -0,0 +1,31 @@
const Command = require('../../structures/Command');
const leven = require('leven');
module.exports = class LevenshteinCommand extends Command {
constructor(client) {
super(client, {
name: 'levenshtein',
aliases: ['leven'],
group: 'analyze',
memberName: 'levenshtein',
description: 'Determines the levenshtein distance 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 distance = leven(text1, text2);
return msg.reply(distance);
}
};
+33
View File
@@ -0,0 +1,33 @@
const Command = require('../../structures/Command');
const leven = require('leven');
module.exports = class PercentDiffCommand extends Command {
constructor(client) {
super(client, {
name: 'percent-diff',
aliases: ['name-diff', 'leven-diff', 'levenshtein-diff'],
group: 'analyze',
memberName: 'percent-diff',
description: 'Determines the percentage 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 distance = leven(text1, text2);
const bigger = Math.max(text1.length, text2.length);
const diff = Math.round(((bigger - distance) / bigger) * 100);
return msg.reply(`${diff}%`);
}
};