From f990df70ea2eab61a2198feae06b93b7c9ee08a2 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Sat, 24 Dec 2022 23:18:49 +0800 Subject: [PATCH] /nbnhhsh will send 404 while no content, add some javadoc --- gradle.properties | 2 +- src/main/java/cc/sukazyo/cono/morny/Log.java | 6 ++++++ .../cc/sukazyo/cono/morny/bot/command/Nbnhhsh.java | 14 ++++++++++++-- .../cono/morny/bot/command/package-info.java | 7 +++++++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 src/main/java/cc/sukazyo/cono/morny/bot/command/package-info.java diff --git a/gradle.properties b/gradle.properties index f3bdb84..c80d4ad 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.3 +VERSION = 1.0.0-RC3.4 USE_DELTA = false VERSION_DELTA = diff --git a/src/main/java/cc/sukazyo/cono/morny/Log.java b/src/main/java/cc/sukazyo/cono/morny/Log.java index f4d1ea4..b9e0e83 100644 --- a/src/main/java/cc/sukazyo/cono/morny/Log.java +++ b/src/main/java/cc/sukazyo/cono/morny/Log.java @@ -18,6 +18,12 @@ public class Log { */ public static final Logger logger = new Logger(new ConsoleAppender()); + /** + * 获取异常的堆栈信息. + * @param e 异常体 + * @return {@link String} 格式的异常的堆栈报告信息. + * @see 1.0.0-alpha5 + */ public static String exceptionLog (Exception e) { final StringWriter stackTrace = new StringWriter(); e.printStackTrace(new PrintWriter(stackTrace)); diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/command/Nbnhhsh.java b/src/main/java/cc/sukazyo/cono/morny/bot/command/Nbnhhsh.java index 22e87cc..20adb23 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/command/Nbnhhsh.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/command/Nbnhhsh.java @@ -1,5 +1,6 @@ package cc.sukazyo.cono.morny.bot.command; +import cc.sukazyo.cono.morny.data.TelegramStickers; import cc.sukazyo.cono.morny.util.tgapi.InputCommand; import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.model.request.ParseMode; @@ -7,6 +8,7 @@ import com.pengrad.telegrambot.request.SendMessage; import cc.sukazyo.cono.morny.MornyCoeur; import cc.sukazyo.cono.morny.data.NbnhhshQuery; +import com.pengrad.telegrambot.request.SendSticker; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -24,13 +26,17 @@ public class Nbnhhsh implements ITelegramCommand { @Override public void execute (@Nonnull InputCommand command, @Nonnull Update event) { + class TagNoContent extends Exception {} try { - String queryTarget = ""; + String queryTarget; if (event.message().replyToMessage() != null && event.message().replyToMessage().text() != null) queryTarget = event.message().replyToMessage().text(); - if (command.hasArgs()) + else if (command.hasArgs()) queryTarget = stringsConnecting(command.getArgs(), " ", 0, command.getArgs().length-1); + else { + throw new TagNoContent(); + } NbnhhshQuery.GuessResult response = NbnhhshQuery.sendGuess(queryTarget); @@ -58,6 +64,10 @@ public class Nbnhhsh implements ITelegramCommand { message.toString() ).parseMode(ParseMode.HTML).replyToMessageId(event.message().messageId())); + } catch (TagNoContent tag) { + MornyCoeur.extra().exec(new SendSticker( + event.message().chat().id(), TelegramStickers.ID_404 + ).replyToMessageId(event.message().messageId())); } catch (Exception e) { MornyCoeur.extra().exec(new SendMessage( event.message().chat().id(), diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/command/package-info.java b/src/main/java/cc/sukazyo/cono/morny/bot/command/package-info.java new file mode 100644 index 0000000..a2d0379 --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/bot/command/package-info.java @@ -0,0 +1,7 @@ +/** + * 一系列的 telegram bot 命令的声明. + *

+ * 命令将在 {@link cc.sukazyo.cono.morny.bot.command.MornyCommands} 当中实例化并注册管理,并通过事件 + * {@link cc.sukazyo.cono.morny.bot.event.OnTelegramCommand} 调用. + */ +package cc.sukazyo.cono.morny.bot.command;