Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"node-fetch": "2",
"node-tesseract-ocr": "^2.2.1",
"sequelize": "^6.19.0",
"sqlite3": "^5.0.5",
"string-similarity": "^4.0.4"
"sqlite3": "^5.0.5"
},
"scripts": {
"start": "node dist",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/docs.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
MessageSelectMenu,
} from "discord.js";
import Bot from "../managers/Bot";
import StringSimilarity from "string-similarity";
import StringSimilarity from "../util/StringSimilarity";

export default class extends Command {
public name = "docs";
Expand Down Expand Up @@ -71,7 +71,7 @@ export default class extends Command {
} catch {
const matches = commandInfo.parameters.filter(
(c: string) =>
StringSimilarity.compareTwoStrings(c, parameter) > 0.5
StringSimilarity(c, parameter) > 0.5
);

if (matches.length > 1) {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/support.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
MessageSelectMenu,
} from "discord.js";
import Bot from "../managers/Bot";
import StringSimilarity from "string-similarity";
import StringSimilarity from "../util/StringSimilarity";

export default class extends Command {
public name = "support";
Expand Down Expand Up @@ -71,7 +71,7 @@ export default class extends Command {
} catch {
const matches = commandInfo.parameters.filter(
(c: string) =>
StringSimilarity.compareTwoStrings(c, parameter) > 0.5
StringSimilarity(c, parameter) > 0.5
);

if (matches.length > 1) {
Expand Down
4 changes: 2 additions & 2 deletions src/events/InteractionCreate.event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandInteraction, Interaction } from "discord.js";
import { Event } from "../handlers/EventHandler";
import StringSimilarity from "string-similarity";
import StringSimilarity from "../util/StringSimilarity";
import StatisticsManager from "../managers/StatisticsManager";

export default class InteractionCreate extends Event<"interactionCreate"> {
Expand Down Expand Up @@ -58,7 +58,7 @@ export default class InteractionCreate extends Event<"interactionCreate"> {

const matches = commandInfo.parameters.filter(
(c: string) =>
StringSimilarity.compareTwoStrings(c, parameter) > 0.5
StringSimilarity(c, parameter) > 0.5
);

if (matches.length > 0) {
Expand Down
32 changes: 32 additions & 0 deletions src/util/StringSimilarity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export default (first: string, second: string) => {
first = first.replace(/\s+/g, '')
second = second.replace(/\s+/g, '')

if (first === second) return 1;
if (first.length < 2 || second.length < 2) return 0;

let firstBigrams = new Map();
for (let i = 0; i < first.length - 1; i++) {
const bigram = first.substring(i, i + 2);
const count = firstBigrams.has(bigram)
? firstBigrams.get(bigram) + 1
: 1;

firstBigrams.set(bigram, count);
};

let intersectionSize = 0;
for (let i = 0; i < second.length - 1; i++) {
const bigram = second.substring(i, i + 2);
const count = firstBigrams.has(bigram)
? firstBigrams.get(bigram)
: 0;

if (count > 0) {
firstBigrams.set(bigram, count - 1);
intersectionSize++;
}
}

return (2.0 * intersectionSize) / (first.length + second.length - 2);
}
77 changes: 36 additions & 41 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"@nodelib/fs.stat" "2.0.5"
run-parallel "^1.1.9"

"@nodelib/fs.stat@^2.0.2", "@nodelib/[email protected].5":
"@nodelib/[email protected].5", "@nodelib/fs.stat@^2.0.2":
version "2.0.5"
resolved "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz"
integrity sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==
Expand Down Expand Up @@ -268,7 +268,7 @@ acorn@^8.4.1:
resolved "https://registry.npmjs.org/acorn/-/acorn-8.7.0.tgz"
integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==

agent-base@^6.0.2, agent-base@6:
agent-base@6, agent-base@^6.0.2:
version "6.0.2"
resolved "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz"
integrity sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==
Expand Down Expand Up @@ -468,7 +468,7 @@ camelcase@^6.2.0:
resolved "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz"
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

chalk@^4.1.0, chalk@^4.1.1, chalk@^4.1.2, chalk@4:
chalk@4, chalk@^4.1.0, chalk@^4.1.1, chalk@^4.1.2:
version "4.1.2"
resolved "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz"
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
Expand Down Expand Up @@ -611,20 +611,20 @@ crypto-random-string@^2.0.0:
resolved "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz"
integrity sha512-v1plID3y9r/lPhviJ1wrXpLeyUIGAZ2SHNYTEapm7/8A9nLPoyvVp3RK/EPFqn5kEznyWgYZNsRtYYIWbuG8KA==

debug@4, debug@^4.0.0, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.3:
version "4.3.3"
resolved "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz"
integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==
dependencies:
ms "2.1.2"

debug@^3.2.7:
version "3.2.7"
resolved "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz"
integrity sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==
dependencies:
ms "^2.1.1"

debug@^4.0.0, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.3, debug@4:
version "4.3.3"
resolved "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz"
integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==
dependencies:
ms "2.1.2"

decompress-response@^3.3.0:
version "3.3.0"
resolved "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz"
Expand Down Expand Up @@ -814,7 +814,7 @@ discord-api-types@^0.36.2:
resolved "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.36.3.tgz"
integrity sha512-bz/NDyG0KBo/tY14vSkrwQ/n3HKPf87a0WFW/1M9+tXYK+vp5Z5EksawfCWo2zkAc6o7CClc0eff1Pjrqznlwg==

discord.js@^13.1.0, discord.js@^13.14.0:
discord.js@^13.14.0:
version "13.16.0"
resolved "https://registry.npmjs.org/discord.js/-/discord.js-13.16.0.tgz"
integrity sha512-bOoCs1Ilojd/UshZVxmEcpxVmHcYOv2fPVZOVq3aFV8xrKLJfaF9mxlvGZ1D1z9aIqf2NkptDr+QndeNuQBTxQ==
Expand Down Expand Up @@ -861,7 +861,7 @@ emoji-regex@^8.0.0:
resolved "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz"
integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==

encoding@^0.1.0, encoding@^0.1.12:
encoding@^0.1.12:
version "0.1.13"
resolved "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz"
integrity sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==
Expand Down Expand Up @@ -1023,6 +1023,11 @@ fs.realpath@^1.0.0:
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=

fsevents@~2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==

function-bind@^1.1.1:
version "1.1.1"
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz"
Expand Down Expand Up @@ -1281,21 +1286,21 @@ inflight@^1.0.4:
once "^1.3.0"
wrappy "1"

inherits@^2.0.3, inherits@^2.0.4, inherits@2:
inherits@2, inherits@^2.0.3, inherits@^2.0.4:
version "2.0.4"
resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==

ini@~1.3.0:
version "1.3.8"
resolved "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz"
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==

[email protected]:
version "2.0.0"
resolved "https://registry.npmjs.org/ini/-/ini-2.0.0.tgz"
integrity sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA==

ini@~1.3.0:
version "1.3.8"
resolved "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz"
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==

ip@^1.1.5:
version "1.1.8"
resolved "https://registry.npmjs.org/ip/-/ip-1.1.8.tgz"
Expand Down Expand Up @@ -1688,12 +1693,12 @@ moment-timezone@^0.5.34:
dependencies:
moment ">= 2.9.0"

moment@^2.29.1, "moment@>= 2.9.0":
"moment@>= 2.9.0", moment@^2.29.1:
version "2.29.3"
resolved "https://registry.npmjs.org/moment/-/moment-2.29.3.tgz"
integrity sha512-c6YRvhEo//6T2Jz/vVtYzqBzwvPT95JBQ+smCytzf7c50oMZRsR/a4w88aD34I+/QVSfnoAnSBFPJHItlOMJVw==

ms@^2.0.0, ms@2.1.2:
ms@2.1.2, ms@^2.0.0:
version "2.1.2"
resolved "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
Expand Down Expand Up @@ -1739,7 +1744,7 @@ node-addon-api@^4.2.0:
resolved "https://registry.npmjs.org/node-addon-api/-/node-addon-api-4.3.0.tgz"
integrity sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ==

node-fetch@^2.6.1, node-fetch@^2.6.7, node-fetch@2:
node-fetch@2, node-fetch@^2.6.1, node-fetch@^2.6.7:
version "2.6.7"
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
Expand Down Expand Up @@ -1960,7 +1965,7 @@ postcss-values-parser@^5.0.0:
is-url-superb "^4.0.0"
quote-unquote "^1.0.0"

postcss@^8.0.9, postcss@^8.1.7, postcss@^8.2.13:
postcss@^8.1.7, postcss@^8.2.13:
version "8.4.6"
resolved "https://registry.npmjs.org/postcss/-/postcss-8.4.6.tgz"
integrity sha512-OovjwIzs9Te46vlEx7+uXB0PLijpwjXGKXjVGGPIGubGpq7uh5Xgf6D6FiJ/SzJMBosHDp6a2hiXOS97iBXcaA==
Expand Down Expand Up @@ -2314,18 +2319,6 @@ ssri@^8.0.0, ssri@^8.0.1:
dependencies:
minipass "^3.1.1"

string_decoder@^1.1.1:
version "1.3.0"
resolved "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz"
integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==
dependencies:
safe-buffer "~5.2.0"

string-similarity@^4.0.4:
version "4.0.4"
resolved "https://registry.npmjs.org/string-similarity/-/string-similarity-4.0.4.tgz"
integrity sha512-/q/8Q4Bl4ZKAPjj8WerIBJWALKkaPRfrvhfF8k/B23i4nzrlRj2/go1m90In7nG/3XDSbOo0+pu6RvCTM9RGMQ==

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.2, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz"
Expand All @@ -2335,6 +2328,13 @@ string-similarity@^4.0.4:
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string_decoder@^1.1.1:
version "1.3.0"
resolved "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz"
integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==
dependencies:
safe-buffer "~5.2.0"

stringify-object@^3.2.1:
version "3.3.0"
resolved "https://registry.npmjs.org/stringify-object/-/stringify-object-3.3.0.tgz"
Expand Down Expand Up @@ -2493,17 +2493,12 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"

typescript@^3.9.5:
version "3.9.10"
resolved "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz"
integrity sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==

typescript@^3.9.7:
typescript@^3.9.5, typescript@^3.9.7:
version "3.9.10"
resolved "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz"
integrity sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==

typescript@^4.5.5, typescript@>=2.7, "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta":
typescript@^4.5.5:
version "4.5.5"
resolved "https://registry.npmjs.org/typescript/-/typescript-4.5.5.tgz"
integrity sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==
Expand Down