feat: 支持指令操作热更新和热重载

This commit is contained in:
Rock Chin
2023-01-01 22:55:09 +08:00
parent 3b1a72358e
commit 7e83ba3f77

View File

@@ -14,6 +14,8 @@ import config
import pkg.openai.session
import pkg.openai.manager
import pkg.utils.reloader
import pkg.utils.updater
processing = []
@@ -157,6 +159,21 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes
if not (hasattr(config, 'include_image_description')
and not config.include_image_description):
reply.append(" ".join(params))
elif cmd == 'reload' and launcher_type == 'person' and launcher_id == config.admin_qq:
try:
pkg.utils.reloader.reload_all()
reply = ["[bot]已重新加载所有模块"]
except Exception as e:
logging.error("reload failed:{}".format(e))
reply = ["[bot]重载失败:{}".format(e)]
elif cmd == 'update' and launcher_type == 'person' and launcher_id == config.admin_qq:
try:
pkg.utils.updater.update_all()
pkg.utils.reloader.reload_all()
reply = ["[bot]已更新所有模块"]
except Exception as e:
logging.error("update failed:{}".format(e))
reply = ["[bot]更新失败:{}".format(e)]
except Exception as e:
mgr.notify_admin("{}指令执行失败:{}".format(session_name, e))
logging.exception(e)