44 lines
1.5 KiB
PHP
Raw Normal View History

2022-08-13 17:00:29 +08:00
<?php
declare(strict_types=1);
namespace Module\Example;
2023-02-13 04:07:41 +08:00
use Choir\Http\ServerRequest;
2022-12-25 17:42:32 +08:00
use OneBot\Driver\Event\WebSocket\WebSocketMessageEvent;
use ZM\Annotation\Framework\BindEvent;
2022-08-13 17:00:29 +08:00
use ZM\Annotation\Http\Route;
use ZM\Annotation\Middleware\Middleware;
2022-12-28 22:05:03 +08:00
use ZM\Annotation\OneBot\BotCommand;
use ZM\Annotation\OneBot\CommandArgument;
use ZM\Annotation\OneBot\CommandHelp;
use ZM\Context\BotContext;
2022-08-13 17:00:29 +08:00
use ZM\Middleware\TimerMiddleware;
class Hello123
{
2023-02-24 23:09:37 +08:00
#[BindEvent(WebSocketMessageEvent::class, level: 5000)]
public function onMessage(WebSocketMessageEvent $event)
{
$Data = json_decode($event->getFrame()->getData(), true);
}
2022-08-13 17:00:29 +08:00
#[Route('/route', request_method: ['GET'])]
#[Route('/route/{id}', request_method: ['GET'])]
2022-08-13 17:00:29 +08:00
#[Middleware(TimerMiddleware::class)]
2023-02-24 23:09:37 +08:00
public function route(array $params, ServerRequest $request, \HttpRequestEvent $event, BotContext $ctx)
2022-08-13 17:00:29 +08:00
{
2023-02-13 04:07:41 +08:00
// 目前因内部实现限制,路由方法的参数必须按照这个顺序定义,可以省略,但是不能乱序
// 如果希望获取其他依赖,可以在现有参数后面继续添加
return 'Hello ZhamaoThis is the first 3.0 page' . ($params['id'] ?? '');
2022-08-13 17:00:29 +08:00
}
2022-12-25 17:42:32 +08:00
2022-12-28 22:05:03 +08:00
#[BotCommand('echo', 'echo')]
#[CommandArgument('text', '要回复的内容', required: true)]
#[CommandHelp('复读机', '只需要发送 echo+内容 即可自动复读', 'echo 你好 会回复 你好')]
public function repeat(\OneBotEvent $event, BotContext $context): void
{
$context->reply($event->getMessage());
}
2022-08-13 17:00:29 +08:00
}