From ff428f76b2644e040e5f073462689d140e00fdfd Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Tue, 14 Dec 2021 22:38:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=8B=E4=BB=B6=E5=8A=AB?= =?UTF-8?q?=E6=8C=81=E5=8A=9F=E8=83=BD=E7=9A=84=E5=91=BD=E4=BB=A4=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E6=96=87=E6=9C=AC=E6=9B=B4=E6=94=B9=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B4=B4=E7=BA=B8=E7=AE=A1=E7=90=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加事件劫持与返回命令的事件请求命令 - 添加贴纸管理类集中存放贴纸 id - 修改 runtime 方法中的 memory 字段名为 "vm memory" - 为 runtime 方法, OnInlineQuery 添加 @since 标签 --- gradle.properties | 2 +- .../cono/morny/GradleProjectConfigures.java | 4 +- .../morny/bot/event/OnCommandExecute.java | 28 +++---- .../morny/bot/event/OnEventHackHandle.java | 21 +++++ .../cono/morny/bot/event/OnInlineQuery.java | 3 + .../bot/event/on_commands/EventHack.java | 76 +++++++++++++++++++ .../cono/morny/data/TelegramStickers.java | 16 ++++ 7 files changed, 134 insertions(+), 16 deletions(-) create mode 100644 src/main/java/cc/sukazyo/cono/morny/bot/event/OnEventHackHandle.java create mode 100644 src/main/java/cc/sukazyo/cono/morny/bot/event/on_commands/EventHack.java create mode 100644 src/main/java/cc/sukazyo/cono/morny/data/TelegramStickers.java diff --git a/gradle.properties b/gradle.properties index ad6e88f..67c4c6b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.4.1.3 +VERSION = 0.4.2.0 # dependencies diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index 9000285..04559c8 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.1.3"; - public static final long COMPILE_TIMESTAMP = 1639476313268L; + public static final String VERSION = "0.4.2.0"; + public static final long COMPILE_TIMESTAMP = 1639492714364L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java index d3e6def..5f5da75 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java @@ -6,7 +6,9 @@ import cc.sukazyo.cono.morny.MornySystem; import cc.sukazyo.cono.morny.MornyTrusted; import cc.sukazyo.cono.morny.bot.api.EventListener; import cc.sukazyo.cono.morny.bot.api.InputCommand; +import cc.sukazyo.cono.morny.bot.event.on_commands.EventHack; import cc.sukazyo.cono.morny.bot.event.on_commands.GetUsernameAndId; +import cc.sukazyo.cono.morny.data.TelegramStickers; import cc.sukazyo.cono.morny.util.CommonFormatUtils; import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.model.request.ParseMode; @@ -19,12 +21,6 @@ import static cc.sukazyo.cono.morny.Log.logger; public class OnCommandExecute extends EventListener { - private static final String ONLINE_STATUS_RETURN_STICKER_ID = "CAACAgEAAx0CW-CvvgAC5eBhhhODGRuu0pxKLwoQ3yMsowjviAACcycAAnj8xgVVU666si1utiIE"; - private static final String HELLO_STICKER_ID = "CAACAgEAAxkBAAMnYYYWKNXO4ibo9dlsmDctHhhV6fIAAqooAAJ4_MYFJJhrHS74xUAiBA"; - private static final String EXIT_STICKER_ID = "CAACAgEAAxkBAAMoYYYWt8UjvP0N405SAyvg2SQZmokAAkMiAAJ4_MYFw6yZLu06b-MiBA"; - private static final String EXIT_403_STICKER_ID = "CAACAgEAAxkBAAMqYYYa_7hpXH6hMOYMX4Nh8AVYd74AAnQnAAJ4_MYFRdmmsQKLDZgiBA"; - private static final String NON_COMMAND_QUESTION_STICKER_ID = "CAACAgEAAx0CSQh32gABA966YbRJpbmi2lCHINBDuo1DknSTsbsAAqUoAAJ4_MYFUa8SIaZriAojBA"; - @Override public boolean onMessage (@Nonnull Update event) { if (event.message().text() == null) { @@ -38,6 +34,9 @@ public class OnCommandExecute extends EventListener { case "/user": GetUsernameAndId.exec(command.getArgs(), event); break; + case "/event_hack": + EventHack.exec(event, command); + break; case "/o": onCommandOnExec(event); break; @@ -65,7 +64,7 @@ public class OnCommandExecute extends EventListener { else { // 无法解析的显式命令格式,报错找不到命令 MornyCoeur.getAccount().execute(new SendSticker( event.message().chat().id(), - NON_COMMAND_QUESTION_STICKER_ID + TelegramStickers.ID_404 ).replyToMessageId(event.message().messageId()) ); return true; @@ -75,15 +74,15 @@ public class OnCommandExecute extends EventListener { private void onCommandOnExec (@Nonnull Update event) { MornyCoeur.getAccount().execute(new SendSticker( event.message().chat().id(), - ONLINE_STATUS_RETURN_STICKER_ID + TelegramStickers.ID_ONLINE_STATUS_RETURN ).replyToMessageId(event.message().messageId()) ); } private void onCommandHelloExec (@Nonnull Update event) { MornyCoeur.getAccount().execute(new SendSticker( - event.message().chat().id(), - HELLO_STICKER_ID + event.message().chat().id(), + TelegramStickers.ID_HELLO ).replyToMessageId(event.message().messageId()) ); } @@ -92,7 +91,7 @@ public class OnCommandExecute extends EventListener { if (MornyTrusted.isTrusted(event.message().from().id())) { MornyCoeur.getAccount().execute(new SendSticker( event.message().chat().id(), - EXIT_STICKER_ID + TelegramStickers.ID_EXIT ).replyToMessageId(event.message().messageId()) ); logger.info("Morny exited by user @" + event.message().from().username()); @@ -100,7 +99,7 @@ public class OnCommandExecute extends EventListener { } else { MornyCoeur.getAccount().execute(new SendSticker( event.message().chat().id(), - EXIT_403_STICKER_ID + TelegramStickers.ID_403 ).replyToMessageId(event.message().messageId()) ); logger.info("403 exited tag from user @" + event.message().from().username()); @@ -126,6 +125,9 @@ public class OnCommandExecute extends EventListener { ).replyToMessageId(event.message().messageId()).parseMode(ParseMode.HTML)); } + /** + * @since 0.4.1.2 + */ private void onCommandRuntimeExec (@Nonnull Update event) { MornyCoeur.getAccount().execute(new SendMessage( event.message().chat().id(), @@ -137,7 +139,7 @@ public class OnCommandExecute extends EventListener { java runtime: - %s - %s - memory: + vm memory: - %d / %d MB morny version: - %s diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnEventHackHandle.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnEventHackHandle.java new file mode 100644 index 0000000..3b5f1bc --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnEventHackHandle.java @@ -0,0 +1,21 @@ +package cc.sukazyo.cono.morny.bot.event; + +/** + * @since 0.4.2.0 + */ +public class OnEventHackHandle { + + /** + * @since 0.4.2.0 + */ + public enum HackType { + USER, GROUP, ANY + } + + /** + * @since 0.4.2.0 + */ + public static void registerHack(long fromMessageId, long fromChatId, long fromUserId,HackType type) { + } + +} diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnInlineQuery.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnInlineQuery.java index 6bf189e..5dfd54e 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnInlineQuery.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnInlineQuery.java @@ -11,6 +11,9 @@ import com.pengrad.telegrambot.request.AnswerInlineQuery; import org.jetbrains.annotations.NotNull; /** + * telegram inlineQuery 功能的处理类, + * 也是一个 InlineQueryManager(还没做) + * * @since 0.4.1.3 */ public class OnInlineQuery extends EventListener { 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 new file mode 100644 index 0000000..cd3c6f2 --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/on_commands/EventHack.java @@ -0,0 +1,76 @@ +package cc.sukazyo.cono.morny.bot.event.on_commands; + +import cc.sukazyo.cono.morny.MornyCoeur; +import cc.sukazyo.cono.morny.MornyTrusted; +import cc.sukazyo.cono.morny.bot.api.InputCommand; +import cc.sukazyo.cono.morny.bot.event.OnEventHackHandle; +import cc.sukazyo.cono.morny.data.TelegramStickers; +import com.pengrad.telegrambot.model.Update; +import com.pengrad.telegrambot.request.SendSticker; + +/** + * @since 0.4.2.0 + */ +public class EventHack { + + /** + * @since 0.4.2.0 + */ + public static void exec (Update event, InputCommand command) { + + boolean isOk = false; + + String x_mode = ""; + if (command.hasArgs()) { + x_mode = command.getArgs()[0]; + } + + switch (x_mode) { + case "any": + if (MornyTrusted.isTrusted(event.message().from().id())) { + OnEventHackHandle.registerHack( + event.message().messageId(), + event.message().from().id(), + event.message().chat().id(), + OnEventHackHandle.HackType.ANY + ); + isOk = true; + } + break; + case "group": + OnEventHackHandle.registerHack( + event.message().messageId(), + event.message().from().id(), + event.message().chat().id(), + OnEventHackHandle.HackType.GROUP + ); + isOk = true; + break; + default: + OnEventHackHandle.registerHack( + event.message().messageId(), + event.message().from().id(), + event.message().chat().id(), + OnEventHackHandle.HackType.USER + ); + isOk = true; + break; + } + + if (isOk) { + MornyCoeur.getAccount().execute(new SendSticker( + event.message().chat().id(), + TelegramStickers.ID_WAITING + ).replyToMessageId(event.message().messageId()) + ); + } else { + MornyCoeur.getAccount().execute(new SendSticker( + event.message().chat().id(), + TelegramStickers.ID_403 + ).replyToMessageId(event.message().messageId()) + ); + } + + } + +} diff --git a/src/main/java/cc/sukazyo/cono/morny/data/TelegramStickers.java b/src/main/java/cc/sukazyo/cono/morny/data/TelegramStickers.java new file mode 100644 index 0000000..d4715e1 --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/data/TelegramStickers.java @@ -0,0 +1,16 @@ +package cc.sukazyo.cono.morny.data; + +/** + * 存放 bot 使用到的贴纸 + * @since 0.4.2.0 + */ +public class TelegramStickers { + + public static final String ID_ONLINE_STATUS_RETURN = "CAACAgEAAx0CW-CvvgAC5eBhhhODGRuu0pxKLwoQ3yMsowjviAACcycAAnj8xgVVU666si1utiIE"; + public static final String ID_HELLO = "CAACAgEAAxkBAAMnYYYWKNXO4ibo9dlsmDctHhhV6fIAAqooAAJ4_MYFJJhrHS74xUAiBA"; + public static final String ID_EXIT = "CAACAgEAAxkBAAMoYYYWt8UjvP0N405SAyvg2SQZmokAAkMiAAJ4_MYFw6yZLu06b-MiBA"; + public static final String ID_403 = "CAACAgEAAxkBAAMqYYYa_7hpXH6hMOYMX4Nh8AVYd74AAnQnAAJ4_MYFRdmmsQKLDZgiBA"; + public static final String ID_404 = "CAACAgEAAx0CSQh32gABA966YbRJpbmi2lCHINBDuo1DknSTsbsAAqUoAAJ4_MYFUa8SIaZriAojBA"; + public static final String ID_WAITING = "CAACAgEAAx0CSQh32gABA-8DYbh7W2VhJ490ucfZMUMrgMR2FW4AAm4nAAJ4_MYFjx6zpxJPWsQjBA"; + +}