Daily build
This commit is contained in:
@@ -4,6 +4,9 @@ import pkgutil
|
||||
import sys
|
||||
|
||||
|
||||
from core.command_manager import matcher
|
||||
|
||||
|
||||
def load_all_plugins():
|
||||
"""
|
||||
扫描并加载当前包下所有的插件(支持文件和文件夹)
|
||||
@@ -24,12 +27,17 @@ def load_all_plugins():
|
||||
|
||||
try:
|
||||
if full_module_name in sys.modules:
|
||||
importlib.reload(sys.modules[full_module_name])
|
||||
module = importlib.reload(sys.modules[full_module_name])
|
||||
action = "重载"
|
||||
else:
|
||||
importlib.import_module(full_module_name)
|
||||
module = importlib.import_module(full_module_name)
|
||||
action = "加载"
|
||||
|
||||
# 提取插件元数据
|
||||
if hasattr(module, "__plugin_meta__"):
|
||||
meta = getattr(module, "__plugin_meta__")
|
||||
matcher.plugins[full_module_name] = meta
|
||||
|
||||
type_str = "包" if is_pkg else "文件"
|
||||
print(f" [{type_str}] 成功{action}: {module_name}")
|
||||
except Exception as e:
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
"""
|
||||
Echo 插件
|
||||
Echo 与交互插件
|
||||
|
||||
提供 /echo 指令,用于原样回复用户输入的内容。
|
||||
提供 /echo 和 /赞我 指令。
|
||||
"""
|
||||
from core.command_manager import matcher
|
||||
from core.bot import Bot
|
||||
from models import MessageEvent
|
||||
|
||||
__plugin_meta__ = {
|
||||
"name": "echo",
|
||||
"description": "提供 echo 和 赞我 功能",
|
||||
"usage": "/echo [内容] - 复读内容\n/赞我 - 让机器人给你点赞",
|
||||
}
|
||||
|
||||
@matcher.command("echo")
|
||||
async def handle_echo(bot: Bot, event: MessageEvent, args: list[str]):
|
||||
@@ -24,17 +29,18 @@ async def handle_echo(bot: Bot, event: MessageEvent, args: list[str]):
|
||||
|
||||
await event.reply(reply_msg)
|
||||
|
||||
@matcher.command("poke")
|
||||
@matcher.command("赞我")
|
||||
async def handle_poke(bot: Bot, event: MessageEvent, args: list[str]):
|
||||
"""
|
||||
处理 poke 指令,发送群戳一戳
|
||||
处理 赞我 指令,发送点赞
|
||||
|
||||
:param bot: Bot 实例
|
||||
:param event: 消息事件对象
|
||||
:param args: 指令参数列表(本指令不使用参数)
|
||||
"""
|
||||
|
||||
await bot.call_api("group_poke", {
|
||||
"group_id": event.group_id,
|
||||
"user_id": event.user_id
|
||||
})
|
||||
try:
|
||||
# 尝试发送赞
|
||||
await bot.send_like(event.user_id, times=10)
|
||||
await event.reply("戳一戳发送成功!")
|
||||
except Exception as e:
|
||||
await event.reply(f"戳一戳发送失败:{str(e)}")
|
||||
34
base_plugins/help.py
Normal file
34
base_plugins/help.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
帮助插件
|
||||
|
||||
提供 /help 指令,用于展示所有已加载插件的帮助信息。
|
||||
"""
|
||||
from core.command_manager import matcher
|
||||
from models.events.message import MessageEvent
|
||||
|
||||
__plugin_meta__ = {
|
||||
"name": "帮助",
|
||||
"description": "显示所有可用指令的帮助信息",
|
||||
"usage": "/help",
|
||||
}
|
||||
|
||||
@matcher.command("help")
|
||||
async def help_command(bot, event: MessageEvent):
|
||||
"""
|
||||
处理 /help 指令,生成并发送帮助信息
|
||||
|
||||
:param bot: Bot 实例
|
||||
:param event: 消息事件对象
|
||||
"""
|
||||
help_text = "--- 可用指令列表 ---\n"
|
||||
|
||||
for plugin_name, meta in matcher.plugins.items():
|
||||
name = meta.get("name", "未命名插件")
|
||||
description = meta.get("description", "暂无描述")
|
||||
usage = meta.get("usage", "暂无用法说明")
|
||||
|
||||
help_text += f"\n{name} ({plugin_name}):\n"
|
||||
help_text += f" 功能: {description}\n"
|
||||
help_text += f" 用法: {usage}\n"
|
||||
|
||||
await bot.send(event, help_text.strip())
|
||||
Reference in New Issue
Block a user