mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Use string-similarity
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const leven = require('leven');
|
||||
const stringSimilarity = require('string-similarity');
|
||||
|
||||
module.exports = class PercentDiffCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'percent-diff',
|
||||
aliases: ['name-diff', 'leven-diff', 'levenshtein-diff'],
|
||||
aliases: ['name-diff'],
|
||||
group: 'analyze',
|
||||
memberName: 'percent-diff',
|
||||
description: 'Determines the percentage between two strings.',
|
||||
description: 'Determines the percentage of difference between two strings.',
|
||||
args: [
|
||||
{
|
||||
key: 'text1',
|
||||
@@ -25,9 +25,7 @@ module.exports = class PercentDiffCommand extends Command {
|
||||
}
|
||||
|
||||
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}%`);
|
||||
const diff = stringSimilarity.compareTwoStrings(text1, text2);
|
||||
return msg.reply(`${Math.round(diff * 100)}%`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
"semver": "^7.3.5",
|
||||
"sherlockjs": "^1.4.0",
|
||||
"stackblur-canvas": "^2.5.0",
|
||||
"string-similarity": "^4.0.4",
|
||||
"tesseract.js": "^2.1.4",
|
||||
"text-diff": "^1.0.1",
|
||||
"tictactoe-minimax-ai": "^1.2.1",
|
||||
|
||||
Reference in New Issue
Block a user