From 53824b7126a3e1155011e8d3ded4a0bd5c1d56dc Mon Sep 17 00:00:00 2001 From: netkas Date: Mon, 4 Nov 2024 01:16:35 -0500 Subject: [PATCH] Add method to retrieve event handlers by command --- src/TgBotLib/Bot.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/TgBotLib/Bot.php b/src/TgBotLib/Bot.php index 40e1888..e024d34 100644 --- a/src/TgBotLib/Bot.php +++ b/src/TgBotLib/Bot.php @@ -289,6 +289,27 @@ return $results; } + /** + * Retrieves an array of event handlers that correspond to the specified command. + * + * @param string $command The command to filter the event handlers by. + * @return array The array of event handlers that match the specified command. + */ + public function getEventHandlersByCommand(string $command): array + { + $results = []; + /** @var UpdateEvent $eventHandler */ + foreach($this->eventHandlers as $eventHandler) + { + if(strtolower($eventHandler::getCommand()) === strtolower($command)) + { + $results[] = $eventHandler; + } + } + + return $results; + } + /** * Removes all event handlers. *