update 0.0.6.4

This commit is contained in:
HibiKi 2021-11-29 13:09:47 +08:00
parent fbd7c568d9
commit c1348d08ed
4 changed files with 42 additions and 3 deletions

View File

@ -92,11 +92,14 @@ def init_plugins_config(data_path):
if user_config_file.exists(): if user_config_file.exists():
with open(user_config_file, "r", encoding="utf8") as f: with open(user_config_file, "r", encoding="utf8") as f:
_data = _yaml.load(f) _data = _yaml.load(f)
# 数据替换
for plugin in Config.keys(): for plugin in Config.keys():
_tmp_data[plugin] = {} _tmp_data[plugin] = {}
for k in Config[plugin].keys(): for k in Config[plugin].keys():
if _data.get(plugin) and k in _data[plugin].keys(): if _data.get(plugin) and k in _data[plugin].keys():
Config.set_config(plugin, k, _data[plugin][k]) Config.set_config(plugin, k, _data[plugin][k])
if level2module := Config.get_level2module(plugin, k):
admin_manager.set_admin_level(level2module, _data[plugin][k])
_tmp_data[plugin][k] = Config.get_config(plugin, k) _tmp_data[plugin][k] = Config.get_config(plugin, k)
Config.save() Config.save()
temp_file = Path() / "configs" / "temp_config.yaml" temp_file = Path() / "configs" / "temp_config.yaml"
@ -145,3 +148,4 @@ def init_plugins_config(data_path):
logger.error(f"生成简易配置注释错误 {type(e)}{e}") logger.error(f"生成简易配置注释错误 {type(e)}{e}")
if temp_file.exists(): if temp_file.exists():
temp_file.unlink() temp_file.unlink()

View File

@ -29,7 +29,7 @@ class ConfigsManager:
name: Optional[str] = None, name: Optional[str] = None,
help_: Optional[str] = None, help_: Optional[str] = None,
default_value: Optional[str] = None, default_value: Optional[str] = None,
_override: bool = False _override: bool = False,
): ):
""" """
为插件添加一个配置不会被覆盖只有第一个生效 为插件添加一个配置不会被覆盖只有第一个生效
@ -61,6 +61,7 @@ class ConfigsManager:
"name": name.strip() if isinstance(name, str) else name, "name": name.strip() if isinstance(name, str) else name,
"help": help_.strip() if isinstance(help_, str) else help_, "help": help_.strip() if isinstance(help_, str) else help_,
"default_value": default_value, "default_value": default_value,
"level_module": _module,
} }
def remove_plugin_config(self, module: str): def remove_plugin_config(self, module: str):
@ -119,6 +120,17 @@ class ConfigsManager:
return self._data[module][key]["value"] return self._data[module][key]["value"]
return None return None
def get_level2module(self, module: str, key: str) -> Optional[str]:
"""
获取指定key所绑定的module一般为权限等级
:param module: 模块名
:param key: 配置名称
:return:
"""
if self._data.get(module) is not None:
if self._data[module].get(key) is not None:
return self._data[module][key].get("level_module")
def get(self, key: str): def get(self, key: str):
""" """
获取插件配置数据 获取插件配置数据
@ -158,3 +170,4 @@ class ConfigsManager:
def __getitem__(self, key): def __getitem__(self, key):
return self._data[key] return self._data[key]

View File

@ -3,6 +3,8 @@ from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, MessageEvent from nonebot.adapters.cqhttp import Bot, MessageEvent
from utils.message_builder import image from utils.message_builder import image
from services.log import logger from services.log import logger
from utils.manager import withdraw_message_manager
from configs.config import Config
__zx_plugin_name__ = "coser" __zx_plugin_name__ = "coser"
__plugin_usage__ = """ __plugin_usage__ = """
@ -21,6 +23,13 @@ __plugin_settings__ = {
"limit_superuser": False, "limit_superuser": False,
"cmd": ["cos", "coser", "括丝", "COS", "Cos", "cOS", "coS"], "cmd": ["cos", "coser", "括丝", "COS", "Cos", "cOS", "coS"],
} }
__plugin_configs__ = {
"WITHDRAW_COS_MESSAGE": {
"value": (0, 1),
"help": "自动撤回参1延迟撤回色图时间(秒)0 为关闭 | 参2监控聊天类型0(私聊) 1(群聊) 2(群聊+私聊)",
"default_value": (0, 1),
},
}
coser = on_command( coser = on_command(
"cos", aliases={"coser", "括丝", "COS", "Cos", "cOS", "coS"}, priority=5, block=True "cos", aliases={"coser", "括丝", "COS", "Cos", "cOS", "coS"}, priority=5, block=True
@ -33,7 +42,13 @@ url = "http://iw233.cn/API/cos.php"
@coser.handle() @coser.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State): async def _(bot: Bot, event: MessageEvent, state: T_State):
try: try:
await coser.send(image(url)) msg_id = await coser.send(image(url))
withdraw_message_manager.withdraw_message(
event,
msg_id["message_id"],
Config.get_config("coser", "WITHDRAW_COS_MESSAGE"),
)
except Exception as e: except Exception as e:
await coser.send("你cos给我看") await coser.send("你cos给我看")
logger.error(f"coser 发送了未知错误 {type(e)}{e}") logger.error(f"coser 发送了未知错误 {type(e)}{e}")

View File

@ -2,9 +2,15 @@ from typing import Optional, List, Union, Dict
from pathlib import Path from pathlib import Path
from .data_class import StaticData from .data_class import StaticData
from utils.utils import get_matchers, get_bot from utils.utils import get_matchers, get_bot
from configs.config import Config
import nonebot import nonebot
Config.add_plugin_config(
"group_manager", "DEFAULT_GROUP_LEVEL", 5, help_="默认群权限", default_value=5
)
class GroupManager(StaticData): class GroupManager(StaticData):
""" """
群权限 | 功能 | 聊天时间 管理器 群权限 | 功能 | 聊天时间 管理器
@ -274,7 +280,7 @@ class GroupManager(StaticData):
参数 参数
:param group_id: 群号 :param group_id: 群号
""" """
default_group_level = 5 # Config.get_config("group_manager") default_group_level = Config.get_config("group_manager", "DEFAULT_GROUP_LEVEL")
if not default_group_level: if not default_group_level:
default_group_level = 5 default_group_level = 5
if not self._data["group_manager"].get(group_id): if not self._data["group_manager"].get(group_id):
@ -293,3 +299,4 @@ class GroupManager(StaticData):
del self._data["super"]["close_plugins"] del self._data["super"]["close_plugins"]
return _x return _x
return None return None