取消配置替换定时任务,统一存储

This commit is contained in:
HibiKier 2022-08-22 22:49:35 +08:00
parent 82fe59e469
commit d2dccfebc5
3 changed files with 21 additions and 23 deletions

View File

@ -108,16 +108,16 @@ def init_plugins_config(data_path):
_data, wf, indent=2, Dumper=yaml.RoundTripDumper, allow_unicode=True _data, wf, indent=2, Dumper=yaml.RoundTripDumper, allow_unicode=True
) )
user_config_file = Path() / "configs" / "config.yaml" user_config_file = Path() / "configs" / "config.yaml"
if not user_config_file.exists(): # if not user_config_file.exists():
_replace_config() _replace_config()
else: # else:
logger.info('五分钟后将进行配置数据替换,请注意...') # logger.info('五分钟后将进行配置数据替换,请注意...')
scheduler.add_job( # scheduler.add_job(
_replace_config, # _replace_config,
"date", # "date",
run_date=datetime.now() + timedelta(minutes=5), # run_date=datetime.now() + timedelta(minutes=5),
id=f"_replace_config" # id=f"_replace_config"
) # )
def _replace_config(): def _replace_config():

View File

@ -94,13 +94,14 @@ class ConfigsManager:
del self._data[module] del self._data[module]
self.save() self.save()
def set_config(self, module: str, key: str, value: Any, save_simple_data: bool = False): def set_config(self, module: str, key: str, value: Any, auto_save: bool = False, save_simple_data: bool = True):
""" """
设置配置值 设置配置值
:param module: 模块名 :param module: 模块名
:param key: 配置名称 :param key: 配置名称
:param value: :param value:
:param save_simple_data: 同时保存至config.yaml :param auto_save: 自动保存
:param save_simple_data: 保存至config.yaml
""" """
if module in self._data.keys(): if module in self._data.keys():
if ( if (
@ -109,6 +110,7 @@ class ConfigsManager:
): ):
self._data[module][key]["value"] = value self._data[module][key]["value"] = value
self._simple_data[module][key] = value self._simple_data[module][key] = value
if auto_save:
self.save(save_simple_data=save_simple_data) self.save(save_simple_data=save_simple_data)
def set_help(self, module: str, key: str, help_: str): def set_help(self, module: str, key: str, help_: str):
@ -145,18 +147,12 @@ class ConfigsManager:
:param default: 没有key值内容的默认返回值 :param default: 没有key值内容的默认返回值
""" """
key = key.upper() key = key.upper()
# 优先使用simple_data if module in self._data.keys():
if module in self._simple_data.keys():
for key in [key, f"{key} [LEVEL]"]: for key in [key, f"{key} [LEVEL]"]:
if self._simple_data[module].get(key) is not None: if self._data[module].get(key) is not None:
return self._simple_data[module][key] if self._data[module][key]["value"] is None:
# if module in self._data.keys(): return self._data[module][key]["default_value"]
# if module in self._data.keys(): return self._data[module][key]["value"]
# for key in [key, f"{key} [LEVEL]"]:
# if self._data[module].get(key) is not None:
# if self._data[module][key]["value"] is None:
# return self._data[module][key]["value"]
# return self._data[module][key]["default_value"]
if default is not None: if default is not None:
return default return default
return None return None

View File

@ -53,6 +53,8 @@ async def _(event: MessageEvent, state: T_State, arg: Message = CommandArg()):
if img_list: if img_list:
state["img_list"] = arg state["img_list"] = arg
print(Config.get_config("image_management", "IMAGE_DIR_LIST"))
@upload_img.got( @upload_img.got(
"path", "path",