mirror of
https://github.com/amalthea-mc/spigot-tg-bridge.git
synced 2024-11-23 10:52:26 +00:00
feature: release 0.0.13
Changelog: - bug fixes - better placeholders for message formatting
This commit is contained in:
parent
8c7fe22e3d
commit
4a00808ab5
@ -57,13 +57,13 @@ P. S. You can always update plugin configuration without restarting the server.
|
|||||||
| logPlayerDeath | If true, plugin will send message to Telegram if player died | `boolean` | :x: | `false` |
|
| logPlayerDeath | If true, plugin will send message to Telegram if player died | `boolean` | :x: | `false` |
|
||||||
| logPlayerAsleep | If true, plugin will send message to Telegram if player fell asleep | `boolean` | :x: | `false` |
|
| logPlayerAsleep | If true, plugin will send message to Telegram if player fell asleep | `boolean` | :x: | `false` |
|
||||||
| strings | Dictionary of tokens - strings for plugin i18n | `Map<string, string>` | :x: | See default config |
|
| strings | Dictionary of tokens - strings for plugin i18n | `Map<string, string>` | :x: | See default config |
|
||||||
| commands | Dictionary of command text used in Telegram bot | `Map<string, string>` | :x: | See default config |
|
| commands | Dictionary of command text used in Telegram bot | `Map<string, string>` | :heavy_check_mark: | See below |
|
||||||
| telegramMessageFormat | Format string for TGtoMC chat message | `string` | :x: | See default config |
|
| telegramMessageFormat | Format string for TGtoMC chat message | `string` | :x: | See default config |
|
||||||
|
|
||||||
|
|
||||||
## Telegram bot commands:
|
## Telegram bot commands:
|
||||||
|
|
||||||
Commands are customizeable through config, but there are default values for them as well
|
Commands are customizeable through config. If command doesn't exist in config, it will be disabled
|
||||||
|
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
|:-------:|:------------|
|
|:-------:|:------------|
|
||||||
|
@ -10,6 +10,7 @@ class Configuration(plugin: Plugin) {
|
|||||||
var isEnabled: Boolean = false
|
var isEnabled: Boolean = false
|
||||||
var logFromMCtoTG: Boolean = false
|
var logFromMCtoTG: Boolean = false
|
||||||
var telegramMessageFormat: String = ""
|
var telegramMessageFormat: String = ""
|
||||||
|
var minecraftMessageFormat: String = ""
|
||||||
var serverStartMessage: String? = null
|
var serverStartMessage: String? = null
|
||||||
var serverStopMessage: String? = null
|
var serverStopMessage: String? = null
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ class Configuration(plugin: Plugin) {
|
|||||||
logFromTGtoMC = getBoolean("logFromTGtoMC", true)
|
logFromTGtoMC = getBoolean("logFromTGtoMC", true)
|
||||||
logFromMCtoTG = getBoolean("logFromMCtoTG", true)
|
logFromMCtoTG = getBoolean("logFromMCtoTG", true)
|
||||||
telegramMessageFormat = getString("telegramMessageFormat", "<%username%>: %message%")!!
|
telegramMessageFormat = getString("telegramMessageFormat", "<%username%>: %message%")!!
|
||||||
|
minecraftMessageFormat = getString("minecraftMessageFormat", "<i>%username%</i>: %message%")!!
|
||||||
allowedChats = getLongList("chats")
|
allowedChats = getLongList("chats")
|
||||||
serverStartMessage = getString("serverStartMessage")
|
serverStartMessage = getString("serverStartMessage")
|
||||||
serverStopMessage = getString("serverStopMessage")
|
serverStopMessage = getString("serverStopMessage")
|
||||||
@ -67,9 +69,9 @@ class Configuration(plugin: Plugin) {
|
|||||||
|
|
||||||
logJoinLeave = getBoolean("logJoinLeave", false)
|
logJoinLeave = getBoolean("logJoinLeave", false)
|
||||||
onlineString = getString("strings.online", "Online")!!
|
onlineString = getString("strings.online", "Online")!!
|
||||||
nobodyOnlineString = getString("strings.offline", "Nobody online")!!
|
nobodyOnlineString = getString("strings.nobodyOnline", "Nobody online")!!
|
||||||
joinString = getString("strings.joined", "joined")
|
joinString = getString("strings.joined", "<i>%username%</i> joined.")
|
||||||
leaveString = getString("strings.left", "left")
|
leaveString = getString("strings.left", "<i>%username%</i> left.")
|
||||||
logDeath = getBoolean("logPlayerDeath", false)
|
logDeath = getBoolean("logPlayerDeath", false)
|
||||||
logPlayerAsleep = getBoolean("logPlayerAsleep", false)
|
logPlayerAsleep = getBoolean("logPlayerAsleep", false)
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ object Constants {
|
|||||||
const val noUsername = "Bot username must be defined."
|
const val noUsername = "Bot username must be defined."
|
||||||
}
|
}
|
||||||
object INFO {
|
object INFO {
|
||||||
const val reloading = "Reloading plugin... This may take some time"
|
const val reloading = "Reloading plugin... This may take some time."
|
||||||
const val reloadComplete = "Reload completed."
|
const val reloadComplete = "Reload completed."
|
||||||
}
|
}
|
||||||
object TIMES_OF_DAY {
|
object TIMES_OF_DAY {
|
||||||
|
@ -24,17 +24,17 @@ class EventHandler(
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
fun onPlayerJoin(event: PlayerJoinEvent) {
|
fun onPlayerJoin(event: PlayerJoinEvent) {
|
||||||
if (!config.logJoinLeave) return
|
if (!config.logJoinLeave || config.joinString == null) return
|
||||||
val text = "<i>${TgBot.escape(event.player.displayName)}</i> " +
|
val username = TgBot.fullEscape(event.player.displayName)
|
||||||
"${config.joinString}."
|
val text = config.joinString!!.replace("%username%", username)
|
||||||
plugin.tgBot.broadcastToTG(text)
|
plugin.tgBot.broadcastToTG(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
fun onPlayerLeave(event: PlayerQuitEvent) {
|
fun onPlayerLeave(event: PlayerQuitEvent) {
|
||||||
if (!config.logJoinLeave) return
|
if (!config.logJoinLeave || config.leaveString == null) return
|
||||||
val text = "<i>${TgBot.escape(event.player.displayName)}</i> " +
|
val username = TgBot.fullEscape(event.player.displayName)
|
||||||
"${config.leaveString}."
|
val text = config.leaveString!!.replace("%username%", username)
|
||||||
plugin.tgBot.broadcastToTG(text)
|
plugin.tgBot.broadcastToTG(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,8 +42,8 @@ class EventHandler(
|
|||||||
fun onPlayerDied(event: PlayerDeathEvent) {
|
fun onPlayerDied(event: PlayerDeathEvent) {
|
||||||
if (!config.logDeath) return
|
if (!config.logDeath) return
|
||||||
event.deathMessage?.let {
|
event.deathMessage?.let {
|
||||||
val plName = event.entity.displayName
|
val username = TgBot.fullEscape(event.entity.displayName)
|
||||||
val text = it.replace(plName, "<i>$plName</i>")
|
val text = it.replace(username, "<i>$username</i>")
|
||||||
plugin.tgBot.broadcastToTG(text)
|
plugin.tgBot.broadcastToTG(text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import com.github.kotlintelegrambot.entities.ParseMode
|
|||||||
import com.github.kotlintelegrambot.entities.Update
|
import com.github.kotlintelegrambot.entities.Update
|
||||||
import com.github.kotlintelegrambot.entities.User
|
import com.github.kotlintelegrambot.entities.User
|
||||||
import okhttp3.logging.HttpLoggingInterceptor
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
import kotlin.reflect.KProperty0
|
|
||||||
import org.kraftwerk28.spigot_tg_bridge.Constants as C
|
import org.kraftwerk28.spigot_tg_bridge.Constants as C
|
||||||
|
|
||||||
fun Bot.skipUpdates(lastUpdateID: Long = 0) {
|
fun Bot.skipUpdates(lastUpdateID: Long = 0) {
|
||||||
@ -106,7 +105,7 @@ class TgBot(private val plugin: Plugin, private val config: Configuration) {
|
|||||||
val playerList = plugin.server.onlinePlayers
|
val playerList = plugin.server.onlinePlayers
|
||||||
val playerStr = plugin.server
|
val playerStr = plugin.server
|
||||||
.onlinePlayers
|
.onlinePlayers
|
||||||
.mapIndexed { i, s -> "${i + 1}. ${s.displayName}" }
|
.mapIndexed { i, s -> "${i + 1}. ${fullEscape(s.displayName)}" }
|
||||||
.joinToString("\n")
|
.joinToString("\n")
|
||||||
val text =
|
val text =
|
||||||
if (playerList.isNotEmpty()) "${config.onlineString}:\n$playerStr"
|
if (playerList.isNotEmpty()) "${config.onlineString}:\n$playerStr"
|
||||||
@ -159,7 +158,9 @@ class TgBot(private val plugin: Plugin, private val config: Configuration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun messageFromMinecraft(username: String, text: String): String =
|
private fun messageFromMinecraft(username: String, text: String): String =
|
||||||
"<i>${escape(username)}</i>: $text"
|
config.minecraftMessageFormat
|
||||||
|
.replace("%username%", fullEscape(username))
|
||||||
|
.replace("%message%", escapeHTML(text))
|
||||||
|
|
||||||
private fun rawUserMention(user: User): String =
|
private fun rawUserMention(user: User): String =
|
||||||
(if (user.firstName.length < 2) null else user.firstName)
|
(if (user.firstName.length < 2) null else user.firstName)
|
||||||
@ -176,6 +177,6 @@ class TgBot(private val plugin: Plugin, private val config: Configuration) {
|
|||||||
fun escapeHTML(s: String) =
|
fun escapeHTML(s: String) =
|
||||||
s.replace("&", "&").replace(">", ">").replace("<", "<")
|
s.replace("&", "&").replace(">", ">").replace("<", "<")
|
||||||
fun escapeColorCodes(s: String) = s.replace("\u00A7.".toRegex(), "")
|
fun escapeColorCodes(s: String) = s.replace("\u00A7.".toRegex(), "")
|
||||||
fun escape(s: String) = escapeColorCodes(escapeHTML(s))
|
fun fullEscape(s: String) = escapeColorCodes(escapeHTML(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,11 +11,12 @@ logFromTGtoMC: true
|
|||||||
logPlayerDeath: false
|
logPlayerDeath: false
|
||||||
logPlayerAsleep: false
|
logPlayerAsleep: false
|
||||||
telegramMessageFormat: '<%username%>: %message%'
|
telegramMessageFormat: '<%username%>: %message%'
|
||||||
|
minecraftMessageFormat: '<i>%username%</i>: %message%'
|
||||||
strings:
|
strings:
|
||||||
online: '<b>Online</b>'
|
online: '<b>Online</b>'
|
||||||
nobodyOnline: '<b>Nobody online...</b>'
|
nobodyOnline: '<b>Nobody online...</b>'
|
||||||
joined: 'joined'
|
joined: '<i>%username%</i> joined.'
|
||||||
left: 'left'
|
left: '<i>%username%</i> left.'
|
||||||
commands:
|
commands:
|
||||||
time: 'time'
|
time: 'time'
|
||||||
online: 'online'
|
online: 'online'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name: SpigotTGBridge
|
name: SpigotTGBridge
|
||||||
version: 0.0.12
|
version: 0.0.13
|
||||||
api-version: '1.15'
|
api-version: '1.15'
|
||||||
main: org.kraftwerk28.spigot_tg_bridge.Plugin
|
main: org.kraftwerk28.spigot_tg_bridge.Plugin
|
||||||
description: Telegram <-> Minecraft communication plugin for Spigot.
|
description: Telegram <-> Minecraft communication plugin for Spigot.
|
||||||
|
Loading…
Reference in New Issue
Block a user