Browse Source

plugins: support reload plugin

master
lanvent 1 year ago
parent
commit
300b7b9687
3 changed files with 25 additions and 1 deletions
  1. +14
    -0
      plugins/godcmd/godcmd.py
  2. +10
    -0
      plugins/plugin_manager.py
  3. +1
    -1
      plugins/sdwebui/sdwebui.py

+ 14
- 0
plugins/godcmd/godcmd.py View File

@@ -63,6 +63,11 @@ ADMIN_COMMANDS = {
"args": ["插件名", "优先级"], "args": ["插件名", "优先级"],
"desc": "设置指定插件的优先级,越大越优先", "desc": "设置指定插件的优先级,越大越优先",
}, },
"reloadp": {
"alias": ["reloadp", "重载插件"],
"args": ["插件名"],
"desc": "重载指定插件配置",
},
"enablep": { "enablep": {
"alias": ["enablep", "启用插件"], "alias": ["enablep", "启用插件"],
"args": ["插件名"], "args": ["插件名"],
@@ -216,6 +221,15 @@ class Godcmd(Plugin):
result = "插件" + args[0] + "优先级已设置为" + args[1] result = "插件" + args[0] + "优先级已设置为" + args[1]
else: else:
result = "插件不存在" result = "插件不存在"
elif cmd == "reloadp":
if len(args) != 1:
ok, result = False, "请提供插件名"
else:
ok = PluginManager().reload_plugin(args[0])
if ok:
result = "插件配置已重载"
else:
result = "插件不存在"
elif cmd == "enablep": elif cmd == "enablep":
if len(args) != 1: if len(args) != 1:
ok, result = False, "请提供插件名" ok, result = False, "请提供插件名"


+ 10
- 0
plugins/plugin_manager.py View File

@@ -96,6 +96,16 @@ class PluginManager:
self.listening_plugins[event].append(name) self.listening_plugins[event].append(name)
self.refresh_order() self.refresh_order()


def reload_plugin(self, name):
if name in self.instances:
for event in self.listening_plugins:
if name in self.listening_plugins[event]:
self.listening_plugins[event].remove(name)
del self.instances[name]
self.activate_plugins()
return True
return False
def load_plugins(self): def load_plugins(self):
self.load_config() self.load_config()
self.scan_plugins() self.scan_plugins()


+ 1
- 1
plugins/sdwebui/sdwebui.py View File

@@ -78,7 +78,7 @@ class SDWebUI(Plugin):
options = {**self.default_options, **rule_options} options = {**self.default_options, **rule_options}
params["prompt"] = params.get("prompt", "")+f", {prompt}" params["prompt"] = params.get("prompt", "")+f", {prompt}"
if len(options) > 0: if len(options) > 0:
logger.info("[SD] cover rule_options={}".format(rule_options))
logger.info("[SD] cover options={}".format(options))
self.api.set_options(options) self.api.set_options(options)
logger.info("[SD] params={}".format(params)) logger.info("[SD] params={}".format(params))
result = self.api.txt2img( result = self.api.txt2img(


Loading…
Cancel
Save