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.file.Files;
import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.Map;
import java.util.Timer;

View file

@ -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));