Skip to content

Commit

Permalink
Merge pull request #2407 from ayasa520/fix_reloadp
Browse files Browse the repository at this point in the history
fix(plugin): fix reloadp command not taking effect
  • Loading branch information
Saboteur7 authored Dec 13, 2024
2 parents 9f7e2e1 + c567641 commit 16324e7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
8 changes: 4 additions & 4 deletions common/linkai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from bridge.reply import Reply, ReplyType
from common.log import logger
from linkai import LinkAIClient, PushMsg
from config import conf, pconf, plugin_config, available_setting
from config import conf, pconf, plugin_config, available_setting, write_plugin_config
from plugins import PluginManager
import time

Expand Down Expand Up @@ -51,10 +51,10 @@ def on_config(self, config: dict):
local_config["voice_reply_voice"] = False

if config.get("admin_password"):
if not plugin_config.get("Godcmd"):
plugin_config["Godcmd"] = {"password": config.get("admin_password"), "admin_users": []}
if not pconf("Godcmd"):
write_plugin_config({"Godcmd": {"password": config.get("admin_password"), "admin_users": []} })
else:
plugin_config["Godcmd"]["password"] = config.get("admin_password")
pconf("Godcmd")["password"] = config.get("admin_password")
PluginManager().instances["GODCMD"].reload()

if config.get("group_app_map") and pconf("linkai"):
Expand Down
8 changes: 8 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,14 @@ def write_plugin_config(pconf: dict):
for k in pconf:
plugin_config[k.lower()] = pconf[k]

def remove_plugin_config(name: str):
"""
移除待重新加载的插件全局配置
:param name: 待重载的插件名
"""
global plugin_config
plugin_config.pop(name.lower(), None)


def pconf(plugin_name: str) -> dict:
"""
Expand Down
2 changes: 1 addition & 1 deletion plugins/godcmd/godcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def model_mapping(self, model) -> str:
return model

def reload(self):
gconf = plugin_config[self.name]
gconf = pconf(self.name)
if gconf:
if gconf.get("password"):
self.password = gconf["password"]
Expand Down
2 changes: 1 addition & 1 deletion plugins/linkai/linkai.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def _load_config_template(self):
plugin_conf = json.load(f)
plugin_conf["midjourney"]["enabled"] = False
plugin_conf["summary"]["enabled"] = False
plugin_config["linkai"] = plugin_conf
write_plugin_config({"linkai": plugin_conf})
return plugin_conf
except Exception as e:
logger.exception(e)
Expand Down
6 changes: 3 additions & 3 deletions plugins/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import json
from config import pconf, plugin_config, conf
from config import pconf, plugin_config, conf, write_plugin_config
from common.log import logger


Expand All @@ -24,13 +24,13 @@ def load_config(self) -> dict:
plugin_conf = json.load(f)

# 写入全局配置内存
plugin_config[self.name] = plugin_conf
write_plugin_config({self.name: plugin_conf})
logger.debug(f"loading plugin config, plugin_name={self.name}, conf={plugin_conf}")
return plugin_conf

def save_config(self, config: dict):
try:
plugin_config[self.name] = config
write_plugin_config({self.name: config})
# 写入全局配置
global_config_path = "./plugins/config.json"
if os.path.exists(global_config_path):
Expand Down
3 changes: 2 additions & 1 deletion plugins/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from common.log import logger
from common.singleton import singleton
from common.sorted_dict import SortedDict
from config import conf, write_plugin_config
from config import conf, remove_plugin_config, write_plugin_config

from .event import *

Expand Down Expand Up @@ -163,6 +163,7 @@ def activate_plugins(self): # 生成新开启的插件实例

def reload_plugin(self, name: str):
name = name.upper()
remove_plugin_config(name)
if name in self.instances:
for event in self.listening_plugins:
if name in self.listening_plugins[event]:
Expand Down

0 comments on commit 16324e7

Please sign in to comment.