mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
Update plugins2settings_manager.py
This commit is contained in:
parent
98374dcd74
commit
a9a636c9ae
@ -2,8 +2,10 @@ from typing import List, Optional, Union, Tuple
|
|||||||
from .data_class import StaticData
|
from .data_class import StaticData
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
|
from ruamel import yaml
|
||||||
|
|
||||||
yaml = YAML(typ="safe")
|
|
||||||
|
_yaml = YAML(typ="safe")
|
||||||
|
|
||||||
|
|
||||||
class Plugins2settingsManager(StaticData):
|
class Plugins2settingsManager(StaticData):
|
||||||
@ -16,7 +18,7 @@ class Plugins2settingsManager(StaticData):
|
|||||||
super().__init__(None)
|
super().__init__(None)
|
||||||
if file.exists():
|
if file.exists():
|
||||||
with open(file, "r", encoding="utf8") as f:
|
with open(file, "r", encoding="utf8") as f:
|
||||||
self._data = yaml.load(f)
|
self._data = _yaml.load(f)
|
||||||
if self._data:
|
if self._data:
|
||||||
if "PluginSettings" in self._data.keys():
|
if "PluginSettings" in self._data.keys():
|
||||||
self._data = (
|
self._data = (
|
||||||
@ -91,11 +93,19 @@ class Plugins2settingsManager(StaticData):
|
|||||||
return key
|
return key
|
||||||
return keys
|
return keys
|
||||||
|
|
||||||
|
def save(self, path: Union[str, Path] = None):
|
||||||
|
path = path or self.file
|
||||||
|
if isinstance(path, str):
|
||||||
|
path = Path(path)
|
||||||
|
if path:
|
||||||
|
with open(path, "w", encoding="utf8") as f:
|
||||||
|
yaml.dump({"PluginSettings": self._data}, f, indent=2, Dumper=yaml.RoundTripDumper, allow_unicode=True)
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
"""
|
"""
|
||||||
重载本地数据
|
重载本地数据
|
||||||
"""
|
"""
|
||||||
if self.file.exists():
|
if self.file.exists():
|
||||||
with open(self.file, "r", encoding="utf8") as f:
|
with open(self.file, "r", encoding="utf8") as f:
|
||||||
self._data: dict = yaml.load(f)
|
self._data: dict = _yaml.load(f)
|
||||||
self._data = self._data["PluginSettings"]
|
self._data = self._data["PluginSettings"]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user