Skip to content

Commit

Permalink
Add Fuzzywuzzy Library for the Response of FeatureManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyzev committed Nov 5, 2023
1 parent 6645e5a commit 8388f49
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
5 changes: 1 addition & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 9 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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" }
Expand Down
10 changes: 7 additions & 3 deletions src/main/kotlin/dev/lyzev/schizoid/feature/FeatureManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,10 +80,13 @@ object FeatureManager : EventListener {
event.isCancelled = true
val args = message.substring(PREFIX.length).split(" ")
val feature = find<Command>(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())
}
}
}
Expand Down

0 comments on commit 8388f49

Please sign in to comment.