release(0.0.4): add /time command (shows time on server)

This commit is contained in:
kraftwerk28 2020-02-10 16:57:28 +02:00
parent 66e91a304a
commit 3d30fc47a5
2 changed files with 17 additions and 6 deletions

View File

@ -1,7 +1,6 @@
package org.kraftwerk28.rzcraft_bridge package org.kraftwerk28.rzcraft_bridge
import org.telegram.telegrambots.bots.TelegramLongPollingBot import org.telegram.telegrambots.bots.TelegramLongPollingBot
import org.telegram.telegrambots.meta.api.methods.BotApiMethod
import org.telegram.telegrambots.meta.api.methods.ParseMode import org.telegram.telegrambots.meta.api.methods.ParseMode
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators
import org.telegram.telegrambots.meta.api.methods.send.SendMessage import org.telegram.telegrambots.meta.api.methods.send.SendMessage
@ -10,7 +9,7 @@ import org.telegram.telegrambots.meta.api.objects.Update
import org.telegram.telegrambots.meta.api.objects.User import org.telegram.telegrambots.meta.api.objects.User
import org.telegram.telegrambots.meta.exceptions.TelegramApiException import org.telegram.telegrambots.meta.exceptions.TelegramApiException
class Bot(var plugin: Plugin) : TelegramLongPollingBot() { class Bot(private var plugin: Plugin) : TelegramLongPollingBot() {
private var allowedChats: List<Long> = plugin.config.getLongList("chats") private var allowedChats: List<Long> = plugin.config.getLongList("chats")
private var chatToMC: Boolean = private var chatToMC: Boolean =
@ -45,7 +44,19 @@ class Bot(var plugin: Plugin) : TelegramLongPollingBot() {
val text = val text =
if (playerList.isNotEmpty()) "$onlineStr:\n$playerStr" if (playerList.isNotEmpty()) "$onlineStr:\n$playerStr"
else offlineStr else offlineStr
reply(msg, text, { it.setParseMode(ParseMode.HTML) }) reply(msg, text) { it.replyToMessageId = msg.messageId }
}
if (msg.text.startsWith("/time")) {
val t = plugin.server.worlds[0].time
var text = when {
t <= 12000 -> "\uD83C\uDFDE Day"
t <= 13800 -> "\uD83C\uDF06 Sunset"
t <= 22200 -> "\uD83C\uDF03 Night"
t <= 24000 -> "\uD83C\uDF05 Sunrise"
else -> ""
}
text += " ($t)"
reply(msg, text) { it.replyToMessageId = msg.messageId }
} }
// stop, if no command matched: // stop, if no command matched:
if (msg.text!!.startsWith("/")) return if (msg.text!!.startsWith("/")) return
@ -80,8 +91,8 @@ class Bot(var plugin: Plugin) : TelegramLongPollingBot() {
text: String, text: String,
prep: ((sender: SendMessage) -> Unit)? = null prep: ((sender: SendMessage) -> Unit)? = null
): Message { ): Message {
val snd = SendMessage(msg.chatId, text) val snd = SendMessage(msg.chatId, text).setParseMode(ParseMode.HTML)
if (prep != null) { prep(snd) } if (prep != null) prep(snd)
return execute(snd) return execute(snd)
} }

View File

@ -1,5 +1,5 @@
name: RZCraftBridge name: RZCraftBridge
version: 0.0.3 version: 0.0.4
api-version: '1.15' api-version: '1.15'
main: org.kraftwerk28.rzcraft_bridge.Plugin main: org.kraftwerk28.rzcraft_bridge.Plugin
description: Telegram <-> Minecraft communication plugin for RzaszkówCraft. description: Telegram <-> Minecraft communication plugin for RzaszkówCraft.