zhamao-framework/mybot.php

40 lines
874 B
PHP
Raw Permalink Normal View History

2022-08-13 17:00:29 +08:00
<?php
declare(strict_types=1);
use OneBot\Driver\Event\Http\HttpRequestEvent;
require 'vendor/autoload.php';
// 创建框架 App
2022-12-18 00:15:34 +08:00
$app = new ZM\ZMApplication();
2022-08-13 17:00:29 +08:00
// 传入自定义配置文件
$app->patchConfig([
'driver' => 'workerman',
]);
// 改变启动所需的参数
$app->patchArgs([
'--private-mode',
]);
// 如果有 Composer 依赖的插件,使用 enablePlugins 进行开启
$app->enablePlugins([
'a',
'b',
'c',
'd',
]);
// BotCommand 事件构造
2022-12-19 01:45:27 +08:00
$cmd = BotCommand::make('test')->on(function () {
2022-08-13 17:00:29 +08:00
ctx()->reply('test ok');
});
2022-12-19 01:45:27 +08:00
$event = BotEvent::make(type: 'message')->on(function () {
2022-08-13 17:00:29 +08:00
});
$app->addBotEvent($event);
$app->addBotCommand($cmd);
2022-12-18 00:15:34 +08:00
$app->addEvent(HttpRequestEvent::getName(), function (HttpRequestEvent $event) {
2022-08-13 17:00:29 +08:00
$event->withResponse(\OneBot\Http\HttpFactory::getInstance()->createResponse(503));
});
$app->run();