refactor&fix(manager): modify argument

This commit is contained in:
MingxuanGame
2022-05-24 01:27:55 +08:00
parent 41836bde26
commit c4d53d58eb
5 changed files with 26 additions and 55 deletions
+6 -13
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'"