diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-03-16 09:59:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-16 09:59:05 +0100 |
commit | bb9cef4d5b035a6722890018a27bb2502afa40bc (patch) | |
tree | 7d16956fa980c1c4520501abfeae92f840216d5c /src/main | |
parent | fe51024f9a230f6408e69bd73293c71412bf9c0e (diff) | |
download | skyhanni-bb9cef4d5b035a6722890018a27bb2502afa40bc.tar.gz skyhanni-bb9cef4d5b035a6722890018a27bb2502afa40bc.tar.bz2 skyhanni-bb9cef4d5b035a6722890018a27bb2502afa40bc.zip |
Backend: Chat History Search (#1187)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt | 2 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt | 20 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index d01a4a8c3..3b1c02bb0 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -391,7 +391,7 @@ object Commands { registerCommand("shtestwaypoint", "Set a waypoint on that location") { SkyHanniDebugsAndTests.waypoint(it) } registerCommand("shtesttablist", "Set your clipboard as a fake tab list.") { TabListData.toggleDebugCommand() } registerCommand("shreloadlocalrepo", "Reloading the local repo data") { SkyHanniMod.repo.reloadLocalRepo() } - registerCommand("shchathistory", "Show the unfiltered chat history") { ChatManager.openChatFilterGUI() } + registerCommand("shchathistory", "Show the unfiltered chat history") { ChatManager.openChatFilterGUI(it) } registerCommand( "shstoplisteners", "Unregistering all loaded forge event listeners" diff --git a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt index 915acf214..8573a629f 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt @@ -5,12 +5,14 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.MessageSendToServerEvent import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.features.chat.ChatFilterGui +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.IdentityCharacteristics import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.ReflectionUtils.getClassInstance import at.hannibal2.skyhanni.utils.ReflectionUtils.getModContainer import at.hannibal2.skyhanni.utils.ReflectionUtils.makeAccessible +import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraft.client.Minecraft import net.minecraft.client.gui.ChatLine import net.minecraft.client.gui.GuiNewChat @@ -40,6 +42,10 @@ object ChatManager { private fun getRecentMessageHistory(): List<MessageFilteringResult> = messageHistory.toList().map { it.second } + private fun getRecentMessageHistoryWithSearch(searchTerm: String): List<MessageFilteringResult> = + messageHistory.toList().map { it.second } + .filter { it.message.formattedText.removeColor().contains(searchTerm, ignoreCase = true) } + enum class ActionKind(format: Any) { BLOCKED(EnumChatFormatting.RED.toString() + EnumChatFormatting.BOLD), RETRACTED(EnumChatFormatting.DARK_PURPLE.toString() + EnumChatFormatting.BOLD), @@ -182,8 +188,18 @@ object ChatManager { return false } - fun openChatFilterGUI() { - SkyHanniMod.screenToOpen = ChatFilterGui(getRecentMessageHistory()) + fun openChatFilterGUI(args: Array<String>) { + SkyHanniMod.screenToOpen = if (args.isEmpty()) { + ChatFilterGui(getRecentMessageHistory()) + } else { + val searchTerm = args.joinToString(" ") + val history = getRecentMessageHistoryWithSearch(searchTerm) + if (history.isEmpty()) { + ChatUtils.chat("§eNot found in chat history! ($searchTerm)") + return + } + ChatFilterGui(history) + } } private val chatLinesField by lazy { |