Skip to content

Commit

Permalink
feat: init quick confirm (Teahouse-Studios#1046)
Browse files Browse the repository at this point in the history
Signed-off-by: xtex <xtexchooser@duck.com>
  • Loading branch information
xtexChooser committed Dec 10, 2023
1 parent dea485a commit e57d42d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion core/builtins/message/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/builtins/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion core/builtins/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@


confirm_command = Config('confirm_command', default=["是", "对", "對", "yes", "Yes", "YES", "y", "Y"])
quick_confirm = Config('quick_confirm', default=True)
command_prefix = Config('command_prefix', default=['~', '~']) # 消息前缀


class EnableDirtyWordCheck:
status = False


__all__ = ["confirm_command", "command_prefix", "EnableDirtyWordCheck", "PrivateAssets", "Secret"]
__all__ = ["confirm_command", "quick_confirm", "command_prefix", "EnableDirtyWordCheck", "PrivateAssets", "Secret"]
6 changes: 6 additions & 0 deletions core/types/message/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)。
Expand Down

0 comments on commit e57d42d

Please sign in to comment.