refactor&fix(manager): modify argument

This commit is contained in:
MingxuanGame 2022-05-24 01:27:55 +08:00
parent 41836bde26
commit c4d53d58eb
No known key found for this signature in database
GPG Key ID: 90C7EFA11DC3C2FF
5 changed files with 26 additions and 55 deletions

View File

@ -28,7 +28,7 @@ def init_plugins_cd_limit(data_path):
_module = _plugin.module
plugin_cd_limit = _module.__getattribute__("__plugin_cd_limit__")
plugins2cd_manager.add_cd_limit(
matcher.plugin_name, data_dict=plugin_cd_limit
matcher.plugin_name, **plugin_cd_limit
)
except AttributeError:
pass
@ -76,7 +76,7 @@ def init_plugins_block_limit(data_path):
_module = _plugin.module
plugin_block_limit = _module.__getattribute__("__plugin_block_limit__")
plugins2block_manager.add_block_limit(
matcher.plugin_name, data_dict=plugin_block_limit
matcher.plugin_name, **plugin_block_limit
)
except AttributeError:
pass
@ -124,7 +124,7 @@ def init_plugins_count_limit(data_path):
_module = _plugin.module
plugin_count_limit = _module.__getattribute__("__plugin_count_limit__")
plugins2count_manager.add_count_limit(
matcher.plugin_name, data_dict=plugin_count_limit
matcher.plugin_name, **plugin_count_limit
)
except AttributeError:
pass

View File

@ -21,18 +21,17 @@ class Plugins2blockManager(StaticData):
with open(file, "r", encoding="utf8") as f:
self._data = yaml.load(f)
if "PluginBlockLimit" in self._data.keys():
self._data = (
self._data["PluginBlockLimit"] if self._data["PluginBlockLimit"] else {}
)
self._data = self._data["PluginBlockLimit"] or {}
def add_block_limit(
self,
plugin: str,
*,
status: Optional[bool] = True,
check_type: Optional[str] = "all",
limit_type: Optional[str] = "user",
rst: Optional[str] = None,
data_dict: Optional[dict] = None,
**kwargs # 用于接收额外实参
):
"""
添加插件调用 block 限制
@ -41,16 +40,10 @@ class Plugins2blockManager(StaticData):
:param check_type: 检查类型 'private'/'group'/'all'限制私聊/群聊/全部
:param limit_type: 限制类型 监听对象以user_id或group_id作为键来限制'user'用户id'group'群id
:param rst: 回复的话为空则不回复
:param data_dict: 封装好的字典数据
"""
if data_dict:
status = data_dict.get("status")
check_type = data_dict.get("check_type")
limit_type = data_dict.get("limit_type")
rst = data_dict.get("rst")
status = status if status is not None else True
check_type = check_type if check_type else "all"
limit_type = limit_type if limit_type else "user"
status = status or True
check_type = check_type or "all"
limit_type = limit_type or "user"
if check_type not in ["all", "group", "private"]:
raise ValueError(
f"{plugin} 添加block限制错误check_type 必须为 'private'/'group'/'all'"

View File

@ -34,7 +34,7 @@ class Plugins2cdManager(StaticData):
check_type: Optional[str] = "all",
limit_type: Optional[str] = "user",
rst: Optional[str] = None,
data_dict: Optional[dict] = None,
**kwargs # 用于接收额外实参
):
"""
添加插件调用 cd 限制
@ -44,18 +44,11 @@ class Plugins2cdManager(StaticData):
:param check_type: 检查类型 'private'/'group'/'all'限制私聊/群聊/全部
:param limit_type: 限制类型 监听对象以user_id或group_id作为键来限制'user'用户id'group'群id
:param rst: 回复的话为空则不回复
:param data_dict: 封装好的字典数据
"""
if data_dict:
cd = data_dict.get("cd")
status = data_dict.get("status")
check_type = data_dict.get("check_type")
limit_type = data_dict.get("limit_type")
rst = data_dict.get("rst")
cd = cd if cd is not None else 5
status = status if status is not None else True
check_type = check_type if check_type else "all"
limit_type = limit_type if limit_type else "user"
cd = cd or 5
status = status or True
check_type = check_type or "all"
limit_type = limit_type or "user"
if check_type not in ["all", "group", "private"]:
raise ValueError(
f"{plugin} 添加cd限制错误check_type 必须为 'private'/'group'/'all'"

View File

@ -33,7 +33,7 @@ class Plugins2countManager(StaticData):
status: Optional[bool] = True,
limit_type: Optional[str] = "user",
rst: Optional[str] = None,
data_dict: Optional[dict] = None,
**kwargs # 用于接收额外实参
):
"""
添加插件调用 次数 限制
@ -42,16 +42,10 @@ class Plugins2countManager(StaticData):
:param status: 默认开关状态
:param limit_type: 限制类型 监听对象以user_id或group_id作为键来限制'user'用户id'group'群id
:param rst: 回复的话为空则不回复
:param data_dict: 封装好的字典数据
"""
if data_dict:
max_count = data_dict.get("max_count")
status = data_dict.get("status")
limit_type = data_dict.get("limit_type")
rst = data_dict.get("rst")
status = status if status is not None else True
limit_type = limit_type if limit_type else "user"
max_count = max_count if max_count is not None else 5
max_count = max_count or 5
status = status or True
limit_type = limit_type or "user"
if limit_type not in ["user", "group"]:
raise ValueError(f"{plugin} 添加count限制错误limit_type 必须为 'user'/'group'")
self._data[plugin] = {

View File

@ -47,26 +47,17 @@ class Plugins2settingsManager(StaticData):
:param plugin_type: 插件类型
:param cost_gold: 需要消费的金币
"""
if kwargs:
level = kwargs.get("level") if kwargs.get("level") is not None else 5
default_status = (
kwargs.get("default_status")
if kwargs.get("default_status") is not None
else True
)
limit_superuser = (
kwargs.get("limit_superuser")
if kwargs.get("limit_superuser") is not None
else False
)
cmd = kwargs.get("cmd") if kwargs.get("cmd") is not None else []
cost_gold = cost_gold if kwargs.get("cost_gold") else 0
level = level or 5
cmd = cmd or []
cost_gold = cost_gold or 0
self._data[plugin] = {
"level": level if level is not None else 5,
"default_status": default_status if default_status is not None else True,
"limit_superuser": limit_superuser
if limit_superuser is not None
else False,
"limit_superuser": (
limit_superuser
if limit_superuser is not None
else False
),
"cmd": cmd,
"plugin_type": list(
plugin_type if plugin_type is not None else ("normal",)