diff --git a/gsuid_core/config.py b/gsuid_core/config.py index 6da05ed..40fa337 100644 --- a/gsuid_core/config.py +++ b/gsuid_core/config.py @@ -37,7 +37,9 @@ plugins_sample = { 'black_list': [], 'white_list': [], 'prefix': [], - 'allow_empty_prefix': True, + 'force_prefix': [], + 'disable_force_prefix': False, + 'allow_empty_prefix': None, 'sv': {}, } diff --git a/gsuid_core/sv.py b/gsuid_core/sv.py index 54058a7..b6f1c82 100644 --- a/gsuid_core/sv.py +++ b/gsuid_core/sv.py @@ -70,7 +70,16 @@ class Plugins: return _plugin def __hash__(self) -> int: - return hash(f'{self.name}{self.pm}{self.area}') + return hash(f'{self.name}{self.priority}{self.pm}{self.area}') + + def __eq__(self, other): + if isinstance(other, Plugins): + return (self.name, self.pm, self.priority) == ( + other.name, + other.pm, + other.priority, + ) + return False def __init__( self, @@ -83,6 +92,8 @@ class Plugins: white_list: List = [], sv: Dict = {}, prefix: Union[List[str], str] = [], + force_prefix: List[str] = [], + disable_force_prefix: bool = False, allow_empty_prefix: Optional[bool] = None, force: bool = False, ): @@ -107,6 +118,8 @@ class Plugins: self.sv = {} self.prefix = prefix self.allow_empty_prefix = allow_empty_prefix + self.force_prefix = force_prefix + self.disable_force_prefix = disable_force_prefix self.is_initialized = True def set(self, **kwargs): @@ -206,6 +219,16 @@ class SV: 'allow_empty_prefix' ] = None + if 'disable_force_prefix' not in config_plugins[plugins_name]: + config_plugins[plugins_name][ + 'disable_force_prefix' + ] = False + + if plugins_name in SL.plugins: + config_plugins[plugins_name]['force_prefix'] = SL.plugins[ + plugins_name + ].force_prefix + plugins = Plugins( **config_plugins[plugins_name], force=True, @@ -317,6 +340,10 @@ class SV: if self.plugins.allow_empty_prefix: _pp.append("") + if not self.plugins.disable_force_prefix: + for _i in self.plugins.force_prefix: + _pp.append(_i) + for _k in keyword_list: if prefix and _pp: for _p in _pp: diff --git a/gsuid_core/web_app.py b/gsuid_core/web_app.py index cd4a2fa..ca94379 100644 --- a/gsuid_core/web_app.py +++ b/gsuid_core/web_app.py @@ -89,6 +89,8 @@ def _set_Plugins(request: Request, data: Dict, name: str): plguin = SL.plugins[name] data['pm'] = int(data['pm']) data['priority'] = int(data['priority']) + if 'prefix' in data: + data['prefix'] = data['prefix'].split(',') data['black_list'] = data['black_list'].split(',') data['white_list'] = data['white_list'].split(',') diff --git a/gsuid_core/webconsole/create_sv_panel.py b/gsuid_core/webconsole/create_sv_panel.py index a358dd7..fdaec41 100644 --- a/gsuid_core/webconsole/create_sv_panel.py +++ b/gsuid_core/webconsole/create_sv_panel.py @@ -21,6 +21,9 @@ def get_sv_panel( area: Literal['GROUP', 'DIRECT', 'ALL'] = 'ALL', black_list: List = [], white_list: List = [], + prefix: List = [], + disable_force_prefix: bool = False, + allow_empty_prefix: bool = False, ): api = f'{API}/{name}' @@ -32,243 +35,326 @@ def get_sv_panel( if API == '/genshinuid/setPlugins': area_options.append({'label': '按照服务设定', 'value': 'SV'}) + extra = { + 'type': 'flex', + 'className': 'p-1', + 'items': [ + { + 'type': 'container', + 'body': [ + get_input_tag('自定义插件前缀', 'prefix', prefix, []), + ], + 'size': 'xs', + 'style': { + 'position': 'static', + 'display': 'block', + 'flex': '1 1 auto', + 'flexGrow': 1, + 'flexBasis': 'auto', + }, + 'wrapperBody': False, + 'isFixedHeight': False, + 'isFixedWidth': False, + 'id': 'u:bafbdfce89c3', + }, + { + 'type': 'container', + 'body': [ + { + 'type': 'switch', + 'label': '是否禁用插件自带前缀', + 'option': '开启/关闭功能', + 'name': 'allow_empty_prefix', + 'falseValue': False, + 'trueValue': True, + 'id': 'u:d739bc85f366', + 'value': disable_force_prefix, + }, + ], + 'size': 'xs', + 'style': { + 'position': 'static', + 'display': 'block', + 'flex': '1 1 auto', + 'flexGrow': 1, + 'flexBasis': 'auto', + }, + 'wrapperBody': False, + 'isFixedHeight': False, + 'isFixedWidth': False, + 'id': 'u:80670a4807f5', + }, + { + 'type': 'container', + 'body': [ + { + 'type': 'switch', + 'label': '是否允许空前缀', + 'option': '开启/关闭功能', + 'name': 'allow_empty_prefix', + 'falseValue': False, + 'trueValue': True, + 'id': 'u:d739bc85f359', + 'value': allow_empty_prefix, + }, + ], + 'size': 'xs', + 'style': { + 'position': 'static', + 'display': 'block', + 'flex': '1 1 auto', + 'flexGrow': 1, + 'flexBasis': 'auto', + }, + 'wrapperBody': False, + 'isFixedHeight': False, + 'isFixedWidth': False, + 'id': 'u:80670a4807f2', + }, + ], + 'style': {'position': 'static'}, + 'direction': 'row', + 'justify': 'flex-start', + 'alignItems': 'stretch', + 'id': 'u:2a2b198f141b', + 'label': '', + } + + switch = { + 'type': 'flex', + 'className': 'p-1', + 'items': [ + { + 'type': 'container', + 'size': 'xs', + 'style': { + 'position': 'static', + 'display': 'block', + 'flex': '1 1 auto', + 'flexGrow': 1, + 'flexBasis': 'auto', + }, + 'wrapperBody': False, + 'isFixedHeight': False, + 'isFixedWidth': False, + 'id': 'u:bafbdfce89c2', + 'body': [ + { + 'type': 'tpl', + 'tpl': name, + 'inline': True, + 'wrapperComponent': '', + 'id': 'u:cd523cbd8f0c', + 'style': { + 'fontFamily': '', + 'fontSize': 25, + }, + }, + { + 'type': 'switch', + 'label': '总开关', + 'option': '开启/关闭功能', + 'name': 'enabled', + 'falseValue': False, + 'trueValue': True, + 'id': 'u:d739bc85f307', + 'value': enabled, + }, + ], + }, + { + 'type': 'container', + 'size': 'xs', + 'style': { + 'position': 'static', + 'display': 'block', + 'flex': '1 1 auto', + 'flexGrow': 1, + 'flexBasis': 'auto', + }, + 'wrapperBody': False, + 'isFixedHeight': False, + 'isFixedWidth': False, + 'id': 'u:80670a4807f2', + }, + { + 'type': 'container', + 'body': [], + 'size': 'xs', + 'style': { + 'position': 'static', + 'display': 'block', + 'flex': '1 1 auto', + 'flexGrow': 1, + 'flexBasis': 'auto', + }, + 'wrapperBody': False, + 'isFixedHeight': False, + 'isFixedWidth': False, + 'id': 'u:f24811f21e93', + }, + ], + 'style': {'position': 'static'}, + 'direction': 'row', + 'justify': 'flex-start', + 'alignItems': 'stretch', + 'id': 'u:2a2b198f141b', + 'label': '', + } + + ol = { + 'type': 'flex', + 'className': 'p-1', + 'items': [ + { + 'type': 'container', + 'body': [ + { + 'type': 'select', + 'label': '权限控制', + 'name': 'pm', + 'options': [ + {'label': 'BOT主人', 'value': '0'}, + {'label': '超级管理员', 'value': '1'}, + {'label': '群主', 'value': '2'}, + {'label': '管理员', 'value': '3'}, + {'label': '频道管理员', 'value': '4'}, + { + 'label': '子频道管理员', + 'value': '5', + }, + {'label': '正常人', 'value': '6'}, + {'label': '权限极低', 'value': '7'}, + {'label': '黑名单', 'value': '8'}, + ], + 'id': 'u:c71f20b605d4', + 'multiple': False, + 'value': str(pm), + } + ], + 'size': 'xs', + 'style': { + 'position': 'static', + 'display': 'block', + 'flex': '1 1 auto', + 'flexGrow': 1, + 'flexBasis': 'auto', + }, + 'wrapperBody': False, + 'isFixedHeight': False, + 'isFixedWidth': False, + 'id': 'u:bafbdfce89c2', + }, + { + 'type': 'container', + 'body': [ + { + 'type': 'input-number', + 'label': '命令优先级', + 'name': 'priority', + 'keyboard': True, + 'id': 'u:0b72c9b8086d', + 'step': 1, + 'value': priority, + } + ], + 'size': 'xs', + 'style': { + 'position': 'static', + 'display': 'block', + 'flex': '1 1 auto', + 'flexGrow': 1, + 'flexBasis': 'auto', + }, + 'wrapperBody': False, + 'isFixedHeight': False, + 'isFixedWidth': False, + 'id': 'u:80670a4807f2', + }, + { + 'type': 'container', + 'body': [ + { + 'type': 'select', + 'label': '作用范围', + 'name': 'area', + 'options': area_options, + 'id': 'u:88e66f806556', + 'multiple': False, + 'value': area, + } + ], + 'size': 'xs', + 'style': { + 'position': 'static', + 'display': 'block', + 'flex': '1 1 auto', + 'flexGrow': 1, + 'flexBasis': 'auto', + }, + 'wrapperBody': False, + 'isFixedHeight': False, + 'isFixedWidth': False, + 'id': 'u:f24811f21e93', + }, + ], + 'style': {'position': 'static'}, + 'direction': 'row', + 'justify': 'flex-start', + 'alignItems': 'stretch', + 'id': 'u:2a2b198f141b', + 'label': '', + } + + black = { + 'type': 'flex', + 'className': 'p-1', + 'items': [ + { + 'type': 'container', + 'size': 'xs', + 'body': [ + get_input_tag('黑名单', 'black_list', black_list, []) + ], + 'wrapperBody': False, + 'style': {'flex': '0 0 auto', 'display': 'block'}, + 'id': 'u:48c938f71548', + } + ], + 'direction': 'column', + 'justify': 'center', + 'alignItems': 'stretch', + 'id': 'u:a7b2f1bbc0a8', + 'label': '', + } + + white = { + 'type': 'flex', + 'className': 'p-1', + 'items': [ + { + 'type': 'container', + 'size': 'xs', + 'body': [ + get_input_tag('白名单', 'white_list', white_list, []) + ], + 'wrapperBody': False, + 'style': {'flex': '0 0 auto', 'display': 'block'}, + 'id': 'u:48c938f71548', + } + ], + 'direction': 'column', + 'justify': 'center', + 'alignItems': 'stretch', + 'id': 'u:a7b2f1bbc0a8', + 'label': '', + } card = { "type": "service", "body": { 'type': 'card', 'header': {'title': '', 'subTitle': ''}, - 'body': [ - { - 'type': 'flex', - 'className': 'p-1', - 'items': [ - { - 'type': 'container', - 'size': 'xs', - 'style': { - 'position': 'static', - 'display': 'block', - 'flex': '1 1 auto', - 'flexGrow': 1, - 'flexBasis': 'auto', - }, - 'wrapperBody': False, - 'isFixedHeight': False, - 'isFixedWidth': False, - 'id': 'u:bafbdfce89c2', - 'body': [ - { - 'type': 'tpl', - 'tpl': name, - 'inline': True, - 'wrapperComponent': '', - 'id': 'u:cd523cbd8f0c', - 'style': { - 'fontFamily': '', - 'fontSize': 25, - }, - }, - { - 'type': 'switch', - 'label': '总开关', - 'option': '开启/关闭功能', - 'name': 'enabled', - 'falseValue': False, - 'trueValue': True, - 'id': 'u:d739bc85f307', - 'value': enabled, - }, - ], - }, - { - 'type': 'container', - 'size': 'xs', - 'style': { - 'position': 'static', - 'display': 'block', - 'flex': '1 1 auto', - 'flexGrow': 1, - 'flexBasis': 'auto', - }, - 'wrapperBody': False, - 'isFixedHeight': False, - 'isFixedWidth': False, - 'id': 'u:80670a4807f2', - }, - { - 'type': 'container', - 'body': [], - 'size': 'xs', - 'style': { - 'position': 'static', - 'display': 'block', - 'flex': '1 1 auto', - 'flexGrow': 1, - 'flexBasis': 'auto', - }, - 'wrapperBody': False, - 'isFixedHeight': False, - 'isFixedWidth': False, - 'id': 'u:f24811f21e93', - }, - ], - 'style': {'position': 'static'}, - 'direction': 'row', - 'justify': 'flex-start', - 'alignItems': 'stretch', - 'id': 'u:2a2b198f141b', - 'label': '', - }, - { - 'type': 'flex', - 'className': 'p-1', - 'items': [ - { - 'type': 'container', - 'body': [ - { - 'type': 'select', - 'label': '权限控制', - 'name': 'pm', - 'options': [ - {'label': 'BOT主人', 'value': '0'}, - {'label': '超级管理员', 'value': '1'}, - {'label': '群主', 'value': '2'}, - {'label': '管理员', 'value': '3'}, - {'label': '频道管理员', 'value': '4'}, - { - 'label': '子频道管理员', - 'value': '5', - }, - {'label': '正常人', 'value': '6'}, - {'label': '权限极低', 'value': '7'}, - {'label': '黑名单', 'value': '8'}, - ], - 'id': 'u:c71f20b605d4', - 'multiple': False, - 'value': str(pm), - } - ], - 'size': 'xs', - 'style': { - 'position': 'static', - 'display': 'block', - 'flex': '1 1 auto', - 'flexGrow': 1, - 'flexBasis': 'auto', - }, - 'wrapperBody': False, - 'isFixedHeight': False, - 'isFixedWidth': False, - 'id': 'u:bafbdfce89c2', - }, - { - 'type': 'container', - 'body': [ - { - 'type': 'input-number', - 'label': '命令优先级', - 'name': 'priority', - 'keyboard': True, - 'id': 'u:0b72c9b8086d', - 'step': 1, - 'value': priority, - } - ], - 'size': 'xs', - 'style': { - 'position': 'static', - 'display': 'block', - 'flex': '1 1 auto', - 'flexGrow': 1, - 'flexBasis': 'auto', - }, - 'wrapperBody': False, - 'isFixedHeight': False, - 'isFixedWidth': False, - 'id': 'u:80670a4807f2', - }, - { - 'type': 'container', - 'body': [ - { - 'type': 'select', - 'label': '作用范围', - 'name': 'area', - 'options': area_options, - 'id': 'u:88e66f806556', - 'multiple': False, - 'value': area, - } - ], - 'size': 'xs', - 'style': { - 'position': 'static', - 'display': 'block', - 'flex': '1 1 auto', - 'flexGrow': 1, - 'flexBasis': 'auto', - }, - 'wrapperBody': False, - 'isFixedHeight': False, - 'isFixedWidth': False, - 'id': 'u:f24811f21e93', - }, - ], - 'style': {'position': 'static'}, - 'direction': 'row', - 'justify': 'flex-start', - 'alignItems': 'stretch', - 'id': 'u:2a2b198f141b', - 'label': '', - }, - { - 'type': 'flex', - 'className': 'p-1', - 'items': [ - { - 'type': 'container', - 'size': 'xs', - 'body': [ - get_input_tag( - '黑名单', 'black_list', black_list, [] - ) - ], - 'wrapperBody': False, - 'style': {'flex': '0 0 auto', 'display': 'block'}, - 'id': 'u:48c938f71548', - } - ], - 'direction': 'column', - 'justify': 'center', - 'alignItems': 'stretch', - 'id': 'u:a7b2f1bbc0a8', - 'label': '', - }, - { - 'type': 'flex', - 'className': 'p-1', - 'items': [ - { - 'type': 'container', - 'size': 'xs', - 'body': [ - get_input_tag( - '白名单', 'white_list', white_list, [] - ) - ], - 'wrapperBody': False, - 'style': {'flex': '0 0 auto', 'display': 'block'}, - 'id': 'u:48c938f71548', - } - ], - 'direction': 'column', - 'justify': 'center', - 'alignItems': 'stretch', - 'id': 'u:a7b2f1bbc0a8', - 'label': '', - }, - ], + 'body': [], 'actions': [ { 'type': 'button', @@ -301,6 +387,11 @@ def get_sv_panel( "id": "u:4c2981f6a055", } + if API == '/genshinuid/setPlugins': + card['body']['body'].extend([switch, ol, extra, black, white]) + else: + card['body']['body'].extend([switch, ol, black, white]) + return card @@ -329,6 +420,9 @@ def get_sv_page(): plugins.area, # type:ignore plugins.black_list, plugins.white_list, + plugins.prefix, + plugins.disable_force_prefix, + plugins.allow_empty_prefix, ) ) grids.append(get_divider())