diff options
Diffstat (limited to 'lib/Chat/Command/Listener.php')
-rw-r--r-- | lib/Chat/Command/Listener.php | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/lib/Chat/Command/Listener.php b/lib/Chat/Command/Listener.php index de7a56807..bbdda8eda 100644 --- a/lib/Chat/Command/Listener.php +++ b/lib/Chat/Command/Listener.php @@ -41,33 +41,35 @@ class Listener { } public static function register(IEventDispatcher $dispatcher): void { - $dispatcher->addListener(ChatManager::EVENT_BEFORE_MESSAGE_SEND, static function (ChatParticipantEvent $event) { - $message = $event->getComment(); - $participant = $event->getParticipant(); - - /** @var self $listener */ - $listener = \OC::$server->get(self::class); - - if (strpos($message->getMessage(), '//') === 0) { - return; - } - - try { - /** @var Command $command */ - /** @var string $arguments */ - [$command, $arguments] = $listener->getCommand($message->getMessage()); - $command = $listener->commandService->resolveAlias($command); - } catch (DoesNotExistException $e) { - return; - } - - if (!$listener->executor->isCommandAvailableForParticipant($command, $participant)) { - $command = $listener->commandService->find('', 'help'); - $arguments = trim($message->getMessage()); - } - - $listener->executor->exec($event->getRoom(), $message, $command, $arguments, $participant); - }); + $dispatcher->addListener(ChatManager::EVENT_BEFORE_MESSAGE_SEND, [self::class, 'executeCommand']); + } + + public static function executeCommand(ChatParticipantEvent $event): void { + $message = $event->getComment(); + $participant = $event->getParticipant(); + + /** @var self $listener */ + $listener = \OC::$server->get(self::class); + + if (strpos($message->getMessage(), '//') === 0) { + return; + } + + try { + /** @var Command $command */ + /** @var string $arguments */ + [$command, $arguments] = $listener->getCommand($message->getMessage()); + $command = $listener->commandService->resolveAlias($command); + } catch (DoesNotExistException $e) { + return; + } + + if (!$listener->executor->isCommandAvailableForParticipant($command, $participant)) { + $command = $listener->commandService->find('', 'help'); + $arguments = trim($message->getMessage()); + } + + $listener->executor->exec($event->getRoom(), $message, $command, $arguments, $participant); } /** |