diff options
author | MicrocontrollersDev <66657148+MicrocontrollersDev@users.noreply.github.com> | 2023-01-14 10:45:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-14 12:45:31 -0500 |
commit | 3470ee81c4444c5955f7899acce226dae14a3da4 (patch) | |
tree | 60c2a0b1bda92e6400cf6b058259f5f52b8b02ce /src/main/kotlin | |
parent | 1b3670de60500c491e5c61b0d304bcde7e30080f (diff) | |
download | Chatting-3470ee81c4444c5955f7899acce226dae14a3da4.tar.gz Chatting-3470ee81c4444c5955f7899acce226dae14a3da4.tar.bz2 Chatting-3470ee81c4444c5955f7899acce226dae14a3da4.zip |
use regex for pms (#16)
* use regex for pms
* maybe do the version thing idk
* fix migration
Co-authored-by: Wyvest <45589059+Wyvest@users.noreply.github.com>
Diffstat (limited to 'src/main/kotlin')
-rw-r--r-- | src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt | 47 | ||||
-rw-r--r-- | src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt | 2 |
2 files changed, 45 insertions, 4 deletions
diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt index 62c2760..b6027a7 100644 --- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt +++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt @@ -6,6 +6,7 @@ import com.google.gson.GsonBuilder import com.google.gson.JsonArray import com.google.gson.JsonObject import com.google.gson.JsonParser +import com.google.gson.JsonPrimitive import net.minecraft.client.Minecraft import net.minecraft.util.IChatComponent import java.io.File @@ -46,6 +47,7 @@ object ChatTabs { applyVersion3Changes(it.asJsonObject) applyVersion4Changes(it.asJsonObject) applyVersion5Changes(it.asJsonObject) + applyVersion6Changes(it.asJsonObject) } chatTabJson.version = ChatTabsJson.VERSION tabFile.writeText(GSON.toJson(chatTabJson)) @@ -56,6 +58,7 @@ object ChatTabs { applyVersion3Changes(it.asJsonObject) applyVersion4Changes(it.asJsonObject) applyVersion5Changes(it.asJsonObject) + applyVersion6Changes(it.asJsonObject) } chatTabJson.version = ChatTabsJson.VERSION tabFile.writeText(GSON.toJson(chatTabJson)) @@ -65,6 +68,7 @@ object ChatTabs { chatTabJson.tabs.forEach { applyVersion4Changes(it.asJsonObject) applyVersion5Changes(it.asJsonObject) + applyVersion6Changes(it.asJsonObject) } chatTabJson.version = ChatTabsJson.VERSION tabFile.writeText(GSON.toJson(chatTabJson)) @@ -73,6 +77,15 @@ object ChatTabs { // ver 5 adds lowercase chatTabJson.tabs.forEach { applyVersion5Changes(it.asJsonObject) + applyVersion6Changes(it.asJsonObject) + } + chatTabJson.version = ChatTabsJson.VERSION + tabFile.writeText(GSON.toJson(chatTabJson)) + } + 5 -> { + // ver 6 changes pm regex + chatTabJson.tabs.forEach { + applyVersion6Changes(it.asJsonObject) } chatTabJson.version = ChatTabsJson.VERSION tabFile.writeText(GSON.toJson(chatTabJson)) @@ -118,6 +131,34 @@ object ChatTabs { json.addProperty("lowercase", false) } + private fun applyVersion6Changes(json: JsonObject) { + if (json.has("starts")) { + val starts = json["starts"].asJsonArray + var detected = false + starts.iterator().let { + while (it.hasNext()) { + when (it.next().asString) { + "To " -> { + detected = true + it.remove() + } + "From " -> { + detected = true + it.remove() + } + } + } + } + if (detected) { + json.add("regex", JsonArray().apply { + add(JsonPrimitive("^(?<type>§dTo|§dFrom) (?<prefix>.+): §r(?<message>§7.*)(?:§r)?\$")) + }) + json.remove("unformatted") + json.addProperty("unformatted", false) + } + } + } + fun shouldRender(message: IChatComponent): Boolean { return currentTab?.shouldRender(message) ?: true } @@ -244,13 +285,13 @@ object ChatTabs { val pm = ChatTab( true, "PM", - unformatted = true, + unformatted = false, lowercase = false, - startsWith = listOf("To ", "From "), + startsWith = null, contains = null, endsWith = null, equals = null, - uncompiledRegex = null, + uncompiledRegex = listOf("^(?<type>§dTo|§dFrom) (?<prefix>.+): §r(?<message>§7.*)(?:§r)?\$"), ignoreStartsWith = null, ignoreContains = null, ignoreEndsWith = null, diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt index b239bbd..c632561 100644 --- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt +++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt @@ -10,6 +10,6 @@ data class ChatTabsJson(@SerializedName("tabs") val tabs: JsonArray, var version } companion object { - const val VERSION = 5 + const val VERSION = 6 } }
\ No newline at end of file |