From ce53e70dfa3be62a6790684cd3015f603d39ca55 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Wed, 16 Mar 2022 17:51:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20XXX=E8=BF=98=E6=98=AFXXX?= =?UTF-8?q?=20=E7=9A=84=E5=8A=9F=E8=83=BD=20=E9=80=9A=E8=BF=87=E6=96=9C?= =?UTF-8?q?=E7=BA=BF=E5=89=8D=E7=BC=80=E8=A7=A6=E5=8F=91=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../cono/morny/GradleProjectConfigures.java | 4 +- .../cono/morny/bot/event/EventListeners.java | 2 + .../cono/morny/bot/event/OnUserRandoms.java | 48 +++++++++++++++++++ 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserRandoms.java diff --git a/gradle.properties b/gradle.properties index 92502e9..8213035 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.7.0.1 +VERSION = 0.7.0.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 c8c9109..b1abc49 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.7.0.1"; - public static final long COMPILE_TIMESTAMP = 1647424091182L; + public static final String VERSION = "0.7.0.2"; + public static final long COMPILE_TIMESTAMP = 1647451512009L; } 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 4eca5a5..2f62796 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 @@ -12,6 +12,7 @@ public class EventListeners { public static final OnCallMe CALL_ME = new OnCallMe(); public static final OnEventHackHandle EVENT_HACK_HANDLE = new OnEventHackHandle(); public static final OnKuohuanhuanNeedSleep KUOHUANHUAN_NEED_SLEEP = new OnKuohuanhuanNeedSleep(); + public static final OnUserRandoms USER_RANDOMS = new OnUserRandoms(); public static void registerAllListeners () { EventListenerManager.addListener( @@ -19,6 +20,7 @@ public class EventListeners { UPDATE_TIMESTAMP_OFFSET_LOCK, KUOHUANHUAN_NEED_SLEEP, COMMANDS_LISTENER, + USER_RANDOMS, USER_SLASH_ACTION, INLINE_QUERY, CALL_ME, 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 new file mode 100644 index 0000000..cd90b67 --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserRandoms.java @@ -0,0 +1,48 @@ +package cc.sukazyo.cono.morny.bot.event; + +import cc.sukazyo.cono.morny.MornyCoeur; +import cc.sukazyo.cono.morny.bot.api.EventListener; +import cc.sukazyo.untitled.util.command.CommonCommand; +import com.pengrad.telegrambot.model.Update; +import com.pengrad.telegrambot.request.SendMessage; +import org.jetbrains.annotations.NotNull; + +import java.util.concurrent.ThreadLocalRandom; +import java.util.regex.Matcher; +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(.+)"); + + @Override + public boolean onMessage (@NotNull Update update) { + + if (update.message().text() == null) return false; + if (!update.message().text().startsWith("/")) return false; + + final String[] preProcess = CommonCommand.format(update.message().text()); + if (preProcess.length > 1) return false; + final String query = preProcess[0]; + + 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()) { + result = ThreadLocalRandom.current().nextBoolean() ? matcher.group(1) : matcher.group(2); + } + + if (result == null) return false; + MornyCoeur.extra().exec(new SendMessage( + update.message().chat().id(), result + ).replyToMessageId(update.message().messageId())); + return true; + + } + +}