diff --git a/gradle.properties b/gradle.properties index 5a613bb..f9896ea 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.7.0.16 +VERSION = 0.7.1.0 CODENAME = fuzhou diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index da03946..b0888fc 100644 --- a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java +++ b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java @@ -4,7 +4,7 @@ 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.16"; + public static final String VERSION = "0.7.1.0"; public static final String CODENAME = "fuzhou"; - public static final long COMPILE_TIMESTAMP = 1654058419036L; + public static final long COMPILE_TIMESTAMP = 1654235503515L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyCommands.java b/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyCommands.java index 1975177..2918a80 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyCommands.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyCommands.java @@ -14,6 +14,7 @@ import com.pengrad.telegrambot.model.request.ParseMode; import com.pengrad.telegrambot.request.SendMessage; import com.pengrad.telegrambot.request.SendSticker; import com.pengrad.telegrambot.request.SetMyCommands; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -60,8 +61,7 @@ public class MornyCommands { register( new ON(), - new Hello(), - new HelloOnStart(), + new Hello(), new HelloOnStart(), new GetUsernameAndId(), new EventHack(), new Nbnhhsh(), @@ -71,7 +71,7 @@ public class MornyCommands { new Version(), new MornyRuntime(), new Jrrp(), - new Exit() + new Exit(), new ExitAlias() ); // 特殊的命令 @@ -197,6 +197,11 @@ public class MornyCommands { @Nonnull @Override public String getDescription () { return "关闭 Bot (仅可信成员)"; } @Override public void execute (@Nonnull InputCommand command, @Nonnull Update event) { onCommandExitExec(event); } } + private static class ExitAlias implements ISimpleCommand { + @Nonnull @Override public String getName () { return "quit"; } + @Nullable @Override public String[] getAliases () { return new String[]{"stop"}; } + @Override public void execute (@NotNull InputCommand command, @NotNull Update event) { onCommandExitExec(event); } + } private static void onCommandExitExec (@Nonnull Update event) { if (MornyCoeur.trustedInstance().isTrusted(event.message().from().id())) { MornyCoeur.extra().exec(new SendSticker( diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnTelegramCommand.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnTelegramCommand.java index 0c632ab..0266cfa 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnTelegramCommand.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnTelegramCommand.java @@ -8,14 +8,19 @@ import com.pengrad.telegrambot.model.Update; import javax.annotation.Nonnull; +import static cc.sukazyo.cono.morny.Log.logger; + public class OnTelegramCommand extends EventListener { @Override public boolean onMessage (@Nonnull Update event) { - if (event.message().text() == null || !event.message().text().startsWith("/")) { + if (event.message().text() == null || !event.message().text().startsWith("/") || event.message().text().startsWith("/ ")) { + logger.debug("not command"); return false; // 检测到非(命令格式)文本,忽略掉命令处理 } final InputCommand command = new InputCommand(event.message().text().substring(1)); + if (!command.getCommand().matches("^\\w+$")) { logger.debug("not command");return false; } + logger.debug("is command"); if (command.getTarget() != null && !MornyCoeur.getUsername().equals(command.getTarget())) { return true; // 检测到命令并非针对 morny,退出整个事件处理链 } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.java index 960ff17..900f387 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.java @@ -41,7 +41,7 @@ public class OnUserSlashAction extends EventListener { final String[] action = CommonCommand.format(text); action[0] = action[0].substring(1); - if (action[0].matches("^[a-zA-Z_]+$")) { + if (action[0].matches("^\\w+(@\\w+)?$")) { return false; // 忽略掉 Telegram 命令格式的输入 } else if (action[0].contains("/")) { return false; // 忽略掉疑似目录格式的输入