2022-08-13 17:00:29 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
namespace Module\Example;
|
|
|
|
|
|
|
2022-12-25 17:42:32 +08:00
|
|
|
|
use OneBot\Driver\Event\WebSocket\WebSocketMessageEvent;
|
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;
|
2022-12-25 17:42:32 +08:00
|
|
|
|
use ZM\Annotation\OneBot\BotEvent;
|
2022-12-28 22:05:03 +08:00
|
|
|
|
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
|
|
|
|
|
|
{
|
|
|
|
|
|
#[Route('/route', request_method: ['GET'])]
|
|
|
|
|
|
#[Middleware(TimerMiddleware::class)]
|
|
|
|
|
|
public function route()
|
|
|
|
|
|
{
|
|
|
|
|
|
return 'Hello Zhamao!This is the first 3.0 page!';
|
|
|
|
|
|
}
|
2022-12-25 17:42:32 +08:00
|
|
|
|
|
|
|
|
|
|
#[BotEvent()]
|
2022-12-25 18:15:07 +08:00
|
|
|
|
public function onOBEvent(\OneBotEvent $event, WebSocketMessageEvent $messageEvent): void
|
2022-12-25 17:42:32 +08:00
|
|
|
|
{
|
|
|
|
|
|
logger()->info("收到了 {$event->getType()}.{$event->getDetailType()} 事件");
|
|
|
|
|
|
}
|
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
|
|
|
|
}
|