2023-01-01 22:52:27 +08:00
|
|
|
import logging
|
2023-01-02 00:35:36 +08:00
|
|
|
import threading
|
|
|
|
|
2023-01-01 22:52:27 +08:00
|
|
|
import importlib
|
|
|
|
import pkgutil
|
2023-01-01 23:18:32 +08:00
|
|
|
import pkg.utils.context
|
2023-01-15 22:23:18 +08:00
|
|
|
import pkg.plugin.host
|
2023-01-01 22:52:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
def walk(module, prefix=''):
|
2023-01-02 13:06:48 +08:00
|
|
|
"""遍历并重载所有模块"""
|
2023-01-01 22:52:27 +08:00
|
|
|
for item in pkgutil.iter_modules(module.__path__):
|
|
|
|
if item.ispkg:
|
|
|
|
walk(__import__(module.__name__ + '.' + item.name, fromlist=['']), prefix + item.name + '.')
|
|
|
|
else:
|
|
|
|
logging.info('reload module: {}'.format(prefix + item.name))
|
|
|
|
importlib.reload(__import__(module.__name__ + '.' + item.name, fromlist=['']))
|
|
|
|
|
|
|
|
|
2023-01-02 13:28:32 +08:00
|
|
|
def reload_all(notify=True):
|
2023-01-02 11:33:26 +08:00
|
|
|
# 解除bot的事件注册
|
|
|
|
import pkg
|
|
|
|
pkg.utils.context.get_qqbot_manager().unsubscribe_all()
|
2023-01-02 00:35:36 +08:00
|
|
|
# 执行关闭流程
|
|
|
|
logging.info("执行程序关闭流程")
|
|
|
|
import main
|
|
|
|
main.stop()
|
|
|
|
|
2023-01-02 13:06:48 +08:00
|
|
|
# 重载所有模块
|
2023-01-03 00:02:18 +08:00
|
|
|
pkg.utils.context.context['exceeded_keys'] = pkg.utils.context.get_openai_manager().key_mgr.exceeded
|
2023-01-01 23:18:32 +08:00
|
|
|
context = pkg.utils.context.context
|
2023-01-01 22:52:27 +08:00
|
|
|
walk(pkg)
|
|
|
|
importlib.reload(__import__('config'))
|
2023-01-02 00:35:36 +08:00
|
|
|
importlib.reload(__import__('main'))
|
2023-01-07 16:50:34 +08:00
|
|
|
importlib.reload(__import__('banlist'))
|
2023-01-01 23:18:32 +08:00
|
|
|
pkg.utils.context.context = context
|
2023-01-02 00:35:36 +08:00
|
|
|
|
2023-01-15 22:23:18 +08:00
|
|
|
# 重载插件
|
|
|
|
import plugins
|
|
|
|
walk(plugins)
|
|
|
|
|
2023-01-02 00:35:36 +08:00
|
|
|
# 执行启动流程
|
|
|
|
logging.info("执行程序启动流程")
|
2023-01-02 12:00:10 +08:00
|
|
|
threading.Thread(target=main.main, args=(False,), daemon=False).start()
|
2023-01-02 00:35:36 +08:00
|
|
|
|
|
|
|
logging.info('程序启动完成')
|
2023-01-02 13:28:32 +08:00
|
|
|
if notify:
|
|
|
|
pkg.utils.context.get_qqbot_manager().notify_admin("重载完成")
|