2021-11-02 16:01:24 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
require_once 'vendor/autoload.php';
|
2021-11-02 16:01:24 +08:00
|
|
|
|
|
|
|
|
|
|
use ZM\Annotation\CQ\CQCommand;
|
|
|
|
|
|
use ZM\Annotation\Swoole\OnOpenEvent;
|
|
|
|
|
|
use ZM\ConnectionManager\ConnectionObject;
|
|
|
|
|
|
use ZM\Console\Console;
|
|
|
|
|
|
use ZM\Module\InstantModule;
|
|
|
|
|
|
use ZM\ZMServer;
|
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
|
$weather = new InstantModule('weather');
|
2021-11-02 16:01:24 +08:00
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
|
$weather->onEvent(OnOpenEvent::class, ['connect_type' => 'qq'], function (ConnectionObject $conn) {
|
|
|
|
|
|
Console::info('机器人 ' . $conn->getOption('connect_id') . ' 已连接!');
|
2021-11-02 16:01:24 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
|
$weather->onEvent(CQCommand::class, ['match' => '你好'], function () {
|
|
|
|
|
|
ctx()->reply('hello呀!');
|
2021-11-02 16:01:24 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
|
$app = new ZMServer('app-name');
|
2021-11-02 16:01:24 +08:00
|
|
|
|
$app->addModule($weather);
|
2022-03-15 18:05:33 +08:00
|
|
|
|
$app->run();
|