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-03-08 15:21:37 +08:00
|
|
|
import pkg.utils.context as context
|
2023-01-15 22:23:18 +08:00
|
|
|
import pkg.plugin.host
|
2023-01-01 22:52:27 +08:00
|
|
|
|
|
|
|
|
2023-03-05 16:04:45 +08:00
|
|
|
def walk(module, prefix='', path_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:
|
2023-03-05 16:04:45 +08:00
|
|
|
|
|
|
|
walk(__import__(module.__name__ + '.' + item.name, fromlist=['']), prefix + item.name + '.', path_prefix + item.name + '/')
|
2023-01-01 22:52:27 +08:00
|
|
|
else:
|
2023-03-05 16:04:45 +08:00
|
|
|
logging.info('reload module: {}, path: {}'.format(prefix + item.name, path_prefix + item.name + '.py'))
|
|
|
|
pkg.plugin.host.__current_module_path__ = "plugins/" + path_prefix + item.name + '.py'
|
2023-01-01 22:52:27 +08:00
|
|
|
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
|
2023-03-08 15:21:37 +08:00
|
|
|
context.get_qqbot_manager().unsubscribe_all()
|
2023-01-02 00:35:36 +08:00
|
|
|
# 执行关闭流程
|
|
|
|
logging.info("执行程序关闭流程")
|
|
|
|
import main
|
|
|
|
main.stop()
|
|
|
|
|
2023-03-30 19:11:39 +08:00
|
|
|
# 删除所有已注册的指令
|
2023-04-06 18:37:07 +08:00
|
|
|
import pkg.qqbot.cmds.aamgr as cmdsmgr
|
2023-03-30 19:11:39 +08:00
|
|
|
cmdsmgr.__command_list__ = {}
|
|
|
|
cmdsmgr.__tree_index__ = {}
|
|
|
|
|
2023-01-02 13:06:48 +08:00
|
|
|
# 重载所有模块
|
2023-03-08 15:21:37 +08:00
|
|
|
context.context['exceeded_keys'] = context.get_openai_manager().key_mgr.exceeded
|
|
|
|
this_context = context.context
|
2023-01-01 22:52:27 +08:00
|
|
|
walk(pkg)
|
2023-03-23 21:29:51 +08:00
|
|
|
importlib.reload(__import__("config-template"))
|
2023-01-01 22:52:27 +08:00
|
|
|
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-04-07 13:28:07 +08:00
|
|
|
importlib.reload(__import__('tips'))
|
2023-03-08 15:21:37 +08:00
|
|
|
context.context = this_context
|
2023-01-02 00:35:36 +08:00
|
|
|
|
2023-01-15 22:23:18 +08:00
|
|
|
# 重载插件
|
|
|
|
import plugins
|
|
|
|
walk(plugins)
|
|
|
|
|
2023-04-07 13:25:57 +08:00
|
|
|
# 初始化相关文件
|
|
|
|
main.check_file()
|
|
|
|
|
2023-01-02 00:35:36 +08:00
|
|
|
# 执行启动流程
|
|
|
|
logging.info("执行程序启动流程")
|
2023-03-23 21:29:51 +08:00
|
|
|
main.load_config()
|
2023-04-07 16:02:22 +08:00
|
|
|
main.complete_tips()
|
2023-03-08 15:21:37 +08:00
|
|
|
context.get_thread_ctl().reload(
|
|
|
|
admin_pool_num=context.get_config().admin_pool_num,
|
|
|
|
user_pool_num=context.get_config().user_pool_num
|
|
|
|
)
|
|
|
|
context.get_thread_ctl().submit_sys_task(
|
|
|
|
main.start,
|
|
|
|
False
|
|
|
|
)
|
2023-01-02 00:35:36 +08:00
|
|
|
|
|
|
|
logging.info('程序启动完成')
|
2023-01-02 13:28:32 +08:00
|
|
|
if notify:
|
2023-03-08 15:21:37 +08:00
|
|
|
context.get_qqbot_manager().notify_admin("重载完成")
|