From 655ab4b00264d9f1c1c5da37b92d26548e012faa Mon Sep 17 00:00:00 2001 From: kraftwerk28 Date: Tue, 29 Jun 2021 19:13:57 +0300 Subject: [PATCH] Fix text handling issue --- .../org/kraftwerk28/spigot_tg_bridge/EventHandler.kt | 12 +++--------- .../kotlin/org/kraftwerk28/spigot_tg_bridge/TgBot.kt | 5 +++-- .../kotlin/org/kraftwerk28/spigot_tg_bridge/Utils.kt | 10 ---------- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/EventHandler.kt b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/EventHandler.kt index 44e93c9..7f9b524 100644 --- a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/EventHandler.kt +++ b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/EventHandler.kt @@ -7,7 +7,6 @@ import org.bukkit.event.player.AsyncPlayerChatEvent import org.bukkit.event.player.PlayerBedEnterEvent import org.bukkit.event.player.PlayerJoinEvent import org.bukkit.event.player.PlayerQuitEvent -import kotlin.system.measureTimeMillis class EventHandler( private val tgBot: TgBot, @@ -18,14 +17,9 @@ class EventHandler( fun onPlayerChat(event: AsyncPlayerChatEvent) { if (!config.logFromMCtoTG) return event.run { - measureTimeMillis { - tgBot.sendMessageToTelegram( - message, player.displayName - ) - } - .also { - println("Time: $it") - } + tgBot.sendMessageToTelegram( + message, player.displayName + ) } } diff --git a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/TgBot.kt b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/TgBot.kt index 90a3b37..cf41360 100644 --- a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/TgBot.kt +++ b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/TgBot.kt @@ -100,10 +100,11 @@ class TgBot( private suspend fun handleUpdate() { val update = updateChan.receive() update.message?.text?.let { - println("Text: $it") commandRegex.matchEntire(it)?.groupValues?.let { - commandMap[it[1]]?.let { it(update) } ?: onTextHandler(update) + commandMap[it[1]]?.let { it(update) } } + } ?: run { + onTextHandler(update) } } diff --git a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/Utils.kt b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/Utils.kt index 7b01611..ba02df8 100644 --- a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/Utils.kt +++ b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/Utils.kt @@ -2,16 +2,6 @@ package org.kraftwerk28.spigot_tg_bridge import com.vdurmont.emoji.EmojiParser -// fun Bot.skipUpdates(lastUpdateID: Long = 0) { -// val newUpdates = getUpdates(lastUpdateID) - -// if (newUpdates.isNotEmpty()) { -// val lastUpd = newUpdates.last() -// if (lastUpd !is Update) return -// return skipUpdates(lastUpd.updateId + 1) -// } -// } - fun String.escapeHtml() = this .replace("&", "&") .replace(">", ">")