From fbbfe73ac12cb72807c447b85109cb438d332785 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Fri, 11 Nov 2022 18:32:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=20"meow-set"=20?= =?UTF-8?q?=E9=83=A8=E5=88=86=E7=9A=84=E6=96=87=E6=A1=88=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E4=B8=BA=E5=85=B6=E6=B7=BB=E5=8A=A0=E4=BA=86=E7=89=B9=E5=BC=82?= =?UTF-8?q?=E5=8C=96=E5=9B=9E=E5=A4=8D=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=B6=E4=BB=A5=E5=8F=8A=20--report-to=20?= =?UTF-8?q?=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复了上次提交的 --report-to 参数没有被正确处理问题 - 创建了一个新的补丁事件,修复了 meow-set 无法使用的问题 --- gradle.properties | 2 +- .../cc/sukazyo/cono/morny/ServerMain.java | 1 + .../cono/morny/bot/command/MornyCommands.java | 10 +++-- .../sukazyo/cono/morny/bot/command/喵呜.java | 40 +++++++++++-------- .../cono/morny/bot/event/EventListeners.java | 2 + .../morny/bot/event/OnUniMeowTrigger.java | 36 +++++++++++++++++ 6 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 src/main/java/cc/sukazyo/cono/morny/bot/event/OnUniMeowTrigger.java diff --git a/gradle.properties b/gradle.properties index d8d160f..50b2c53 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ MORNY_ARCHIVE_NAME = morny-coeur MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s -VERSION = 1.0.0-alpha6 +VERSION = 1.0.0-beta1 USE_DELTA = false VERSION_DELTA = diff --git a/src/main/java/cc/sukazyo/cono/morny/ServerMain.java b/src/main/java/cc/sukazyo/cono/morny/ServerMain.java index 6707185..e9237ee 100644 --- a/src/main/java/cc/sukazyo/cono/morny/ServerMain.java +++ b/src/main/java/cc/sukazyo/cono/morny/ServerMain.java @@ -162,6 +162,7 @@ public class ServerMain { continue; } case "--report-to" -> { + i++; config.reportToChat = Long.parseLong(args[i]); continue; } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyCommands.java b/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyCommands.java index 9ad3087..e50db1b 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyCommands.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyCommands.java @@ -3,6 +3,7 @@ package cc.sukazyo.cono.morny.bot.command; import cc.sukazyo.cono.morny.BuildConfig; import cc.sukazyo.cono.morny.MornyCoeur; import cc.sukazyo.cono.morny.MornySystem; +import cc.sukazyo.cono.morny.bot.event.OnUniMeowTrigger; import cc.sukazyo.cono.morny.daemon.MornyReport; import cc.sukazyo.cono.morny.data.MornyJrrp; import cc.sukazyo.cono.morny.data.TelegramStickers; @@ -83,12 +84,15 @@ public class MornyCommands { // 统一注册这些奇怪的东西&.& register( + new 私わね(), + new 喵呜.Progynova() + ); + // special: 注册出于兼容使用的特别 event 的数据 + OnUniMeowTrigger.register( new 喵呜.抱抱(), new 喵呜.揉揉(), new 喵呜.蹭蹭(), - new 喵呜.贴贴(), - new 私わね(), - new 喵呜.Progynova() + new 喵呜.贴贴() ); } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/command/喵呜.java b/src/main/java/cc/sukazyo/cono/morny/bot/command/喵呜.java index 2bdbb7d..692ce2a 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/command/喵呜.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/command/喵呜.java @@ -3,6 +3,7 @@ package cc.sukazyo.cono.morny.bot.command; import cc.sukazyo.cono.morny.MornyCoeur; import cc.sukazyo.cono.morny.data.TelegramStickers; import cc.sukazyo.cono.morny.util.tgapi.InputCommand; +import com.pengrad.telegrambot.model.Message; import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.model.request.ParseMode; import com.pengrad.telegrambot.request.SendMessage; @@ -11,6 +12,16 @@ import com.pengrad.telegrambot.request.SendSticker; import javax.annotation.Nonnull; import javax.annotation.Nullable; +/** + * WARNING that {@link cc.sukazyo.cono.morny.bot.event.OnTelegramCommand} + * 并不能够处理非 english word 字符之外的命令. + *

+ * 出于这个限制,以下几个命令目前都无法使用 + * @see 抱抱 + * @see 揉揉 + * @see 蹭蹭 + * @see 贴贴 + */ @SuppressWarnings("NonAsciiCharacters") public class 喵呜 { @@ -18,10 +29,7 @@ public class 喵呜 { @Nonnull @Override public String getName () { return "抱抱"; } @Nullable @Override public String[] getAliases () { return new String[0]; } @Override public void execute (@Nonnull InputCommand command, @Nonnull Update event) { - MornyCoeur.extra().exec(new SendMessage( - event.message().chat().id(), - "抱抱——" - )); + replyingSet(event, "抱抱", "抱抱"); } } @@ -29,10 +37,7 @@ public class 喵呜 { @Nonnull @Override public String getName () { return "揉揉"; } @Nullable @Override public String[] getAliases () { return new String[0]; } @Override public void execute (@Nonnull InputCommand command, @Nonnull Update event) { - MornyCoeur.extra().exec(new SendMessage( - event.message().chat().id(), - "蹭蹭w" - )); + replyingSet(event, "蹭蹭", "摸摸"); } } @@ -40,10 +45,7 @@ public class 喵呜 { @Nonnull @Override public String getName () { return "蹭蹭"; } @Nullable @Override public String[] getAliases () { return new String[0]; } @Override public void execute (@Nonnull InputCommand command, @Nonnull Update event) { - MornyCoeur.extra().exec(new SendMessage( - event.message().chat().id(), - "喵呜~-" - )); + replyingSet(event, "揉揉", "蹭蹭"); } } @@ -51,13 +53,19 @@ public class 喵呜 { @Nonnull @Override public String getName () { return "贴贴"; } @Nullable @Override public String[] getAliases () { return new String[0]; } @Override public void execute (@Nonnull InputCommand command, @Nonnull Update event) { - MornyCoeur.extra().exec(new SendMessage( - event.message().chat().id(), - "(贴贴喵呜&.&)" - ).parseMode(ParseMode.HTML)); + replyingSet(event, "贴贴", "贴贴"); } } + private static void replyingSet (@Nonnull Update event, @Nonnull String whileRec, @Nonnull String whileNew) { + final boolean isNew = event.message().replyToMessage() == null; + final Message target = isNew ? event.message() : event.message().replyToMessage(); + MornyCoeur.extra().exec(new SendMessage( + event.message().chat().id(), + isNew ? whileNew : whileRec + ).replyToMessageId(target.messageId()).parseMode(ParseMode.HTML)); + } + public static class Progynova implements ITelegramCommand { @Nonnull @Override public String getName () { return "install"; } @Nullable @Override public String[] getAliases () { return new String[0]; } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/EventListeners.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/EventListeners.java index 7b165f9..389b037 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/EventListeners.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/EventListeners.java @@ -16,6 +16,7 @@ public class EventListeners { public static final OnCallMsgSend CALL_MSG_SEND = new OnCallMsgSend(); public static final OnMedicationNotifyApply MEDICATION_NOTIFY_APPLY = new OnMedicationNotifyApply(); public static final OnRandomlyTriggered RANDOMLY_TRIGGERED = new OnRandomlyTriggered(); + public static final OnUniMeowTrigger UNI_MEOW_TRIGGER = new OnUniMeowTrigger(); public static void registerAllListeners () { EventListenerManager.addListener( @@ -24,6 +25,7 @@ public class EventListeners { /* write functional event behind here */ // KUOHUANHUAN_NEED_SLEEP, COMMANDS_LISTENER, + UNI_MEOW_TRIGGER, RANDOMLY_TRIGGERED, USER_RANDOMS, USER_SLASH_ACTION, diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUniMeowTrigger.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUniMeowTrigger.java new file mode 100644 index 0000000..59e8be1 --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUniMeowTrigger.java @@ -0,0 +1,36 @@ +package cc.sukazyo.cono.morny.bot.event; + +import cc.sukazyo.cono.morny.bot.api.EventListener; +import cc.sukazyo.cono.morny.bot.command.ISimpleCommand; +import cc.sukazyo.cono.morny.util.tgapi.InputCommand; +import com.pengrad.telegrambot.model.Update; + +import javax.annotation.Nonnull; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; + +public class OnUniMeowTrigger extends EventListener { + + private static final Map triggers = new HashMap<>(); + + public static void register (ISimpleCommand... list) { + for (ISimpleCommand cmd : list) + triggers.put(cmd.getName(), cmd); + } + + @Override + public boolean onMessage (@Nonnull Update event) { + if (event.message().text() == null) return false; + AtomicBoolean ok = new AtomicBoolean(false); + triggers.forEach((name, command) -> { + name = "/" + name; + if (name.equals(event.message().text())) { + command.execute(new InputCommand(name), event); + ok.set(true); + } + }); + return ok.get(); + } + +}