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}%`);
}
};
+2 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "139.3.0",
"version": "139.4.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"private": true,
@@ -64,6 +64,7 @@
"jszip": "^3.6.0",
"kuroshiro": "^1.1.2",
"kuroshiro-analyzer-kuromoji": "^1.1.0",
"leven": "^3.1.0",
"mathjs": "^9.3.2",
"moment": "^2.29.1",
"moment-duration-format": "^2.3.2",