From b5941494f69d9d18b2bb3e5097669fdc040302be Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Fri, 6 May 2022 11:27:34 +0800 Subject: [PATCH] =?UTF-8?q?#30=20=E4=BD=BF=20SlashAction=20=E7=9A=84?= =?UTF-8?q?=E5=9B=9E=E6=89=A7=E6=94=AF=E6=8C=81=E9=A2=91=E9=81=93=E8=BA=AB?= =?UTF-8?q?=E4=BB=BD=E7=9A=84=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 但由于API限制,链接无法导向至频道 --- gradle.properties | 2 +- .../cono/morny/GradleProjectConfigures.java | 4 +-- .../morny/bot/event/OnUserSlashAction.java | 15 +++++----- .../util/tgapi/TGToStringFromMessage.java | 30 +++++++++++++++++++ 4 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 src/main/java/cc/sukazyo/cono/morny/util/tgapi/TGToStringFromMessage.java diff --git a/gradle.properties b/gradle.properties index d270904..5c9ffe4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.6.3.1 +VERSION = 0.6.3.2 # dependencies diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index cfd598d..d08ca5a 100644 --- a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java +++ b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java @@ -4,6 +4,6 @@ package cc.sukazyo.cono.morny; * the final field that will be updated by gradle automatically. */ public class GradleProjectConfigures { - public static final String VERSION = "0.6.3.0"; - public static final long COMPILE_TIMESTAMP = 1651804975121L; + public static final String VERSION = "0.6.3.2"; + public static final long COMPILE_TIMESTAMP = 1651806802187L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.java index bfb5da3..b624a23 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.java @@ -2,12 +2,13 @@ package cc.sukazyo.cono.morny.bot.event; import cc.sukazyo.cono.morny.MornyCoeur; import cc.sukazyo.cono.morny.bot.api.EventListener; +import cc.sukazyo.cono.morny.util.tgapi.TGToStringFromMessage; import cc.sukazyo.untitled.telegram.api.formatting.TGToString; import cc.sukazyo.untitled.util.command.CommonCommand; import cc.sukazyo.untitled.util.string.StringArrays; +import com.pengrad.telegrambot.model.Message; import com.pengrad.telegrambot.model.Update; -import com.pengrad.telegrambot.model.User; import com.pengrad.telegrambot.model.request.ParseMode; import com.pengrad.telegrambot.request.SendMessage; @@ -55,22 +56,22 @@ public class OnUserSlashAction extends EventListener { hasObject ? StringArrays.connectStringArray(action, " ", isHardParse?2:1, action.length-1) : ""; - final User origin = event.message().from(); - final User target = (event.message().replyToMessage() == null ? ( + final Message origin = event.message(); + final Message target = (event.message().replyToMessage() == null ? ( origin ): ( - event.message().replyToMessage().from() + event.message().replyToMessage() )); MornyCoeur.extra().exec(new SendMessage( event.message().chat().id(), String.format( "%s %s%s %s %s!", - TGToString.as(origin).firstnameRefHtml(), + TGToStringFromMessage.as(origin).getSenderFirstNameRefHtml(), escapeHtml(verb), escapeHtml((hasObject?"":"了")), origin==target ? - "自己" : - TGToString.as(target).firstnameRefHtml(), + "自己" : + TGToStringFromMessage.as(target).getSenderFirstNameRefHtml(), escapeHtml(hasObject ? object+" " : "") ) ).parseMode(ParseMode.HTML).replyToMessageId(event.message().messageId())); diff --git a/src/main/java/cc/sukazyo/cono/morny/util/tgapi/TGToStringFromMessage.java b/src/main/java/cc/sukazyo/cono/morny/util/tgapi/TGToStringFromMessage.java new file mode 100644 index 0000000..e4fac35 --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/util/tgapi/TGToStringFromMessage.java @@ -0,0 +1,30 @@ +package cc.sukazyo.cono.morny.util.tgapi; + +import cc.sukazyo.untitled.telegram.api.formatting.TGToString; +import cc.sukazyo.untitled.util.telegram.formatting.MsgEscape; +import com.pengrad.telegrambot.model.Message; + +import javax.annotation.Nonnull; + +public class TGToStringFromMessage extends TGToString { + + @Nonnull + private final Message message; + + public TGToStringFromMessage (@Nonnull Message message) { this.message = message; } + public static TGToStringFromMessage as (@Nonnull Message message) { return new TGToStringFromMessage(message); } + + @Nonnull + public String getSenderFirstNameRefHtml () { + return message.senderChat()==null ? TGToString.as(message.from()).firstnameRefHtml() : String.format( + "%s", + message.senderChat().id(), + MsgEscape.escapeHtml(message.senderChat().title()) + ); + } + + public long getSenderId () { + return message.senderChat()==null ? message.from().id() : message.senderChat().id(); + } + +}