Files

51 lines
1.8 KiB
Python
Raw Permalink Normal View History

import os
import json
from config import pconf, plugin_config, conf, write_plugin_config
2023-07-20 14:24:40 +08:00
from common.log import logger
2023-03-12 11:53:06 +08:00
class Plugin:
def __init__(self):
self.handlers = {}
2023-03-24 22:37:48 +08:00
def load_config(self) -> dict:
"""
加载当前插件配置
:return: 插件配置字典
"""
# 优先获取 plugins/config.json 中的全局配置
plugin_conf = pconf(self.name)
2023-09-06 11:53:33 +08:00
if not plugin_conf:
# 全局配置不存在,则获取插件目录下的配置
plugin_config_path = os.path.join(self.path, "config.json")
if os.path.exists(plugin_config_path):
2023-08-07 14:42:24 +08:00
with open(plugin_config_path, "r", encoding="utf-8") as f:
plugin_conf = json.load(f)
2023-09-30 15:14:42 +08:00
# 写入全局配置内存
write_plugin_config({self.name: plugin_conf})
return plugin_conf
2023-07-28 12:40:06 +08:00
def save_config(self, config: dict):
try:
write_plugin_config({self.name: config})
2023-07-28 12:40:06 +08:00
# 写入全局配置
global_config_path = "./plugins/config.json"
if os.path.exists(global_config_path):
with open(global_config_path, "w", encoding='utf-8') as f:
json.dump(plugin_config, f, indent=4, ensure_ascii=False)
# 写入插件配置
plugin_config_path = os.path.join(self.path, "config.json")
if os.path.exists(plugin_config_path):
with open(plugin_config_path, "w", encoding='utf-8') as f:
json.dump(config, f, indent=4, ensure_ascii=False)
except Exception as e:
logger.warn("save plugin config failed: {}".format(e))
2023-03-24 22:37:48 +08:00
def get_help_text(self, **kwargs):
2023-04-17 01:00:08 +08:00
return "暂无帮助信息"
2024-02-05 12:01:41 +08:00
def reload(self):
pass