Plugins新增force_prefixdisable_force_prefix, 可在网页控制台功能服务配置修改prefix (#76)

This commit is contained in:
KimigaiiWuyi 2024-10-04 05:14:04 +08:00
parent 980fe9d677
commit 5f322393c8
4 changed files with 359 additions and 234 deletions

View File

@ -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': {},
}

View File

@ -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:

View File

@ -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(',')

View File

@ -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,13 +35,92 @@ def get_sv_panel(
if API == '/genshinuid/setPlugins':
area_options.append({'label': '按照服务设定', 'value': 'SV'})
card = {
"type": "service",
"body": {
'type': 'card',
'header': {'title': '', 'subTitle': ''},
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': [
@ -118,8 +200,9 @@ def get_sv_panel(
'alignItems': 'stretch',
'id': 'u:2a2b198f141b',
'label': '',
},
{
}
ol = {
'type': 'flex',
'className': 'p-1',
'items': [
@ -221,8 +304,9 @@ def get_sv_panel(
'alignItems': 'stretch',
'id': 'u:2a2b198f141b',
'label': '',
},
{
}
black = {
'type': 'flex',
'className': 'p-1',
'items': [
@ -230,9 +314,7 @@ def get_sv_panel(
'type': 'container',
'size': 'xs',
'body': [
get_input_tag(
'黑名单', 'black_list', black_list, []
)
get_input_tag('黑名单', 'black_list', black_list, [])
],
'wrapperBody': False,
'style': {'flex': '0 0 auto', 'display': 'block'},
@ -244,8 +326,9 @@ def get_sv_panel(
'alignItems': 'stretch',
'id': 'u:a7b2f1bbc0a8',
'label': '',
},
{
}
white = {
'type': 'flex',
'className': 'p-1',
'items': [
@ -253,9 +336,7 @@ def get_sv_panel(
'type': 'container',
'size': 'xs',
'body': [
get_input_tag(
'白名单', 'white_list', white_list, []
)
get_input_tag('白名单', 'white_list', white_list, [])
],
'wrapperBody': False,
'style': {'flex': '0 0 auto', 'display': 'block'},
@ -267,8 +348,13 @@ def get_sv_panel(
'alignItems': 'stretch',
'id': 'u:a7b2f1bbc0a8',
'label': '',
},
],
}
card = {
"type": "service",
"body": {
'type': 'card',
'header': {'title': '', 'subTitle': ''},
'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())