39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from core.plugin import Plugin, command, on_message
|
|
from models.events.message import MessageEvent
|
|
from core.permission import Permission
|
|
|
|
# 插件元信息
|
|
__plugin_meta__ = {
|
|
"name": "类风格插件示例",
|
|
"description": "演示如何使用类风格编写插件",
|
|
"usage": "/hello - 打招呼\n/echo <msg> - 复读消息",
|
|
}
|
|
|
|
class MyPlugin(Plugin):
|
|
def __init__(self):
|
|
super().__init__()
|
|
# 可以在这里初始化一些状态
|
|
self.count = 0
|
|
|
|
@command("hello")
|
|
async def hello(self, event: MessageEvent, args: list[str]):
|
|
self.count += 1
|
|
await self.reply(event, f"Hello from class-based plugin! (Called {self.count} times)")
|
|
|
|
@command("echo", permission=Permission.USER)
|
|
async def echo(self, event: MessageEvent, args: list[str]):
|
|
if args:
|
|
await self.reply(event, " ".join(args))
|
|
else:
|
|
await self.reply(event, "请输入要复读的内容。")
|
|
|
|
@on_message()
|
|
async def handle_message(self, event: MessageEvent):
|
|
# 这是一个通用的消息处理器,会处理所有消息
|
|
# 注意:这可能会与命令冲突,通常需要过滤
|
|
if "特定关键词" in event.raw_message:
|
|
await self.reply(event, "检测到特定关键词!")
|
|
|
|
# 实例化插件以注册
|
|
plugin = MyPlugin()
|