From 0c17f2cd8091694854b9f94e6db87c35b21c1b16 Mon Sep 17 00:00:00 2001 From: Sodium-Aluminate Date: Wed, 6 Dec 2023 23:57:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=BD=AC=E5=8F=91=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E6=B6=88=E6=81=AF=E7=9A=84=E6=8F=8F=E8=BF=B0=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=98=BE=E7=A4=BA=E6=98=AF=E5=90=A6=E6=98=AF?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/de/strifel/VTools/ServerCloser.java | 3 +- .../de/strifel/VTools/listeners/TGBridge.java | 62 +++++++++++++++---- 2 files changed, 51 insertions(+), 14 deletions(-) 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));