添加热重载,优化readme

This commit is contained in:
2026-01-01 20:14:45 +08:00
parent 3ba15d38f9
commit dc5fc265f1
5 changed files with 103 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
import importlib
import os
import pkgutil
import sys
def load_all_plugins():
@@ -14,11 +15,17 @@ def load_all_plugins():
full_module_name = f"{package_name}.{module_name}"
try:
importlib.import_module(full_module_name)
if full_module_name in sys.modules:
importlib.reload(sys.modules[full_module_name])
action = "重载"
else:
importlib.import_module(full_module_name)
action = "加载"
type_str = "" if is_pkg else "文件"
print(f" [{type_str}] 成功加载: {module_name}")
print(f" [{type_str}] 成功{action}: {module_name}")
except Exception as e:
print(f" 加载插件 {module_name} 失败: {e}")
print(f" {action if 'action' in locals() else '加载'}插件 {module_name} 失败: {e}")
load_all_plugins()

View File

@@ -23,3 +23,18 @@ async def handle_echo(bot: Bot, event: MessageEvent, args: list[str]):
reply_msg = " ".join(args)
await event.reply(reply_msg)
@matcher.command("poke")
async def handle_poke(bot: Bot, event: MessageEvent, args: list[str]):
"""
处理 echo 指令,原样回复用户输入的内容
:param bot: Bot 实例
:param event: 消息事件对象
:param args: 指令参数列表
"""
await bot.call_api("group_poke", {
"group_id": event.group_id,
"user_id": event.user_id
})