mirror of
https://github.com/amalthea-mc/spigot-tg-bridge.git
synced 2024-11-23 10:52:26 +00:00
feature: release 0.0.7
This commit is contained in:
parent
d6dd9cb4a1
commit
7ba216f98c
@ -28,9 +28,15 @@
|
||||
| logJoinLeave | If true, plugin will send corresponding messages to chats, when player joins or leaves server | boolean | :x: | true |
|
||||
| logFromMCtoTG | If true, plugin will send messages from players on server, to Telegram chats | boolean | :x: | true |
|
||||
| logFromTGtoMC | If true, plugin will send messages from chats, to Minecraft server | boolean | :x: | true |
|
||||
| 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:
|
||||
|
||||
Commands are customizeable through config, but there are default values for them as well
|
||||
|
||||
| Command | Description |
|
||||
|:-------:|:------------|
|
||||
| `/online` | Get players, currently online |
|
||||
|
32
build.gradle
32
build.gradle
@ -1,3 +1,14 @@
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath group: 'org.yaml', name: 'snakeyaml', version: '1.26'
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.3.60'
|
||||
@ -5,10 +16,10 @@ plugins {
|
||||
}
|
||||
|
||||
group 'org.kraftwerk28'
|
||||
version '0.0.4-SNAPSHOT'
|
||||
|
||||
//def defaultOutDir = "$System.env.HOME/MinecraftServers/spigot_1.15.2/plugins/"
|
||||
//rootProject.libsDirName = System.getenv("OUT_DIR") ?: defaultOutDir
|
||||
def pluginConfigFile = new File("src/main/resources/plugin.yml").newInputStream()
|
||||
def cfg = (Map<String, Object>)new Yaml().load(pluginConfigFile)
|
||||
def v = cfg.get("version")
|
||||
version "$v-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
@ -23,6 +34,15 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
def plugDir = "MinecraftServers/spigot_1.15.2/plugins/"
|
||||
def homeDir = System.properties['user.home']
|
||||
|
||||
task cpArtifacts(type: Copy) {
|
||||
from shadowJar
|
||||
into "$homeDir/$plugDir"
|
||||
}
|
||||
shadowJar.finalizedBy cpArtifacts
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
||||
testImplementation group: 'junit', name: 'junit', version: '4.12'
|
||||
@ -30,8 +50,8 @@ dependencies {
|
||||
implementation group: 'org.telegram', name: 'telegrambots', version: '4.6'
|
||||
implementation 'com.vdurmont:emoji-java:5.1.1'
|
||||
|
||||
def tgBotVer = '5.0.0'
|
||||
implementation "io.github.kotlin-telegram-bot.kotlin-telegram-bot:telegram:$tgBotVer"
|
||||
// def tgBotVer = '5.0.0'
|
||||
// implementation "io.github.kotlin-telegram-bot.kotlin-telegram-bot:telegram:$tgBotVer"
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
|
@ -87,9 +87,9 @@ class Bot(private var plugin: Plugin) : TelegramLongPollingBot() {
|
||||
}
|
||||
|
||||
fun broadcastToTG(text: String) {
|
||||
allowedChats.forEach {
|
||||
allowedChats.forEach { chatID ->
|
||||
try {
|
||||
val msg = SendMessage(it, text).setParseMode(ParseMode.HTML)
|
||||
val msg = SendMessage(chatID, text).setParseMode(ParseMode.HTML)
|
||||
execute(msg)
|
||||
} catch (e: TelegramApiException) {
|
||||
}
|
||||
@ -118,4 +118,8 @@ class Bot(private var plugin: Plugin) : TelegramLongPollingBot() {
|
||||
(if (user.firstName.length < 2) null else user.firstName)
|
||||
?: user.userName
|
||||
?: user.lastName
|
||||
|
||||
private fun telegramUserMention(user: User): String =
|
||||
if (user.userName != null) "@${user.userName}"
|
||||
else "<a href=\"tg://user?id=${user.id}\">${user.firstName ?: user.lastName}</a>"
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ object Constants {
|
||||
val SERVER_START_MSG = "serverStartMessage"
|
||||
val SERVER_STOP_MSG = "serverStopMessage"
|
||||
val LOG_JOIN_LEAVE = "logJoinLeave"
|
||||
val LOG_PLAYER_DEATH = "logPlayerDeath"
|
||||
val LOG_PLAYER_ASLEEP = "logPlayerAsleep"
|
||||
object STRINGS {
|
||||
val ONLINE = "strings.online"
|
||||
val OFFLINE = "strings.offline"
|
||||
@ -27,6 +29,8 @@ object Constants {
|
||||
val logFromMCtoTG = false
|
||||
val logFromTGtoMC = false
|
||||
val logJoinLeave = false
|
||||
val logPlayerDeath = false
|
||||
val logPlayerAsleep = false
|
||||
object COMMANDS {
|
||||
val TIME = "/time"
|
||||
val ONLINE = "/online"
|
||||
|
@ -2,7 +2,9 @@ package org.kraftwerk28.spigot_tg_bridge
|
||||
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.entity.PlayerDeathEvent
|
||||
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 org.kraftwerk28.spigot_tg_bridge.Constants as C
|
||||
@ -12,13 +14,18 @@ class EventHandler(private val plugin: Plugin) : Listener {
|
||||
private val joinStr: String
|
||||
private val leftStr: String
|
||||
private val logJoinLeave: Boolean
|
||||
private val logDeathMessage: Boolean
|
||||
private val logPlayerAsleep: Boolean
|
||||
|
||||
init {
|
||||
plugin.config.run {
|
||||
joinStr = getString(C.FIELDS.STRINGS.JOINED, C.DEFS.playerJoined)!!
|
||||
leftStr = getString(C.FIELDS.STRINGS.LEFT, C.DEFS.playerLeft)!!
|
||||
logJoinLeave = getBoolean(C.FIELDS.LOG_JOIN_LEAVE, C.DEFS.logJoinLeave)
|
||||
logDeathMessage = getBoolean(C.FIELDS.LOG_PLAYER_DEATH, C.DEFS.logPlayerDeath)
|
||||
logPlayerAsleep = getBoolean(C.FIELDS.LOG_PLAYER_ASLEEP, C.DEFS.logPlayerAsleep)
|
||||
}
|
||||
plugin.logger.info("Log death message: $logDeathMessage")
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -43,4 +50,22 @@ class EventHandler(private val plugin: Plugin) : Listener {
|
||||
val text = "<b>${escapeHTML(event.player.displayName)}</b> $leftStr."
|
||||
plugin.tgBot?.broadcastToTG(text)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onPlayerDied(event: PlayerDeathEvent) {
|
||||
if (!logDeathMessage) return
|
||||
event.deathMessage?.let {
|
||||
val plName = event.entity.displayName
|
||||
val text = it.replace(plName, "<b>$plName</b>")
|
||||
plugin.tgBot?.broadcastToTG(text)
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onPlayerAsleep(event: PlayerBedEnterEvent) {
|
||||
if (!logPlayerAsleep) return
|
||||
if (event.bedEnterResult != PlayerBedEnterEvent.BedEnterResult.OK) return
|
||||
val text = "<b>${event.player.displayName}</b> fell asleep."
|
||||
plugin.tgBot?.broadcastToTG(text)
|
||||
}
|
||||
}
|
@ -5,6 +5,3 @@ import org.telegram.telegrambots.meta.api.objects.User
|
||||
fun escapeHTML(s: String): String =
|
||||
s.replace("&", "&").replace(">", ">").replace("<", "<")
|
||||
|
||||
fun telegramUserMention(user: User): String =
|
||||
if (user.userName != null) "@${user.userName}"
|
||||
else "<a href=\"tg://user?id=${user.id}\">${user.firstName ?: user.lastName}</a>"
|
||||
|
@ -7,9 +7,13 @@ serverStopMessage: 'Server stopped.'
|
||||
logJoinLeave: true
|
||||
logFromMCtoTG: true
|
||||
logFromTGtoMC: true
|
||||
logPlayerDeath: false
|
||||
logPlayerAsleep: false
|
||||
strings:
|
||||
online: '<b>Online</b>'
|
||||
nobodyOnline: '<b>Nobody online...</b>'
|
||||
joined: 'joined'
|
||||
left: 'left'
|
||||
|
||||
commands:
|
||||
time: '/time'
|
||||
online: '/online'
|
@ -1,5 +1,5 @@
|
||||
name: SpigotTGBridge
|
||||
version: 0.0.6
|
||||
version: 0.0.7
|
||||
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