mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-27 14:18:36 +02:00
Use string-similarity
This commit is contained in:
@@ -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}%`);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
Reference in New Issue
Block a user