From dcee7d263fe5021861ce4ab8574db55947c7d426 Mon Sep 17 00:00:00 2001 From: Peaksol Date: Sat, 30 Nov 2024 20:29:47 +0800 Subject: [PATCH 1/2] fix issue adding event listener with object --- src/OneBot/Driver/Event/EventProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OneBot/Driver/Event/EventProvider.php b/src/OneBot/Driver/Event/EventProvider.php index e8c77eb..2ed4ae3 100644 --- a/src/OneBot/Driver/Event/EventProvider.php +++ b/src/OneBot/Driver/Event/EventProvider.php @@ -32,7 +32,7 @@ public function addEventListener($event, callable $callback, int $level = 20) * NOTE: 如果使用自定义名称,则需要在事件处理器中使用 `$event->getName()` 获取事件名 * NOTE: 或者是否由其他可能的方法支持自定义名称,从而避免频繁的 new EventDispatcher */ - if (!is_object($event)) { + if (is_object($event)) { $event = get_class($event); } self::$_events[$event][] = [$level, $callback]; From 4867f150a3d65e3746d27741fca4e21996179774 Mon Sep 17 00:00:00 2001 From: Peaksol Date: Sat, 30 Nov 2024 20:35:02 +0800 Subject: [PATCH 2/2] add `self` field to EventBuilder --- src/OneBot/V12/EventBuilder.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/OneBot/V12/EventBuilder.php b/src/OneBot/V12/EventBuilder.php index 8ace3e9..2a44d84 100644 --- a/src/OneBot/V12/EventBuilder.php +++ b/src/OneBot/V12/EventBuilder.php @@ -23,6 +23,10 @@ public function __construct(string $type, string $detail_type = '', string $sub_ $this->data['time'] = $time ?? time(); $this->data['detail_type'] = $detail_type; $this->data['sub_type'] = $sub_type; + $this->data['self'] = [ + 'platform' => OneBot::getInstance()->getPlatform(), + 'user_id' => OneBot::getInstance()->getSelfId(), + ]; } public function feed(string $key, $value): EventBuilder