diff --git a/gsuid_core/client.py b/gsuid_core/client.py index 510725a..4ccc7ec 100644 --- a/gsuid_core/client.py +++ b/gsuid_core/client.py @@ -48,7 +48,7 @@ class GsClient: user_type='direct', user_pm=2, group_id=None, - user_id='51', + user_id='511', content=content, ) msg_send = msgjson.encode(msg) diff --git a/gsuid_core/core.py b/gsuid_core/core.py index 52addd8..f3c06a9 100644 --- a/gsuid_core/core.py +++ b/gsuid_core/core.py @@ -71,7 +71,15 @@ def main(): if name in SL.lst: sv = SL.lst[name] data['pm'] = int(data['pm']) + data['black_list'] = data['black_list'].replace(';', ';') + data['white_list'] = data['white_list'].replace(';', ';') + data['black_list'] = data['black_list'].split(';') + data['white_list'] = data['white_list'].split(';') + if data['black_list'] == ['']: + data['black_list'] = [] + if data['white_list'] == ['']: + data['white_list'] = [] sv.set(**data) @app.post('/genshinuid/setGsConfig') diff --git a/gsuid_core/handler.py b/gsuid_core/handler.py index 1acf406..702dea9 100644 --- a/gsuid_core/handler.py +++ b/gsuid_core/handler.py @@ -91,11 +91,21 @@ async def handle_event(ws: _Bot, msg: MessageReceive): and user_pm <= SL.lst[sv].pm 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') - or (not msg.group_id and SL.lst[sv].area == 'DIRECT') - else False + and ( + True + if SL.lst[sv].area == 'ALL' + or (msg.group_id and SL.lst[sv].area == 'GROUP') + or (not msg.group_id and SL.lst[sv].area == 'DIRECT') + else False + ) + and ( + True + if (not SL.lst[sv].white_list or SL.lst[sv].white_list == ['']) + else ( + msg.user_id in SL.lst[sv].white_list + or msg.group_id in SL.lst[sv].white_list + ) + ) ) ] await asyncio.gather(*pending, return_exceptions=True) diff --git a/gsuid_core/sv.py b/gsuid_core/sv.py index 59db3ec..85f1039 100644 --- a/gsuid_core/sv.py +++ b/gsuid_core/sv.py @@ -49,6 +49,7 @@ class SV: enabled: bool = True, area: Literal['GROUP', 'DIRECT', 'ALL'] = 'ALL', black_list: List = [], + white_list: List = [], ): if not self.is_initialized: logger.info(f'【{name}】模块初始化中...') @@ -65,6 +66,11 @@ class SV: self.pm = config_sv[name]['pm'] self.black_list = config_sv[name]['black_list'] self.area = config_sv[name]['area'] + if 'white_list' not in config_sv[name]: + self.white_list = white_list + self.set(white_list=white_list) + else: + self.white_list = config_sv[name]['white_list'] else: # sv优先级 self.priority = priority @@ -76,6 +82,7 @@ class SV: self.pm = pm # 作用范围 self.area = area + self.white_list = white_list # 写入 self.set( priority=priority, @@ -83,6 +90,7 @@ class SV: pm=pm, black_list=black_list, area=area, + white_list=white_list, ) if name == '测试开关': diff --git a/gsuid_core/webconsole/create_sv_panel.py b/gsuid_core/webconsole/create_sv_panel.py index e183bc2..543b7ac 100644 --- a/gsuid_core/webconsole/create_sv_panel.py +++ b/gsuid_core/webconsole/create_sv_panel.py @@ -10,6 +10,7 @@ def get_sv_panel( enabled: bool = True, area: Literal['GROUP', 'DIRECT', 'ALL'] = 'ALL', black_list: List = [], + white_list: List = [], ): api = f'/genshinuid/setSV/{name}' card = { @@ -230,6 +231,33 @@ def get_sv_panel( 'id': 'u:a7b2f1bbc0a8', 'label': '', }, + { + 'type': 'flex', + 'className': 'p-1', + 'items': [ + { + 'type': 'container', + 'size': 'xs', + 'body': [ + { + 'type': 'input-text', + 'label': '白名单(以;为分割)', + 'name': 'white_list', + 'id': 'u:ab168d425936', + 'value': ';'.join(white_list), + } + ], + 'wrapperBody': False, + 'style': {'flex': '0 0 auto', 'display': 'block'}, + 'id': 'u:48c938f71548', + } + ], + 'direction': 'column', + 'justify': 'center', + 'alignItems': 'stretch', + 'id': 'u:a7b2f1bbc0a8', + 'label': '', + }, ], 'actions': [ { @@ -282,6 +310,7 @@ def get_sv_page(): sv.enabled, sv.area, # type:ignore sv.black_list, + sv.white_list, ) page['body'].append(panel)