From 8388f49d856321bd3fff54a2e8025fe5d5ed80d6 Mon Sep 17 00:00:00 2001 From: Lyzev Date: Sun, 5 Nov 2023 01:10:55 +0100 Subject: [PATCH] Add Fuzzywuzzy Library for the Response of FeatureManager --- build.gradle.kts | 5 +---- gradle/libs.versions.toml | 12 +++++++++--- .../dev/lyzev/schizoid/feature/FeatureManager.kt | 10 +++++++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ebed6ebd75..f5a86961c5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -54,15 +54,12 @@ dependencies { modImplementation(libs.bundles.fabric) - // https://github.com/Lyzev implementation(libs.lyzev.events) implementation(libs.lyzev.settings) - // https://github.com/ronmamo/reflections implementation(libs.reflections) - - // https://github.com/SpaiR/imgui-java implementation(libs.bundles.imgui) + implementation(libs.fuzzywuzzy) } loom { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2e7515a559..38e500b8bd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,21 +5,26 @@ kotlin = "1.9.20" dokka = "1.9.10" -# https://fabricmc.net/develop/ +# https://fabricmc.net/develop minecraft = "1.20.2" yarn_mappings = "1.20.2+build.4" fabric_loader = "0.14.24" fabric_api = "0.90.7+1.20.2" -# https://github.com/FabricMC/fabric-language-kotlin/releases +# https://github.com/FabricMC/fabric-language-kotlin fabric_kl = "1.10.13+kotlin.1.9.20" -# https://github.com/FabricMC/fabric-loom/releases +# https://github.com/FabricMC/fabric-loom fabric_loom = "1.4-SNAPSHOT" +# https://github.com/Lyzev lyzev_events = "1.0.3" lyzev_settings = "1.0.1" +# https://github.com/ronmamo/reflections reflections = "0.10.2" +# https://github.com/SpaiR/imgui-java imgui = "1.86.11" +# https://github.com/intuit/fuzzy-matcher +fuzzywuzzy = "1.4.0" [libraries] minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" } @@ -37,6 +42,7 @@ imgui_lwjgl3 = { module = "io.github.spair:imgui-java-lwjgl3", version.ref = "im imgui_natives_windows = { module = "io.github.spair:imgui-java-natives-windows", version.ref = "imgui" } imgui_natives_linux = { module = "io.github.spair:imgui-java-natives-linux", version.ref = "imgui" } imgui_natives_macos = { module = "io.github.spair:imgui-java-natives-macos", version.ref = "imgui" } +fuzzywuzzy = { module = "me.xdrop:fuzzywuzzy", version.ref = "fuzzywuzzy" } [plugins] kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } diff --git a/src/main/kotlin/dev/lyzev/schizoid/feature/FeatureManager.kt b/src/main/kotlin/dev/lyzev/schizoid/feature/FeatureManager.kt index 328d85cf30..7caa726357 100644 --- a/src/main/kotlin/dev/lyzev/schizoid/feature/FeatureManager.kt +++ b/src/main/kotlin/dev/lyzev/schizoid/feature/FeatureManager.kt @@ -8,6 +8,7 @@ package dev.lyzev.schizoid.feature import dev.lyzev.api.events.* import dev.lyzev.schizoid.Schizoid import dev.lyzev.schizoid.feature.features.command.Command +import me.xdrop.fuzzywuzzy.FuzzySearch import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket import net.minecraft.text.Text import org.reflections.Reflections @@ -79,10 +80,13 @@ object FeatureManager : EventListener { event.isCancelled = true val args = message.substring(PREFIX.length).split(" ") val feature = find(args[0]) - if (feature != null) { + if (feature != null) feature(args.drop(1)) - } else { - sendChatMessage("Unknown command.") + else FuzzySearch.extractOne(args[0], features.flatMap { it.aliases.toList() }).let { result -> + val response = StringBuilder("Unknown command.") + if (result.score > 80 && args[0].isNotBlank()) response.append(" Did you mean ${PREFIX + result.string}?") + else response.append(" Try using ${PREFIX}help for a list of commands.") + sendChatMessage(response.toString()) } } }