Skip to content

Commit

Permalink
feature: release 0.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
kraftwerk28 committed Jul 11, 2020
1 parent 7ba216f commit 6cffdf4
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 195 deletions.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testImplementation group: 'junit', name: 'junit', version: '4.12'
compileOnly "org.spigotmc:spigot-api:1.15.2-R0.1-SNAPSHOT"
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 {
Expand Down
125 changes: 0 additions & 125 deletions src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/Bot.kt

This file was deleted.

62 changes: 31 additions & 31 deletions src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/Constants.kt
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
package org.kraftwerk28.spigot_tg_bridge

object Constants {
val configFilename = "config.yml"
const val configFilename = "config.yml"
// Config field names
object FIELDS {
val BOT_TOKEN = "botToken"
val BOT_USERNAME = "botUsername"
val ALLOWED_CHATS = "chats"
val LOG_FROM_MC_TO_TG = "logFromMCtoTG"
val LOG_FROM_TG_TO_MC = "logFromTGtoMC"
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"
const val BOT_TOKEN = "botToken"
const val BOT_USERNAME = "botUsername"
const val ALLOWED_CHATS = "chats"
const val LOG_FROM_MC_TO_TG = "logFromMCtoTG"
const val LOG_FROM_TG_TO_MC = "logFromTGtoMC"
const val SERVER_START_MSG = "serverStartMessage"
const val SERVER_STOP_MSG = "serverStopMessage"
const val LOG_JOIN_LEAVE = "logJoinLeave"
const val LOG_PLAYER_DEATH = "logPlayerDeath"
const val LOG_PLAYER_ASLEEP = "logPlayerAsleep"
object STRINGS {
val ONLINE = "strings.online"
val OFFLINE = "strings.offline"
val JOINED = "strings.joined"
val LEFT = "strings.left"
const val ONLINE = "strings.online"
const val OFFLINE = "strings.offline"
const val JOINED = "strings.joined"
const val LEFT = "strings.left"
}
object COMMANDS {
val TIME = "commands.time"
val ONLINE = "commands.online"
const val TIME = "commands.time"
const val ONLINE = "commands.online"
}
}
object DEFS {
val logFromMCtoTG = false
val logFromTGtoMC = false
val logJoinLeave = false
val logPlayerDeath = false
val logPlayerAsleep = false
const val logFromMCtoTG = false
const val logFromTGtoMC = false
const val logJoinLeave = false
const val logPlayerDeath = false
const val logPlayerAsleep = false
object COMMANDS {
val TIME = "/time"
val ONLINE = "/online"
const val TIME = "time"
const val ONLINE = "online"
}
val playersOnline = "Online"
val nobodyOnline = "Nobody online"
val playerJoined = "joined"
val playerLeft = "left"
const val playersOnline = "Online"
const val nobodyOnline = "Nobody online"
const val playerJoined = "joined"
const val playerLeft = "left"
}
object WARN {
val noConfigWarning = "No config file found! Writing default config to config.yml."
val noToken = "Bot token must be defined."
val noUsername = "Bot username must be defined."
const val noConfigWarning = "No config file found! Writing default config to config.yml."
const val noToken = "Bot token must be defined."
const val noUsername = "Bot username must be defined."
}
}
16 changes: 8 additions & 8 deletions src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/EventHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ class EventHandler(private val plugin: Plugin) : Listener {
@EventHandler
fun onPlayerChat(event: AsyncPlayerChatEvent) {
if (plugin.chatToTG) {
plugin.tgBot?.sendMessageToTGFrom(
escapeHTML(event.player.displayName), event.message
plugin.tgBot.sendMessageToTGFrom(
event.player.displayName, event.message
)
}
}

@EventHandler
fun onPlayerJoin(event: PlayerJoinEvent) {
if (!logJoinLeave) return
val text = "<b>${escapeHTML(event.player.displayName)}</b> $joinStr."
plugin.tgBot?.broadcastToTG(text)
val text = "<b>${TgBot.escapeHTML(event.player.displayName)}</b> $joinStr."
plugin.tgBot.broadcastToTG(text)
}

@EventHandler
fun onPlayerLeave(event: PlayerQuitEvent) {
if (!logJoinLeave) return
val text = "<b>${escapeHTML(event.player.displayName)}</b> $leftStr."
plugin.tgBot?.broadcastToTG(text)
val text = "<b>${TgBot.escapeHTML(event.player.displayName)}</b> $leftStr."
plugin.tgBot.broadcastToTG(text)
}

@EventHandler
Expand All @@ -57,7 +57,7 @@ class EventHandler(private val plugin: Plugin) : Listener {
event.deathMessage?.let {
val plName = event.entity.displayName
val text = it.replace(plName, "<b>$plName</b>")
plugin.tgBot?.broadcastToTG(text)
plugin.tgBot.broadcastToTG(text)
}
}

Expand All @@ -66,6 +66,6 @@ class EventHandler(private val plugin: Plugin) : Listener {
if (!logPlayerAsleep) return
if (event.bedEnterResult != PlayerBedEnterEvent.BedEnterResult.OK) return
val text = "<b>${event.player.displayName}</b> fell asleep."
plugin.tgBot?.broadcastToTG(text)
plugin.tgBot.broadcastToTG(text)
}
}
27 changes: 9 additions & 18 deletions src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/Plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package org.kraftwerk28.spigot_tg_bridge

import com.vdurmont.emoji.EmojiParser
import org.bukkit.plugin.java.JavaPlugin
import org.telegram.telegrambots.ApiContextInitializer
import org.telegram.telegrambots.meta.TelegramBotsApi
import java.io.File
import org.kraftwerk28.spigot_tg_bridge.Constants as C

class Plugin : JavaPlugin() {

var tgBot: Bot? = null
lateinit var tgBot: TgBot
var chatToTG: Boolean = false

init {
Expand All @@ -32,26 +30,19 @@ class Plugin : JavaPlugin() {
return
}

ApiContextInitializer.init()
val botsApi = TelegramBotsApi()
tgBot = Bot(this)

botsApi.registerBot(tgBot)

tgBot = TgBot(this)
server.pluginManager.registerEvents(EventHandler(this), this)

// Notify everything about server start
config.getString(C.FIELDS.SERVER_START_MSG, null)?.let {
logger.info("Server start message: $it")
tgBot?.broadcastToTG(it)
tgBot.broadcastToTG(it)
}
logger.info("Plugin started.")
}

override fun onDisable() {
config.getString(C.FIELDS.SERVER_STOP_MSG, null)?.let {
logger.info("Server stop message: $it")
tgBot?.broadcastToTG(it)
tgBot.broadcastToTG(it)
}
logger.info("Plugin stopped.")
}
Expand All @@ -62,10 +53,10 @@ class Plugin : JavaPlugin() {
}

fun sendMessageToMCFrom(username: String, text: String) {
val text = run {
val text = "<${escapeHTML(username)}> $text"
EmojiParser.parseToAliases(text)
}
server.broadcastMessage(text)
server.broadcastMessage(
EmojiParser.parseToAliases(
"<${TgBot.escapeHTML(username)}> $text"
)
)
}
}
Loading

0 comments on commit 6cffdf4

Please sign in to comment.