add adapter feature (#121)

This commit is contained in:
sunxyw
2022-05-09 16:39:09 +08:00
committed by GitHub
parent 2481124ada
commit a6401fa9ef
6 changed files with 363 additions and 9 deletions

View File

@@ -10,9 +10,11 @@ use Doctrine\Common\Annotations\AnnotationException;
use Error;
use Exception;
use Throwable;
use ZM\Adapters\OneBot11Adapter;
use ZM\Config\ZMConfig;
use ZM\Console\Console;
use ZM\Exception\InterruptException;
use ZM\Module\QQBot;
use ZM\Store\LightCacheInside;
use ZM\Store\Lock\SpinLock;
use ZM\Store\ZMAtomic;
@@ -117,6 +119,11 @@ class EventDispatcher
{
try {
foreach ((EventManager::$events[$this->class] ?? []) as $v) {
// if ($v->class === QQBot::class && $v->method === 'handleByEvent') {
// zm_dump(EventManager::$events[$this->class]);
// $v->class = OneBot11Adapter::class;
// $v->method = 'handleIncomingRequest';
// }
$this->dispatchEvent($v, $this->rule, ...$params);
if ($this->log) {
Console::verbose("[事件分发{$this->eid}] 单一对象 " . $v->class . '::' . (is_string($v->method) ? $v->method : '{closure}') . ' 分发结束。');

View File

@@ -14,6 +14,8 @@ use Swoole\Coroutine;
use Swoole\Database\PDOConfig;
use Swoole\Process;
use Swoole\WebSocket\Server;
use ZM\Adapters\AdapterInterface;
use ZM\Adapters\OneBot11Adapter;
use ZM\Annotation\AnnotationParser;
use ZM\Annotation\Swoole\OnMessageEvent;
use ZM\Annotation\Swoole\OnStart;
@@ -30,7 +32,6 @@ use ZM\Event\SwooleEvent;
use ZM\Exception\DbException;
use ZM\Exception\ZMKnownException;
use ZM\Framework;
use ZM\Module\QQBot;
use ZM\MySQL\MySQLPool;
use ZM\Store\LightCacheInside;
use ZM\Store\MySQL\SqlPoolStorage;
@@ -215,8 +216,8 @@ class OnWorkerStart implements SwooleEvent
Console::debug('OneBot support enabled, listening OneBot event(3).');
$obj = new OnMessageEvent();
$obj->connect_type = 'qq';
$obj->class = QQBot::class;
$obj->method = 'handleByEvent';
$obj->class = AdapterInterface::class;
$obj->method = 'handleIncomingRequest';
$obj->level = $obb_onebot['message_level'] ?? 99;
EventManager::addEvent(OnMessageEvent::class, $obj);
if ($obb_onebot['single_bot_mode']) {
@@ -310,5 +311,7 @@ class OnWorkerStart implements SwooleEvent
// 基础
$container->instance('server', $server);
$container->instance('worker_id', $server->worker_id);
$container->singleton(AdapterInterface::class, OneBot11Adapter::class);
}
}