From 12b4c918291da2b43a8796874d3896304f877553 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Wed, 15 Dec 2021 12:06:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=91=BC=E5=8F=AB=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20event=5Fhack=20=E5=91=BD=E4=BB=A4=E4=B8=8E=E5=91=BC=E5=8F=AB?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=9A=84=20javadoc?= 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/OnCallMe.java | 72 ++++++++++++++++--- .../bot/event/on_commands/EventHack.java | 9 +++ .../morny/bot/event/on_commands/Roll.java | 4 ++ 5 files changed, 77 insertions(+), 14 deletions(-) create mode 100644 src/main/java/cc/sukazyo/cono/morny/bot/event/on_commands/Roll.java diff --git a/gradle.properties b/gradle.properties index 2e5218c..5a63cde 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.4.2.1 +VERSION = 0.4.2.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 cff1c8f..53e4adc 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.4.2.1"; - public static final long COMPILE_TIMESTAMP = 1639494688933L; + public static final String VERSION = "0.4.2.2"; + public static final long COMPILE_TIMESTAMP = 1639541150226L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java index db1f20f..608c73b 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java @@ -7,20 +7,32 @@ import cc.sukazyo.cono.morny.data.TelegramStickers; import com.pengrad.telegrambot.model.Chat; import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.model.request.ParseMode; +import com.pengrad.telegrambot.request.ForwardMessage; import com.pengrad.telegrambot.request.SendMessage; import com.pengrad.telegrambot.request.SendSticker; import org.jetbrains.annotations.NotNull; /** + * 通过 bot 呼叫主人的事件监听管理类 * @since 0.4.2.1 */ public class OnCallMe extends EventListener { /** + * 主人的 telegram user id,同时被用于 chat id
+ * 跟随 {@link MornyTrusted#MASTER} 的值 * @since 0.4.2.1 */ private static final long ME = MornyTrusted.MASTER; + /** + * 监听私聊 bot 的消息进行呼叫关键字匹配。 + * 如果成功,将会执行呼叫函数,并向呼叫者回显{@link TelegramStickers#ID_WAITING "已呼叫"贴纸} + * + * @param update 事件基础参数,消息事件所属的 tgapi:update 对象 + * @return 事件基础返回值,是否已完成处理事件:
+ * 如果匹配到呼叫,则返回{@code true},反之返回{@code false} + */ @Override public boolean onMessage (@NotNull Update update) { if (update.message().text() == null) @@ -28,18 +40,17 @@ public class OnCallMe extends EventListener { if (update.message().chat().type() != Chat.Type.Private) return false; switch (update.message().text().toLowerCase()) { - case "steam": - case "sbeam": - case "sdeam": - requestSteamJoin(update); - break; - case "hana paresu": - case "花宫": - case "内群": - requestHanaParesuJoin(update); - break; - default: + case "steam", "sbeam", "sdeam" -> + requestSteamJoin(update); + case "hana paresu", "花宫", "内群" -> + requestHanaParesuJoin(update); + default -> { + if (update.message().text().startsWith("cc::")) { + requestCustomCall(update); + break; + } return false; + } } MornyCoeur.getAccount().execute(new SendSticker( update.message().chat().id(), @@ -49,6 +60,12 @@ public class OnCallMe extends EventListener { return true; } + /** + * 执行 steam library 呼叫
+ * 将会向 {@link #ME} 发送 + * + * @param event 执行呼叫的tg事件 + */ private static void requestSteamJoin (Update event) { MornyCoeur.getAccount().execute(new SendMessage( ME, String.format(""" @@ -60,6 +77,12 @@ public class OnCallMe extends EventListener { ).parseMode(ParseMode.HTML)); } + /** + * 执行花宫呼叫
+ * 将会向 {@link #ME} 发送 + * + * @param event 执行呼叫的tg事件 + */ private static void requestHanaParesuJoin (Update event) { MornyCoeur.getAccount().execute(new SendMessage( ME, String.format(""" @@ -71,4 +94,31 @@ public class OnCallMe extends EventListener { ).parseMode(ParseMode.HTML)); } + /** + * 执行自定义呼叫
+ * 将会向 {@link #ME} 发送一个 request 数据消息和转发的原始请求消息
+ *
+ * known issue + * + * @param event 执行呼叫的tg事件 + * @since 0.4.2.2 + */ + private static void requestCustomCall (Update event) { + MornyCoeur.getAccount().execute(new SendMessage( + ME, String.format(""" + request [???] + from %s""", + event.message().from().id(), + event.message().from().firstName() + " " + event.message().from().lastName() + ) + ).parseMode(ParseMode.HTML)); + MornyCoeur.getAccount().execute(new ForwardMessage( + ME, + event.message().chat().id(), + event.message().messageId() + )); + } + } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/on_commands/EventHack.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/on_commands/EventHack.java index cd3c6f2..0df037a 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/on_commands/EventHack.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/on_commands/EventHack.java @@ -9,11 +9,20 @@ import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.request.SendSticker; /** + * {@link OnEventHackHandle} 的命令行前端 * @since 0.4.2.0 */ public class EventHack { /** + * {@link OnEventHackHandle} 的命令行前端
+ *
+ * 实现了通过命令行进行 EventHack 功能。
+ * 支持三种模式,默认为 {@link OnEventHackHandle.HackType#USER USER}, + * {@link OnEventHackHandle.HackType#ANY ANY} 时,将会通过 {@link MornyTrusted#isTrusted(long)} 检查触发用户的权限 + * + * @param event 命令基础参数,触发的事件对象本身 + * @param command 命令基础参数,解析出的命令对象 * @since 0.4.2.0 */ public static void exec (Update event, InputCommand command) { diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/on_commands/Roll.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/on_commands/Roll.java new file mode 100644 index 0000000..4cb209a --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/on_commands/Roll.java @@ -0,0 +1,4 @@ +package cc.sukazyo.cono.morny.bot.event.on_commands; + +public class Roll { +}