mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 19:24:53 +08:00
优化对命令格式的检查,为 exit 添加 /quit /stop 隐藏别名
- 在 OnTelegramCommand 的命令格式检查优化,在确定为 telegram command 格式时不会进行下一步执行 - 在 SlashAction 的命令格式检查支持正常检查 @ 后缀
This commit is contained in:
parent
ec05fea942
commit
8b41111a49
@ -1,6 +1,6 @@
|
||||
## Core
|
||||
|
||||
VERSION = 0.7.0.16
|
||||
VERSION = 0.7.1.0
|
||||
|
||||
CODENAME = fuzhou
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -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,退出整个事件处理链
|
||||
}
|
||||
|
@ -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; // 忽略掉疑似目录格式的输入
|
||||
|
Loading…
Reference in New Issue
Block a user