diff --git a/src/main/java/de/strifel/VTools/ServerCloser.java b/src/main/java/de/strifel/VTools/ServerCloser.java index cbc2be0..894afef 100644 --- a/src/main/java/de/strifel/VTools/ServerCloser.java +++ b/src/main/java/de/strifel/VTools/ServerCloser.java @@ -14,7 +14,6 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.text.MessageFormat; import java.util.Collection; import java.util.Map; import java.util.Timer; @@ -135,7 +134,7 @@ public class ServerCloser { plugin.logger.info("ServerCloser: 即将关机。"); close(); } else { - plugin.logger.error("ServerCloser: 定时器到点时发现服务器有人。这不应发生,因为定时器本应该被打断。"); + plugin.logger.error("ServerCloser: 定时器到点时发现服务器有人。这不应发生,因为定时器本应该被打断。"); TGBridge.error("ServerCloser: #bug @NaAlOH4 定时器到点时发现服务器有人。这不应发生,因为定时器本应该被打断。"); } closeServerTimer.cancel(); diff --git a/src/main/java/de/strifel/VTools/listeners/TGBridge.java b/src/main/java/de/strifel/VTools/listeners/TGBridge.java index 98f9724..7d8c6f3 100644 --- a/src/main/java/de/strifel/VTools/listeners/TGBridge.java +++ b/src/main/java/de/strifel/VTools/listeners/TGBridge.java @@ -105,6 +105,27 @@ public class TGBridge { if (message.chat() == null || message.chat().id() != CHAT_ID || message.from() == null) { break; } + String text = ""; + Message replyTo = message.replyToMessage(); + if (replyTo != null) { + text += "[reply > "; + String replyText = ""; + String replyType = getMessageType(replyTo); + if (replyTo.text() != null) { + replyText += replyTo.text(); + } + if (replyType != null) { + replyText += replyType; + if (replyTo.caption() != null) { + replyText += " \"" + replyTo.caption()+"\""; + } + } + if (replyText.equals("")) { + replyText = "?"; + } + text += replyText + "] "; + } + if (message.text() != null && !message.text().isEmpty()) { String msgText = message.text(); if (msgText.startsWith("/")) { @@ -114,7 +135,6 @@ public class TGBridge { switch (command) { case "/list" -> outbound(genOnlineStatus(), ParseMode.MarkdownV2); case "/setpin" -> { - Message replyTo = message.replyToMessage(); if (arg == null || arg.length() == 0) { if (replyTo == null) { outbound(""" @@ -161,17 +181,14 @@ public class TGBridge { ); } } - tgInbound(message.from(), msgText); - } else if (message.sticker() != null) { - tgInbound(message.from(), "[sticker]"); - } else if (message.photo() != null) { - tgInbound(message.from(), "[photo]"); - } else if (message.audio() != null) { - tgInbound(message.from(), "[audio]"); - } else if (message.voice() != null) { - tgInbound(message.from(), "[voice]"); - } else if (message.document() != null) { - tgInbound(message.from(), "[document]"); + text += msgText; + } + String messageType = getMessageType(message); + if (messageType != null) { + text += "[" + messageType + (message.caption() != null ? " \"" + message.caption() + "\"]" : "]"); + } + if (!text.equals("")) { + tgInbound(message.from(), text); } } catch (Exception e) { plugin.logger.error("handling update", e); @@ -189,6 +206,27 @@ public class TGBridge { }); } + private static String getMessageType(Message message) { + if (message.sticker() != null) { + String emoji = message.sticker().emoji(); + return emoji != null ? "sticker " + emoji : "sticker"; + } + + if (message.photo() != null) { + return "photo"; + } + if (message.audio() != null) { + return "audio"; + } + if (message.voice() != null) { + return "voice"; + } + if (message.document() != null) { + return "document"; + } + return null; + } + private boolean getPinnedMessage() { try { GetChatResponse response = bot.execute(new GetChat(CHAT_ID));