1
0
Fork 0
forked from mc/VTools

支持转发附件消息的描述,支持显示是否是回复信息。

This commit is contained in:
Sodium-Aluminate 2023-12-06 23:57:05 +08:00
parent 301931866a
commit 0c17f2cd80
2 changed files with 51 additions and 14 deletions

View file

@ -14,7 +14,6 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.Timer; import java.util.Timer;
@ -135,7 +134,7 @@ public class ServerCloser {
plugin.logger.info("ServerCloser: 即将关机。"); plugin.logger.info("ServerCloser: 即将关机。");
close(); close();
} else { } else {
plugin.logger.error("ServerCloser: 定时器到点时发现服务器有人。这不应发生,因为定时器本应该被打断。"); plugin.logger.error("ServerCloser: 定时器到点时发现服务器有人。这不应发生,因为定时器本应该被打断。");
TGBridge.error("ServerCloser: #bug @NaAlOH4 定时器到点时发现服务器有人。这不应发生,因为定时器本应该被打断。"); TGBridge.error("ServerCloser: #bug @NaAlOH4 定时器到点时发现服务器有人。这不应发生,因为定时器本应该被打断。");
} }
closeServerTimer.cancel(); closeServerTimer.cancel();

View file

@ -105,6 +105,27 @@ public class TGBridge {
if (message.chat() == null || message.chat().id() != CHAT_ID || message.from() == null) { if (message.chat() == null || message.chat().id() != CHAT_ID || message.from() == null) {
break; 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()) { if (message.text() != null && !message.text().isEmpty()) {
String msgText = message.text(); String msgText = message.text();
if (msgText.startsWith("/")) { if (msgText.startsWith("/")) {
@ -114,7 +135,6 @@ public class TGBridge {
switch (command) { switch (command) {
case "/list" -> outbound(genOnlineStatus(), ParseMode.MarkdownV2); case "/list" -> outbound(genOnlineStatus(), ParseMode.MarkdownV2);
case "/setpin" -> { case "/setpin" -> {
Message replyTo = message.replyToMessage();
if (arg == null || arg.length() == 0) { if (arg == null || arg.length() == 0) {
if (replyTo == null) { if (replyTo == null) {
outbound(""" outbound("""
@ -161,17 +181,14 @@ public class TGBridge {
); );
} }
} }
tgInbound(message.from(), msgText); text += msgText;
} else if (message.sticker() != null) { }
tgInbound(message.from(), "[sticker]"); String messageType = getMessageType(message);
} else if (message.photo() != null) { if (messageType != null) {
tgInbound(message.from(), "[photo]"); text += "[" + messageType + (message.caption() != null ? " \"" + message.caption() + "\"]" : "]");
} else if (message.audio() != null) { }
tgInbound(message.from(), "[audio]"); if (!text.equals("")) {
} else if (message.voice() != null) { tgInbound(message.from(), text);
tgInbound(message.from(), "[voice]");
} else if (message.document() != null) {
tgInbound(message.from(), "[document]");
} }
} catch (Exception e) { } catch (Exception e) {
plugin.logger.error("handling update", 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() { private boolean getPinnedMessage() {
try { try {
GetChatResponse response = bot.execute(new GetChat(CHAT_ID)); GetChatResponse response = bot.execute(new GetChat(CHAT_ID));