mirror of
https://github.com/amalthea-mc/spigot-tg-bridge.git
synced 2024-11-09 12:11:06 +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` |
|
||||
| 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 |
|
||||
| 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 |
|
||||
|
||||
|
||||
## 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 |
|
||||
|:-------:|:------------|
|
||||
|
@ -10,6 +10,7 @@ class Configuration(plugin: Plugin) {
|
||||
var isEnabled: Boolean = false
|
||||
var logFromMCtoTG: Boolean = false
|
||||
var telegramMessageFormat: String = ""
|
||||
var minecraftMessageFormat: String = ""
|
||||
var serverStartMessage: String? = null
|
||||
var serverStopMessage: String? = null
|
||||
|
||||
@ -51,6 +52,7 @@ class Configuration(plugin: Plugin) {
|
||||
logFromTGtoMC = getBoolean("logFromTGtoMC", true)
|
||||
logFromMCtoTG = getBoolean("logFromMCtoTG", true)
|
||||
telegramMessageFormat = getString("telegramMessageFormat", "<%username%>: %message%")!!
|
||||
minecraftMessageFormat = getString("minecraftMessageFormat", "<i>%username%</i>: %message%")!!
|
||||
allowedChats = getLongList("chats")
|
||||
serverStartMessage = getString("serverStartMessage")
|
||||
serverStopMessage = getString("serverStopMessage")
|
||||
@ -67,9 +69,9 @@ class Configuration(plugin: Plugin) {
|
||||
|
||||
logJoinLeave = getBoolean("logJoinLeave", false)
|
||||
onlineString = getString("strings.online", "Online")!!
|
||||
nobodyOnlineString = getString("strings.offline", "Nobody online")!!
|
||||
joinString = getString("strings.joined", "joined")
|
||||
leaveString = getString("strings.left", "left")
|
||||
nobodyOnlineString = getString("strings.nobodyOnline", "Nobody online")!!
|
||||
joinString = getString("strings.joined", "<i>%username%</i> joined.")
|
||||
leaveString = getString("strings.left", "<i>%username%</i> left.")
|
||||
logDeath = getBoolean("logPlayerDeath", false)
|
||||
logPlayerAsleep = getBoolean("logPlayerAsleep", false)
|
||||
|
||||
|
@ -8,7 +8,7 @@ object Constants {
|
||||
const val noUsername = "Bot username must be defined."
|
||||
}
|
||||
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."
|
||||
}
|
||||
object TIMES_OF_DAY {
|
||||
|
@ -24,17 +24,17 @@ class EventHandler(
|
||||
|
||||
@EventHandler
|
||||
fun onPlayerJoin(event: PlayerJoinEvent) {
|
||||
if (!config.logJoinLeave) return
|
||||
val text = "<i>${TgBot.escape(event.player.displayName)}</i> " +
|
||||
"${config.joinString}."
|
||||
if (!config.logJoinLeave || config.joinString == null) return
|
||||
val username = TgBot.fullEscape(event.player.displayName)
|
||||
val text = config.joinString!!.replace("%username%", username)
|
||||
plugin.tgBot.broadcastToTG(text)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onPlayerLeave(event: PlayerQuitEvent) {
|
||||
if (!config.logJoinLeave) return
|
||||
val text = "<i>${TgBot.escape(event.player.displayName)}</i> " +
|
||||
"${config.leaveString}."
|
||||
if (!config.logJoinLeave || config.leaveString == null) return
|
||||
val username = TgBot.fullEscape(event.player.displayName)
|
||||
val text = config.leaveString!!.replace("%username%", username)
|
||||
plugin.tgBot.broadcastToTG(text)
|
||||
}
|
||||
|
||||
@ -42,8 +42,8 @@ class EventHandler(
|
||||
fun onPlayerDied(event: PlayerDeathEvent) {
|
||||
if (!config.logDeath) return
|
||||
event.deathMessage?.let {
|
||||
val plName = event.entity.displayName
|
||||
val text = it.replace(plName, "<i>$plName</i>")
|
||||
val username = TgBot.fullEscape(event.entity.displayName)
|
||||
val text = it.replace(username, "<i>$username</i>")
|
||||
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.User
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import kotlin.reflect.KProperty0
|
||||
import org.kraftwerk28.spigot_tg_bridge.Constants as C
|
||||
|
||||
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 playerStr = plugin.server
|
||||
.onlinePlayers
|
||||
.mapIndexed { i, s -> "${i + 1}. ${s.displayName}" }
|
||||
.mapIndexed { i, s -> "${i + 1}. ${fullEscape(s.displayName)}" }
|
||||
.joinToString("\n")
|
||||
val text =
|
||||
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 =
|
||||
"<i>${escape(username)}</i>: $text"
|
||||
config.minecraftMessageFormat
|
||||
.replace("%username%", fullEscape(username))
|
||||
.replace("%message%", escapeHTML(text))
|
||||
|
||||
private fun rawUserMention(user: User): String =
|
||||
(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) =
|
||||
s.replace("&", "&").replace(">", ">").replace("<", "<")
|
||||
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
|
||||
logPlayerAsleep: false
|
||||
telegramMessageFormat: '<%username%>: %message%'
|
||||
minecraftMessageFormat: '<i>%username%</i>: %message%'
|
||||
strings:
|
||||
online: '<b>Online</b>'
|
||||
nobodyOnline: '<b>Nobody online...</b>'
|
||||
joined: 'joined'
|
||||
left: 'left'
|
||||
joined: '<i>%username%</i> joined.'
|
||||
left: '<i>%username%</i> left.'
|
||||
commands:
|
||||
time: 'time'
|
||||
online: 'online'
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: SpigotTGBridge
|
||||
version: 0.0.12
|
||||
version: 0.0.13
|
||||
api-version: '1.15'
|
||||
main: org.kraftwerk28.spigot_tg_bridge.Plugin
|
||||
description: Telegram <-> Minecraft communication plugin for Spigot.
|
||||
|
Loading…
Reference in New Issue
Block a user