diff options
author | Linnea Gräf <nea@nea.moe> | 2025-01-25 00:40:58 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2025-01-25 00:40:58 +0100 |
commit | af991c28062e405a02c139d3d67c4f86a9043e35 (patch) | |
tree | 29bd1d1568b707be04915f47a1bf558e923cd3fe /src/main/kotlin/datamodel | |
parent | e4f585c173ca0a5d09130ab97c18c48f91fe5ad7 (diff) | |
download | ultra-notifier-af991c28062e405a02c139d3d67c4f86a9043e35.tar.gz ultra-notifier-af991c28062e405a02c139d3d67c4f86a9043e35.tar.bz2 ultra-notifier-af991c28062e405a02c139d3d67c4f86a9043e35.zip |
.
Diffstat (limited to 'src/main/kotlin/datamodel')
-rw-r--r-- | src/main/kotlin/datamodel/ChatType.kt | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/main/kotlin/datamodel/ChatType.kt b/src/main/kotlin/datamodel/ChatType.kt new file mode 100644 index 0000000..1fcc522 --- /dev/null +++ b/src/main/kotlin/datamodel/ChatType.kt @@ -0,0 +1,100 @@ +package moe.nea.ultranotifier.datamodel + +import net.minecraft.text.Text +import java.util.regex.Pattern + +data class ChatTypeId( + val id: String +) + +data class ChatType( + val id: ChatTypeId, + val name: String, + val patterns: List<ChatPattern>, +) + +data class ChatPattern( + val text: String +) { + val pattern = Pattern.compile(text) + val predicate = pattern.asMatchPredicate() +} + +data class ChatCategory( + val label: String, + val chatTypes: Set<ChatTypeId>, +) + +data class ChatUniverse( + val name: String, + val types: List<ChatType>, + val categories: List<ChatCategory>, +) { + fun categorize( + text: String + ): CategorizedChatLine { + val types = this.types + .asSequence() + .filter { + it.patterns.any { + it.predicate.test(text) + } + } + .map { + it.id + } + .toSet() + // TODO: potentially allow recalculating categories on the fly + val categories = categories.filterTo(mutableSetOf()) { it.chatTypes.any { it in types } } + return CategorizedChatLine( + text, types, categories + ) + } +} + +data class CategorizedChatLine( + val text: String, + val types: Set<ChatTypeId>, + val categories: Set<ChatCategory>, +) + +interface HasCategorizedChatLine { + val categorizedChatLine_ultraNotifier: CategorizedChatLine +} + +object ChatCategoryArbiter { + val universe = ChatUniverse( + "Hypixel SkyBlock", + listOf( + ChatType( + ChatTypeId("bazaar"), + "Bazaar", + listOf( + ChatPattern("(?i).*Bazaar.*") + ) + ), + ChatType( + ChatTypeId("auction-house"), + "Auction House", + listOf( + ChatPattern("(?i).*Auction House.*") + ) + ), + ), + listOf( + ChatCategory( + "Economy", + setOf(ChatTypeId("bazaar"), ChatTypeId("auction-house")) + ) + ) + ) + + fun categorize(content: Text): CategorizedChatLine { + universe.categorize(content.lit) + } +} + + + + + |