From 17c29036b3038b548b6bec13ef07734595f08175 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Sat, 19 Nov 2022 22:48:20 +0800 Subject: [PATCH] add a function "if something?" to OnUserRandoms - and now uses @Deprecated not @SuppressWarnings("unused") to tag those unused event. --- gradle.properties | 2 +- .../cono/morny/bot/event/EventListeners.java | 4 +-- .../morny/bot/event/OnActivityRecord.java | 1 + .../bot/event/OnKuohuanhuanNeedSleep.java | 1 + .../cono/morny/bot/event/OnUserRandoms.java | 25 ++++++------------- 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/gradle.properties b/gradle.properties index d18bae9..aee182c 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-RC3 +VERSION = 1.0.0-RC3.1 USE_DELTA = false VERSION_DELTA = 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 389b037..6f6708b 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 @@ -5,13 +5,13 @@ import cc.sukazyo.cono.morny.bot.api.EventListenerManager; public class EventListeners { public static final OnTelegramCommand COMMANDS_LISTENER = new OnTelegramCommand(); - @SuppressWarnings("unused") public static final OnActivityRecord ACTIVITY_RECORDER = new OnActivityRecord(); +// public static final OnActivityRecord ACTIVITY_RECORDER = new OnActivityRecord(); public static final OnUserSlashAction USER_SLASH_ACTION = new OnUserSlashAction(); public static final OnUpdateTimestampOffsetLock UPDATE_TIMESTAMP_OFFSET_LOCK = new OnUpdateTimestampOffsetLock(); public static final OnInlineQueries INLINE_QUERY = new OnInlineQueries(); public static final OnCallMe CALL_ME = new OnCallMe(); public static final OnEventHackHandle EVENT_HACK_HANDLE = new OnEventHackHandle(); - @SuppressWarnings("unused") static final OnKuohuanhuanNeedSleep KUOHUANHUAN_NEED_SLEEP = new OnKuohuanhuanNeedSleep(); +// static final OnKuohuanhuanNeedSleep KUOHUANHUAN_NEED_SLEEP = new OnKuohuanhuanNeedSleep(); public static final OnUserRandoms USER_RANDOMS = new OnUserRandoms(); public static final OnCallMsgSend CALL_MSG_SEND = new OnCallMsgSend(); public static final OnMedicationNotifyApply MEDICATION_NOTIFY_APPLY = new OnMedicationNotifyApply(); diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnActivityRecord.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnActivityRecord.java index 6b26436..8ad0af4 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnActivityRecord.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnActivityRecord.java @@ -7,6 +7,7 @@ import com.pengrad.telegrambot.model.Update; import javax.annotation.Nonnull; +@Deprecated public class OnActivityRecord extends EventListener { @Override diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnKuohuanhuanNeedSleep.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnKuohuanhuanNeedSleep.java index 41091aa..2a51a67 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnKuohuanhuanNeedSleep.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnKuohuanhuanNeedSleep.java @@ -10,6 +10,7 @@ import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Locale; +@Deprecated public class OnKuohuanhuanNeedSleep extends EventListener { @Override diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserRandoms.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserRandoms.java index 898bdac..79d8a28 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserRandoms.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserRandoms.java @@ -2,7 +2,6 @@ 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.UniversalCommand; import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.request.SendMessage; import org.jetbrains.annotations.NotNull; @@ -13,8 +12,8 @@ import java.util.regex.Pattern; public class OnUserRandoms extends EventListener { - private static final Pattern USER_OR_CN_QUERY = Pattern.compile("(.+)还是(.+)"); - private static final Pattern USER_OR_EN_QUERY = Pattern.compile("(.+)or(.+)"); + private static final Pattern USER_OR_QUERY = Pattern.compile("(.+)(?:还是|or)(.+)"); + private static final Pattern USER_IF_QUERY = Pattern.compile("(.+)[吗?|?]+$"); @Override public boolean onMessage (@NotNull Update update) { @@ -22,24 +21,14 @@ public class OnUserRandoms extends EventListener { if (update.message().text() == null) return false; if (!update.message().text().startsWith("/")) return false; - final String[] preProcess = UniversalCommand.format(update.message().text()); - if (preProcess.length > 1) return false; - final String query = preProcess[0]; - - // ----- START CODE BLOCK COMMENT ----- - // 这里实现思路和代码优化有至少一半是 copilot 和 IDEA 提供的 - // 实现思路都可以从人类手里抢一半贡献太恐怖了aba + final String query = update.message().text().substring(1); String result = null; - final Matcher matcher; - if (query.contains("还是")) { - matcher = USER_OR_CN_QUERY.matcher(query); - } else { - matcher = USER_OR_EN_QUERY.matcher(query); - } - if (matcher.find()) { + Matcher matcher; + if ((matcher = USER_OR_QUERY.matcher(query)).find()) { result = ThreadLocalRandom.current().nextBoolean() ? matcher.group(1) : matcher.group(2); + } else if ((matcher = USER_IF_QUERY.matcher(query)).matches()) { + result = (ThreadLocalRandom.current().nextBoolean()?"":"不") + matcher.group(1); } - // ----- STOP CODE BLOCK COMMENT ----- if (result == null) return false; MornyCoeur.extra().exec(new SendMessage(