mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2025-09-24 15:36:23 +00:00
🐛 修复 get_message_id 被弃用的问题并简单修缮了代码格式 (#32)
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> Co-authored-by: Akarin~ <60691961+Asankilp@users.noreply.github.com>
This commit is contained in:
@ -114,30 +114,38 @@ async def call_function(
|
||||
recursive=True,
|
||||
)
|
||||
def on_plugin_file_change(event):
|
||||
if event.src_path.endswith(".py"):
|
||||
logger.info(f"文件变动: {event.src_path}")
|
||||
# 层层向上查找到插件目录
|
||||
dir_list: list[str] = event.src_path.split("/") # type: ignore
|
||||
dir_list[-1] = dir_list[-1].split(".", 1)[0]
|
||||
dir_list.reverse()
|
||||
for plugin_name in dir_list:
|
||||
if plugin := get_plugin(plugin_name):
|
||||
if plugin.module_path.endswith("__init__.py"):
|
||||
# 包插件
|
||||
if os.path.dirname(plugin.module_path).replace(
|
||||
"\\", "/"
|
||||
) in event.src_path.replace("\\", "/"):
|
||||
logger.debug(f"找到变动插件: {plugin.name},正在重新加载")
|
||||
reload_plugin(plugin)
|
||||
context.reset_all()
|
||||
break
|
||||
else:
|
||||
# 单文件插件
|
||||
if plugin.module_path == event.src_path:
|
||||
logger.debug(f"找到变动插件: {plugin.name},正在重新加载")
|
||||
reload_plugin(plugin)
|
||||
context.reset_all()
|
||||
break
|
||||
if not event.src_path.endswith(".py"):
|
||||
return
|
||||
|
||||
logger.info(f"文件变动: {event.src_path}")
|
||||
# 层层向上查找到插件目录
|
||||
dir_list: list[str] = event.src_path.split("/") # type: ignore
|
||||
dir_list[-1] = dir_list[-1].split(".", 1)[0]
|
||||
dir_list.reverse()
|
||||
|
||||
for plugin_name in dir_list:
|
||||
if not (plugin := get_plugin(plugin_name)):
|
||||
continue
|
||||
|
||||
if (
|
||||
plugin.module_path
|
||||
and plugin.module_path.endswith("__init__.py")
|
||||
and os.path.dirname(plugin.module_path).replace("\\", "/")
|
||||
in event.src_path.replace("\\", "/")
|
||||
): # 包插件
|
||||
logger.debug(f"找到变动插件: {plugin.name},正在重新加载")
|
||||
reload_plugin(plugin)
|
||||
context.reset_all()
|
||||
break
|
||||
else:
|
||||
logger.debug("未找到变动插件")
|
||||
return
|
||||
# 单文件插件
|
||||
if plugin.module_path != event.src_path:
|
||||
continue
|
||||
|
||||
logger.debug(f"找到变动插件: {plugin.name},正在重新加载")
|
||||
reload_plugin(plugin)
|
||||
context.reset_all()
|
||||
break
|
||||
else:
|
||||
logger.debug("未找到变动插件")
|
||||
return
|
||||
|
Reference in New Issue
Block a user