diff options
| author | Sho Sakuma <me@m1sk9.dev> | 2026-01-10 23:33:27 +0900 |
|---|---|---|
| committer | Sho Sakuma <me@m1sk9.dev> | 2026-01-10 23:33:27 +0900 |
| commit | fd62f7a05191133f8a2d1972cbf023cc52bd0f26 (patch) | |
| tree | 71f6a2ac9596bb6e80c5d66d3e585f2022c30e44 | |
| parent | 95b347ea444d956359ac0ffb5f5276f2df2b674a (diff) | |
| download | LunaticChat-fd62f7a05191133f8a2d1972cbf023cc52bd0f26.tar.gz LunaticChat-fd62f7a05191133f8a2d1972cbf023cc52bd0f26.tar.bz2 LunaticChat-fd62f7a05191133f8a2d1972cbf023cc52bd0f26.zip | |
fix: Fixed an issue where long messages were not converting correctly
4 files changed, 24 insertions, 8 deletions
diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt index f40ea80..470f3b3 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt @@ -62,7 +62,12 @@ class LunaticChat : timeout = lunaticChatConfiguration.features.japaneseConversion.apiTimeout.milliseconds, httpClient = httpClient, ) - romajiConverter = RomanjiConverter(cache, apiClient, logger) + romajiConverter = RomanjiConverter( + cache = cache, + apiClient = apiClient, + logger = logger, + debugMode = lunaticChatConfiguration.debug + ) val saveInterval = lunaticChatConfiguration.features.japaneseConversion.cacheSaveIntervalSeconds * 20L server.scheduler.runTaskTimerAsynchronously( diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/converter/GoogleIMEClient.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/converter/GoogleIMEClient.kt index 3d8b00a..0689ad4 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/converter/GoogleIMEClient.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/converter/GoogleIMEClient.kt @@ -41,16 +41,23 @@ class GoogleIMEClient( val resultArray = parsed.jsonArray // Response format: [["input", ["candidate1", "candidate2", ...]], ...] - if (resultArray.isNotEmpty()) { - val firstResult = resultArray[0].jsonArray - if (firstResult.size >= 2) { - val candidates = firstResult[1].jsonArray + // For multi-word input, there are multiple arrays, one per segment + val result = StringBuilder() + + for (segment in resultArray) { + val segmentArray = segment.jsonArray + if (segmentArray.size >= 2) { + val candidates = segmentArray[1].jsonArray if (candidates.isNotEmpty()) { - return candidates[0].jsonPrimitive.content + result.append(candidates[0].jsonPrimitive.content) } } } - throw IllegalStateException("No conversion result found in the response.") + if (result.isEmpty()) { + throw IllegalStateException("No conversion result found in the response.") + } + + return result.toString() } } diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/converter/RomanjiConverter.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/converter/RomanjiConverter.kt index b280bd5..79efa87 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/converter/RomanjiConverter.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/converter/RomanjiConverter.kt @@ -6,6 +6,7 @@ class RomanjiConverter( private val cache: ConversionCache, private val apiClient: GoogleIMEClient, private val logger: Logger, + private val debugMode: Boolean = false, ) { /** * Converts the given romaji input to Japanese using the API client. @@ -25,7 +26,9 @@ class RomanjiConverter( // Step 1: Romanji -> Hiragana val hiragana = KanaConverter.toHiragana(input) - logger.info("Romanji -> Hiragana: $input -> $hiragana") + if (debugMode) { + logger.info("Romanji -> Hiragana: $input -> $hiragana") + } // Step 2: Hiragana -> Kanji/Kana val result = diff --git a/platform-paper/src/main/resources/config.yml b/platform-paper/src/main/resources/config.yml index bab8d76..f8b8d83 100644 --- a/platform-paper/src/main/resources/config.yml +++ b/platform-paper/src/main/resources/config.yml @@ -44,6 +44,7 @@ features: # You can use placeholders such as {sender}, {message}, etc. # # {sender} - The name of the message sender +# {recipient} - The name of the message recipient # {message} - The content of the message # ---------------------------------------------- |
