/** * @param $type * @param $message * @return null */ public function send($type, $message) { if (false === $this->isFiltered($type)) { $options = ['in_logger' => true]; $this->slackFacade->multiSendMessage($this->channels, '```' . substr($message, 0, 3000) . '```', $options); } }
/** * Processes !-command * @param RequestDto $dto */ public function processCommand(RequestDto $dto) { $words = preg_split('/\\s+/is', $dto->getText()); $command = Ar::get($words, 0); if (null === $command || '!' !== substr($command, 0, 1)) { return; } $command = substr($command, 1); Logger::get()->info("id: %s, %s is executing command \"%s\" at %s", $dto->getId(), $dto->getUser(), $dto->getText(), $dto->getChannel()); /** @var BaseCommandHandler $commandHandler */ foreach ($this->commandHandlers as $commandHandler) { $commandName = $commandHandler->getName(); if (is_array($commandName)) { if (!in_array($command, $commandName)) { continue; } } else { if ($commandName !== $command) { continue; } } $allowed = $this->checkAccess($dto, $commandHandler); if (!$allowed) { $this->slackFacade->multiSendMessage([$dto->getChannel()], sprintf('SYSTEM: access to command !%s denied', $commandHandler->getName())); Logger::get()->warning("id: %s, access denied for %s trying to run \"%s\" at %s", $dto->getId(), $dto->getUser(), $dto->getText(), $dto->getChannel()); return; } unset($words[0]); if ($commandHandler->canProcessCommand($words, $dto->getChannel())) { /** @var SlackFacade $slackFacade */ $slackFacade = Registry::get('container')['slack_facade']; $commandHandler->setCallerId($dto->getUser()); $commandHandler->setCallerName($slackFacade->getUserNameById($dto->getUser())); Logger::get()->debug("id: %s, starting %s command handler", $dto->getId(), $commandHandler->getName()); $commandHandler->processCommand($words, $dto->getChannel()); Logger::get()->debug("id: %s, finished %s command handler", $dto->getId(), $commandHandler->getName()); } } }
/** @test */ public function shouldNotMultiSendMessageToEmptyList() { $slackApiMock = \Mockery::mock('\\slackbot\\models\\SlackApi'); $slackApiMock->shouldReceive('chatPostMessage')->never(); $slackFacade = new SlackFacade($slackApiMock); $slackFacade->multiSendMessage([], 'Test message', ['as_user' => true]); }
/** * @param ActionDto $dto */ public function sendMessage(ActionDto $dto) { $recipients = $this->parseRecipients($dto->getRecipients()); $this->slackFacade->multiSendMessage($recipients, $dto->getMessage(), ['as_user' => true]); }