mirror of
https://github.com/amalthea-mc/spigot-tg-bridge.git
synced 2024-11-23 19:02:21 +00:00
Fix text handling issue
This commit is contained in:
parent
7c45aa2140
commit
655ab4b002
@ -7,7 +7,6 @@ import org.bukkit.event.player.AsyncPlayerChatEvent
|
|||||||
import org.bukkit.event.player.PlayerBedEnterEvent
|
import org.bukkit.event.player.PlayerBedEnterEvent
|
||||||
import org.bukkit.event.player.PlayerJoinEvent
|
import org.bukkit.event.player.PlayerJoinEvent
|
||||||
import org.bukkit.event.player.PlayerQuitEvent
|
import org.bukkit.event.player.PlayerQuitEvent
|
||||||
import kotlin.system.measureTimeMillis
|
|
||||||
|
|
||||||
class EventHandler(
|
class EventHandler(
|
||||||
private val tgBot: TgBot,
|
private val tgBot: TgBot,
|
||||||
@ -18,15 +17,10 @@ class EventHandler(
|
|||||||
fun onPlayerChat(event: AsyncPlayerChatEvent) {
|
fun onPlayerChat(event: AsyncPlayerChatEvent) {
|
||||||
if (!config.logFromMCtoTG) return
|
if (!config.logFromMCtoTG) return
|
||||||
event.run {
|
event.run {
|
||||||
measureTimeMillis {
|
|
||||||
tgBot.sendMessageToTelegram(
|
tgBot.sendMessageToTelegram(
|
||||||
message, player.displayName
|
message, player.displayName
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.also {
|
|
||||||
println("Time: $it")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -100,10 +100,11 @@ class TgBot(
|
|||||||
private suspend fun handleUpdate() {
|
private suspend fun handleUpdate() {
|
||||||
val update = updateChan.receive()
|
val update = updateChan.receive()
|
||||||
update.message?.text?.let {
|
update.message?.text?.let {
|
||||||
println("Text: $it")
|
|
||||||
commandRegex.matchEntire(it)?.groupValues?.let {
|
commandRegex.matchEntire(it)?.groupValues?.let {
|
||||||
commandMap[it[1]]?.let { it(update) } ?: onTextHandler(update)
|
commandMap[it[1]]?.let { it(update) }
|
||||||
}
|
}
|
||||||
|
} ?: run {
|
||||||
|
onTextHandler(update)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,16 +2,6 @@ package org.kraftwerk28.spigot_tg_bridge
|
|||||||
|
|
||||||
import com.vdurmont.emoji.EmojiParser
|
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
|
fun String.escapeHtml() = this
|
||||||
.replace("&", "&")
|
.replace("&", "&")
|
||||||
.replace(">", ">")
|
.replace(">", ">")
|
||||||
|
Loading…
Reference in New Issue
Block a user