Fix text handling issue

This commit is contained in:
kraftwerk28 2021-06-29 19:13:57 +03:00
parent 7c45aa2140
commit 655ab4b002
3 changed files with 6 additions and 21 deletions

View File

@ -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
)
}
}

View File

@ -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)
}
}

View File

@ -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(">", ">")