Skip to content

Commit

Permalink
release(0.0.4): add /time command (shows time on server)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraftwerk28 committed Feb 10, 2020
1 parent 66e91a3 commit 3d30fc4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions src/main/kotlin/org/kraftwerk28/rzcraft_bridge/Bot.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.kraftwerk28.rzcraft_bridge

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.groupadministration.GetChatAdministrators
import org.telegram.telegrambots.meta.api.methods.send.SendMessage
Expand All @@ -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.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 chatToMC: Boolean =
Expand Down Expand Up @@ -45,7 +44,19 @@ class Bot(var plugin: Plugin) : TelegramLongPollingBot() {
val text =
if (playerList.isNotEmpty()) "$onlineStr:\n$playerStr"
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:
if (msg.text!!.startsWith("/")) return
Expand Down Expand Up @@ -80,8 +91,8 @@ class Bot(var plugin: Plugin) : TelegramLongPollingBot() {
text: String,
prep: ((sender: SendMessage) -> Unit)? = null
): Message {
val snd = SendMessage(msg.chatId, text)
if (prep != null) { prep(snd) }
val snd = SendMessage(msg.chatId, text).setParseMode(ParseMode.HTML)
if (prep != null) prep(snd)
return execute(snd)
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: RZCraftBridge
version: 0.0.3
version: 0.0.4
api-version: '1.15'
main: org.kraftwerk28.rzcraft_bridge.Plugin
description: Telegram <-> Minecraft communication plugin for RzaszkówCraft.
Expand Down

0 comments on commit 3d30fc4

Please sign in to comment.