diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 83b37b5..28a465f 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -8,6 +8,7 @@ + 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 4699de8..66d5947 100644 --- a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/TgBot.kt +++ b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/TgBot.kt @@ -32,6 +32,7 @@ class TgBot(private val plugin: Plugin, private val config: Configuration) { val slashRegex = "^/+".toRegex() val commands = config.commands + skipUpdates() bot = bot { token = config.botToken logLevel = HttpLoggingInterceptor.Level.NONE @@ -45,14 +46,13 @@ class TgBot(private val plugin: Plugin, private val config: Configuration) { }.filterKeys { it != null } dispatch { - cmdBinding.forEach { text, handler -> - command(text!!, handler as HandleUpdate) + cmdBinding.forEach { (text, handler) -> + command(text!!.replace(slashRegex, ""), handler) } text(null, ::onText) } } bot.setMyCommands(getBotCommands()) - bot.skipUpdates() config.webhookConfig?.let { _ -> plugin.logger.info("Running in webhook mode.") @@ -173,10 +173,22 @@ class TgBot(private val plugin: Plugin, private val config: Configuration) { return cmdList.zip(descList).map { BotCommand(it.first, it.second) } } + private fun skipUpdates() { + bot { + token = config.botToken + timeout = 0 + logLevel = HttpLoggingInterceptor.Level.NONE + }.skipUpdates() + } + companion object { - fun escapeHTML(s: String) = - s.replace("&", "&").replace(">", ">").replace("<", "<") + fun escapeHTML(s: String) = s + .replace("&", "&") + .replace(">", ">") + .replace("<", "<") + fun escapeColorCodes(s: String) = s.replace("\u00A7.".toRegex(), "") + fun fullEscape(s: String) = escapeColorCodes(escapeHTML(s)) } } \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7c2f09a..a9feb47 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: SpigotTGBridge -version: 0.0.13 +version: 0.0.14 api-version: '1.15' main: org.kraftwerk28.spigot_tg_bridge.Plugin description: Telegram <-> Minecraft communication plugin for Spigot.