From ac8869daf065361aa87ce8c923b6b5e59b9159fb Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 13 Sep 2024 16:32:02 +0200 Subject: [PATCH] Fix getEventHandler when passing the class name of the main event handler class --- docs | 2 +- src/EventHandler/Message/Entities/MessageEntity.php | 1 + src/Ipc/Client.php | 3 +++ src/Wrappers/Events.php | 7 +++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs b/docs index fde9838eb..ebe6a3f62 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit fde9838eb2e7cdd541f522410f61cac19a0c09d0 +Subproject commit ebe6a3f62fb93a903c7b203d0ab51cd09380bdb9 diff --git a/src/EventHandler/Message/Entities/MessageEntity.php b/src/EventHandler/Message/Entities/MessageEntity.php index a80f237a6..e1455ca70 100644 --- a/src/EventHandler/Message/Entities/MessageEntity.php +++ b/src/EventHandler/Message/Entities/MessageEntity.php @@ -44,6 +44,7 @@ abstract class MessageEntity implements JsonSerializable 'italic', 'messageEntityItalic' => new Italic($entity['offset'], $entity['length']), 'url', 'messageEntityUrl' => new Url($entity['offset'], $entity['length']), 'code', 'messageEntityCode' => new Code($entity['offset'], $entity['length']), + /** @psalm-suppress MixedArgument */ 'pre', 'messageEntityPre' => new Pre($entity['offset'], $entity['length'], $entity['language'] ?? ''), 'text_link', 'messageEntityTextUrl' => new TextUrl($entity['offset'], $entity['length'], $entity['url']), 'text_mention', 'messageEntityMentionName' => new MentionName($entity['offset'], $entity['length'], $entity['user_id'] ?? $entity['user']['id']), diff --git a/src/Ipc/Client.php b/src/Ipc/Client.php index f501925eb..6ab3ba097 100644 --- a/src/Ipc/Client.php +++ b/src/Ipc/Client.php @@ -363,6 +363,9 @@ final class Client extends ClientAbstract public function getEventHandler(?string $class = null): ?EventHandlerProxy { if ($class !== null) { + if ($class === $this->getEventHandlerClass()) { + return new EventHandlerProxy(null, $this); + } return $this->getPlugin($class); } return $this->hasEventHandler() ? new EventHandlerProxy(null, $this) : null; diff --git a/src/Wrappers/Events.php b/src/Wrappers/Events.php index b7bc9bf57..190be417d 100644 --- a/src/Wrappers/Events.php +++ b/src/Wrappers/Events.php @@ -163,6 +163,13 @@ trait Events } return $this->event_handler_instance; } + /** @internal */ + public function getEventHandlerClass(): ?string + { + return $this->event_handler_instance !== null + ? $this->event_handler_instance::class + : null; + } /** * Check if an event handler instance is present. */