From de532e9440c36de9d1e480db936d98f1688a88c1 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Mon, 10 May 2021 19:40:42 -0400 Subject: [PATCH] Leven Commands --- commands/analyze/levenshtein.js | 31 ++++++++++++++++++++++++++++++ commands/analyze/percent-diff.js | 33 ++++++++++++++++++++++++++++++++ package.json | 3 ++- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 commands/analyze/levenshtein.js create mode 100644 commands/analyze/percent-diff.js diff --git a/commands/analyze/levenshtein.js b/commands/analyze/levenshtein.js new file mode 100644 index 00000000..91f5074f --- /dev/null +++ b/commands/analyze/levenshtein.js @@ -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); + } +}; diff --git a/commands/analyze/percent-diff.js b/commands/analyze/percent-diff.js new file mode 100644 index 00000000..7dc260be --- /dev/null +++ b/commands/analyze/percent-diff.js @@ -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}%`); + } +}; diff --git a/package.json b/package.json index d9731eb2..fddf5c77 100644 --- a/package.json +++ b/package.json @@ -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",