Use string-similarity

This commit is contained in:
Dragon Fire
2021-05-14 16:36:14 -04:00
parent fd84f0e985
commit 952a27d67d
2 changed files with 6 additions and 7 deletions
+5 -7
View File
@@ -1,14 +1,14 @@
const Command = require('../../structures/Command'); const Command = require('../../structures/Command');
const leven = require('leven'); const stringSimilarity = require('string-similarity');
module.exports = class PercentDiffCommand extends Command { module.exports = class PercentDiffCommand extends Command {
constructor(client) { constructor(client) {
super(client, { super(client, {
name: 'percent-diff', name: 'percent-diff',
aliases: ['name-diff', 'leven-diff', 'levenshtein-diff'], aliases: ['name-diff'],
group: 'analyze', group: 'analyze',
memberName: 'percent-diff', memberName: 'percent-diff',
description: 'Determines the percentage between two strings.', description: 'Determines the percentage of difference between two strings.',
args: [ args: [
{ {
key: 'text1', key: 'text1',
@@ -25,9 +25,7 @@ module.exports = class PercentDiffCommand extends Command {
} }
run(msg, { text1, text2 }) { run(msg, { text1, text2 }) {
const distance = leven(text1, text2); const diff = stringSimilarity.compareTwoStrings(text1, text2);
const bigger = Math.max(text1.length, text2.length); return msg.reply(`${Math.round(diff * 100)}%`);
const diff = Math.round(((bigger - distance) / bigger) * 100);
return msg.reply(`${diff}%`);
} }
}; };
+1
View File
@@ -79,6 +79,7 @@
"semver": "^7.3.5", "semver": "^7.3.5",
"sherlockjs": "^1.4.0", "sherlockjs": "^1.4.0",
"stackblur-canvas": "^2.5.0", "stackblur-canvas": "^2.5.0",
"string-similarity": "^4.0.4",
"tesseract.js": "^2.1.4", "tesseract.js": "^2.1.4",
"text-diff": "^1.0.1", "text-diff": "^1.0.1",
"tictactoe-minimax-ai": "^1.2.1", "tictactoe-minimax-ai": "^1.2.1",