From 574cec609adfbfc46e38bd7f183a94c84a323676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wuyi=E6=97=A0=E7=96=91?= <444835641@qq.com> Date: Wed, 12 Apr 2023 22:07:19 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=96=B0=E5=A2=9E=E5=8F=AF?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=9A=84`command=5Fstart`=20(KimigaiiWuyi/Ge?= =?UTF-8?q?nshinUID#492)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gsuid_core/config.py | 5 +++-- gsuid_core/handler.py | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/gsuid_core/config.py b/gsuid_core/config.py index 8e9bb35..1516e79 100644 --- a/gsuid_core/config.py +++ b/gsuid_core/config.py @@ -9,14 +9,15 @@ CONFIG_DEFAULT = { 'PORT': '8765', 'masters': [], 'superusers': [], - 'sv': {}, 'log': { 'level': 'INFO', # ... }, + 'command_start': [], + 'sv': {}, } STR_CONFIG = Literal['HOST', 'PORT'] -LIST_CONFIG = Literal['superusers', 'masters'] +LIST_CONFIG = Literal['superusers', 'masters', 'command_start'] DICT_CONFIG = Literal['sv', 'log'] diff --git a/gsuid_core/handler.py b/gsuid_core/handler.py index 18b092a..8ef7ece 100644 --- a/gsuid_core/handler.py +++ b/gsuid_core/handler.py @@ -9,6 +9,7 @@ from gsuid_core.trigger import Trigger from gsuid_core.config import core_config from gsuid_core.models import Event, Message, MessageReceive +command_start = core_config.get_config('command_start') config_masters = core_config.get_config('masters') config_superusers = core_config.get_config('superusers') @@ -66,6 +67,15 @@ async def handle_event(ws: _Bot, msg: MessageReceive): user_pm = await get_user_pml(msg) event = await msg_process(msg) logger.info('[收到事件]', event=event) + + if command_start and event.raw_text: + for start in command_start: + if event.raw_text.strip().startswith(start): + event.raw_text = event.raw_text.replace(start, '') + break + else: + return + valid_event: Dict[Trigger, int] = {} pending = [ _check_command( @@ -79,10 +89,8 @@ async def handle_event(ws: _Bot, msg: MessageReceive): if ( SL.lst[sv].enabled and user_pm <= SL.lst[sv].pm - and ( - msg.group_id not in SL.lst[sv].black_list - or msg.user_id not in SL.lst[sv].black_list - ) + and msg.group_id not in SL.lst[sv].black_list + and msg.user_id not in SL.lst[sv].black_list and True if SL.lst[sv].area == 'ALL' or (msg.group_id and SL.lst[sv].area == 'GROUP')