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(); + } + +}