fix: global plugin config read
parent
954e55f4b4
commit
4bab4299f2
|
|
@ -26,14 +26,16 @@ class Banwords(Plugin):
|
||||||
try:
|
try:
|
||||||
curdir = os.path.dirname(__file__)
|
curdir = os.path.dirname(__file__)
|
||||||
config_path = os.path.join(curdir, "config.json")
|
config_path = os.path.join(curdir, "config.json")
|
||||||
conf = None
|
# loading config from global plugin config
|
||||||
if not os.path.exists(config_path):
|
conf = super().load_config()
|
||||||
conf = {"action": "ignore"}
|
if not conf:
|
||||||
with open(config_path, "w") as f:
|
if not os.path.exists(config_path):
|
||||||
json.dump(conf, f, indent=4)
|
conf = {"action": "ignore"}
|
||||||
else:
|
with open(config_path, "w") as f:
|
||||||
with open(config_path, "r") as f:
|
json.dump(conf, f, indent=4)
|
||||||
conf = super().load_config() or json.load(f)
|
else:
|
||||||
|
with open(config_path, "r") as f:
|
||||||
|
conf = super().load_config() or json.load(f)
|
||||||
self.searchr = WordsSearch()
|
self.searchr = WordsSearch()
|
||||||
self.action = conf["action"]
|
self.action = conf["action"]
|
||||||
banwords_path = os.path.join(curdir, "banwords.txt")
|
banwords_path = os.path.join(curdir, "banwords.txt")
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,13 @@ class BDunit(Plugin):
|
||||||
try:
|
try:
|
||||||
curdir = os.path.dirname(__file__)
|
curdir = os.path.dirname(__file__)
|
||||||
config_path = os.path.join(curdir, "config.json")
|
config_path = os.path.join(curdir, "config.json")
|
||||||
conf = None
|
conf = super().load_config()
|
||||||
if not os.path.exists(config_path):
|
if not conf:
|
||||||
raise Exception("config.json not found")
|
if not os.path.exists(config_path):
|
||||||
else:
|
raise Exception("config.json not found")
|
||||||
with open(config_path, "r") as f:
|
else:
|
||||||
conf = super().load_config() or json.load(f)
|
with open(config_path, "r") as f:
|
||||||
|
conf = json.load(f)
|
||||||
self.service_id = conf["service_id"]
|
self.service_id = conf["service_id"]
|
||||||
self.api_key = conf["api_key"]
|
self.api_key = conf["api_key"]
|
||||||
self.secret_key = conf["secret_key"]
|
self.secret_key = conf["secret_key"]
|
||||||
|
|
|
||||||
|
|
@ -180,14 +180,16 @@ class Godcmd(Plugin):
|
||||||
|
|
||||||
curdir = os.path.dirname(__file__)
|
curdir = os.path.dirname(__file__)
|
||||||
config_path = os.path.join(curdir, "config.json")
|
config_path = os.path.join(curdir, "config.json")
|
||||||
gconf = None
|
# loading config from global plugin config
|
||||||
if not os.path.exists(config_path):
|
gconf = super().load_config()
|
||||||
gconf = {"password": "", "admin_users": []}
|
if not gconf:
|
||||||
with open(config_path, "w") as f:
|
if not os.path.exists(config_path):
|
||||||
json.dump(gconf, f, indent=4)
|
gconf = {"password": "", "admin_users": []}
|
||||||
else:
|
with open(config_path, "w") as f:
|
||||||
with open(config_path, "r") as f:
|
json.dump(gconf, f, indent=4)
|
||||||
gconf = super().load_config() or json.load(f)
|
else:
|
||||||
|
with open(config_path, "r") as f:
|
||||||
|
gconf = json.load(f)
|
||||||
if gconf["password"] == "":
|
if gconf["password"] == "":
|
||||||
self.temp_password = "".join(random.sample(string.digits, 4))
|
self.temp_password = "".join(random.sample(string.digits, 4))
|
||||||
logger.info("[Godcmd] 因未设置口令,本次的临时口令为%s。" % self.temp_password)
|
logger.info("[Godcmd] 因未设置口令,本次的临时口令为%s。" % self.temp_password)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
from config import pconf
|
from config import pconf
|
||||||
|
from common.log import logger
|
||||||
|
|
||||||
class Plugin:
|
class Plugin:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
@ -10,7 +11,9 @@ class Plugin:
|
||||||
加载当前插件配置
|
加载当前插件配置
|
||||||
:return: 插件配置字典
|
:return: 插件配置字典
|
||||||
"""
|
"""
|
||||||
return pconf(self.name)
|
conf = pconf(self.name)
|
||||||
|
logger.info(f"loading from global plugin config, plugin_name={self.name}, conf={conf}")
|
||||||
|
return conf
|
||||||
|
|
||||||
def get_help_text(self, **kwargs):
|
def get_help_text(self, **kwargs):
|
||||||
return "暂无帮助信息"
|
return "暂无帮助信息"
|
||||||
|
|
|
||||||
|
|
@ -121,12 +121,13 @@ class Tool(Plugin):
|
||||||
def _read_json(self) -> dict:
|
def _read_json(self) -> dict:
|
||||||
curdir = os.path.dirname(__file__)
|
curdir = os.path.dirname(__file__)
|
||||||
config_path = os.path.join(curdir, "config.json")
|
config_path = os.path.join(curdir, "config.json")
|
||||||
tool_config = {"tools": [], "kwargs": {}}
|
tool_config = super().load_config()
|
||||||
if not os.path.exists(config_path):
|
if not tool_config:
|
||||||
return tool_config
|
if not os.path.exists(config_path):
|
||||||
else:
|
return {"tools": [], "kwargs": {}}
|
||||||
with open(config_path, "r") as f:
|
else:
|
||||||
tool_config = super().load_config() or json.load(f)
|
with open(config_path, "r") as f:
|
||||||
|
tool_config = json.load(f)
|
||||||
return tool_config
|
return tool_config
|
||||||
|
|
||||||
def _build_tool_kwargs(self, kwargs: dict):
|
def _build_tool_kwargs(self, kwargs: dict):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue