mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-19 02:46:09 +00:00
perf: 完善重载后的启动流程
This commit is contained in:
@@ -87,6 +87,7 @@ def main(first_time_init=False):
|
|||||||
try:
|
try:
|
||||||
time.sleep(10000)
|
time.sleep(10000)
|
||||||
if qqbot != pkg.utils.context.get_qqbot_manager(): # 已经reload了
|
if qqbot != pkg.utils.context.get_qqbot_manager(): # 已经reload了
|
||||||
|
logging.info("以前的main流程由于reload退出")
|
||||||
break
|
break
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
stop()
|
stop()
|
||||||
@@ -103,15 +104,6 @@ def stop():
|
|||||||
qqbot_inst = pkg.utils.context.get_qqbot_manager()
|
qqbot_inst = pkg.utils.context.get_qqbot_manager()
|
||||||
assert isinstance(qqbot_inst, pkg.qqbot.manager.QQBotManager)
|
assert isinstance(qqbot_inst, pkg.qqbot.manager.QQBotManager)
|
||||||
|
|
||||||
# try:
|
|
||||||
# asyncio.run(qqbot_inst.bot.shutdown())
|
|
||||||
# except ValueError:
|
|
||||||
# pass
|
|
||||||
#
|
|
||||||
# import mirai.utils
|
|
||||||
# MiraiRunner.__class__._instance = None
|
|
||||||
# mirai.utils.Singleton._instance = None
|
|
||||||
|
|
||||||
pkg.utils.context.get_openai_manager().key_mgr.dump_fee()
|
pkg.utils.context.get_openai_manager().key_mgr.dump_fee()
|
||||||
for session in pkg.openai.session.sessions:
|
for session in pkg.openai.session.sessions:
|
||||||
logging.info('持久化session: %s', session)
|
logging.info('持久化session: %s', session)
|
||||||
|
|||||||
+7
-12
@@ -161,21 +161,16 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes
|
|||||||
and not config.include_image_description):
|
and not config.include_image_description):
|
||||||
reply.append(" ".join(params))
|
reply.append(" ".join(params))
|
||||||
elif cmd == 'reload' and launcher_type == 'person' and launcher_id == config.admin_qq:
|
elif cmd == 'reload' and launcher_type == 'person' and launcher_id == config.admin_qq:
|
||||||
try:
|
def reload_task():
|
||||||
# pkg.utils.reloader.reload_all()
|
pkg.utils.reloader.reload_all()
|
||||||
threading.Thread(target=pkg.utils.reloader.reload_all, daemon=True).start()
|
|
||||||
# reply = ["[bot]已重新加载所有模块"]
|
threading.Thread(target=reload_task, daemon=True).start()
|
||||||
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:
|
elif cmd == 'update' and launcher_type == 'person' and launcher_id == config.admin_qq:
|
||||||
try:
|
def update_task():
|
||||||
pkg.utils.updater.update_all()
|
pkg.utils.updater.update_all()
|
||||||
pkg.utils.reloader.reload_all()
|
pkg.utils.reloader.reload_all()
|
||||||
reply = ["[bot]已更新所有模块"]
|
|
||||||
except Exception as e:
|
threading.Thread(target=update_task, daemon=True).start()
|
||||||
logging.error("update failed:{}".format(e))
|
|
||||||
reply = ["[bot]更新失败:{}".format(e)]
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
mgr.notify_admin("{}指令执行失败:{}".format(session_name, e))
|
mgr.notify_admin("{}指令执行失败:{}".format(session_name, e))
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ def reload_all():
|
|||||||
|
|
||||||
# 执行启动流程
|
# 执行启动流程
|
||||||
logging.info("执行程序启动流程")
|
logging.info("执行程序启动流程")
|
||||||
main.main()
|
threading.Thread(target=main.main, args=(False,), daemon=False).start()
|
||||||
|
|
||||||
logging.info('程序启动完成')
|
logging.info('程序启动完成')
|
||||||
|
pkg.utils.context.get_qqbot_manager().notify_admin("重载完成")
|
||||||
|
|||||||
Reference in New Issue
Block a user