From 0f8b85c7f9fbc021c76c4aacca5e541a372e2cda Mon Sep 17 00:00:00 2001 From: xtex Date: Sun, 10 Dec 2023 11:09:18 +0800 Subject: [PATCH] feat: init quick confirm (#1046) Signed-off-by: xtex --- config/config.toml.example | 1 + core/builtins/message/__init__.py | 4 +++- core/builtins/tasks.py | 2 +- core/builtins/utils/__init__.py | 3 ++- core/types/message/__init__.py | 6 ++++++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/config/config.toml.example b/config/config.toml.example index c836126b60..fe3c2a7cfb 100644 --- a/config/config.toml.example +++ b/config/config.toml.example @@ -31,6 +31,7 @@ debug = false cache_path = "./cache/" command_prefix = ["~", "~",] confirm_command = ["是", "对", "對", "yes", "Yes", "YES", "y", "Y",] +quick_confirm = true disabled_bots = locale = "zh_cn" timezone_offset = "+8" diff --git a/core/builtins/message/__init__.py b/core/builtins/message/__init__.py index 56473e77e6..37a8646b84 100644 --- a/core/builtins/message/__init__.py +++ b/core/builtins/message/__init__.py @@ -7,7 +7,7 @@ from core.builtins.message.internal import * from core.builtins.tasks import MessageTaskManager from core.builtins.temp import ExecutionLockList -from core.builtins.utils import confirm_command +from core.builtins.utils import confirm_command, quick_confirm from core.exceptions import WaitCancelException from core.types.message import MessageSession as MessageSessionT, MsgInfo, Session from core.utils.i18n import Locale @@ -52,6 +52,8 @@ async def wait_confirm(self, message_chain=None, quote=True, delete=True, append await send.delete() if result.as_display(text_only=True) in confirm_command: return True + if quick_confirm and result.is_quick_confirm(): + return True return False else: raise WaitCancelException diff --git a/core/builtins/tasks.py b/core/builtins/tasks.py index 57cac4424f..2a2a12683e 100644 --- a/core/builtins/tasks.py +++ b/core/builtins/tasks.py @@ -23,7 +23,7 @@ def add_task(cls, session: MessageSession, flag, all_=False, reply=None): Logger.debug(cls._list) @classmethod - def get_result(cls, session: MessageSession): + def get_result(cls, session: MessageSession) -> MessageSession: if 'result' in cls._list[session.target.target_id][session.target.sender_id][session]: return cls._list[session.target.target_id][session.target.sender_id][session]['result'] else: diff --git a/core/builtins/utils/__init__.py b/core/builtins/utils/__init__.py index 895a396c05..eb36408bae 100644 --- a/core/builtins/utils/__init__.py +++ b/core/builtins/utils/__init__.py @@ -3,6 +3,7 @@ confirm_command = Config('confirm_command', default=["是", "对", "對", "yes", "Yes", "YES", "y", "Y"]) +quick_confirm = Config('quick_confirm', default=True) command_prefix = Config('command_prefix', default=['~', '~']) # 消息前缀 @@ -10,4 +11,4 @@ class EnableDirtyWordCheck: status = False -__all__ = ["confirm_command", "command_prefix", "EnableDirtyWordCheck", "PrivateAssets", "Secret"] +__all__ = ["confirm_command", "quick_confirm", "command_prefix", "EnableDirtyWordCheck", "PrivateAssets", "Secret"] diff --git a/core/types/message/__init__.py b/core/types/message/__init__.py index bb24b16a1b..f8605a6668 100644 --- a/core/types/message/__init__.py +++ b/core/types/message/__init__.py @@ -201,6 +201,12 @@ async def check_native_permission(self): """ raise NotImplementedError + def is_quick_confirm(self) -> bool: + """ + 用于检查消息是否可用作快速确认事件。 + """ + return False + async def fake_forward_msg(self, nodelist): """ 用于发送假转发消息(QQ)。