Send to slack the results of a scheduled command.

@todo: add success tag to adjust the color

@param  Event $event
@param        $channel

@return void
546678
static public function output(Event $event, $channel)
    {
        preg_match("/(artisan |'artisan' )(.*)/us", $event->command, $matches);
        $eventCommand = $matches[2];

        $event->sendOutputTo(base_path() . '/storage/logs/' . $eventCommand . '.txt');
        if (is_null($event->output)) {
            //if no output, don't send anything
            return;
        }

        $event->then(function () use ($event, $eventCommand, $channel) {
            $message = file_get_contents($event->output);

            Artisan::call('slack:post', [
                'to'     => $channel,
                'attach' => [
                    'color' => 'grey',
                    'title' => $eventCommand,
                    'text'  => $message
                ]
            ]);
        });
    }
228228
public function hangup($channel = false)
    {
        $cmd = 'HANGUP';
        if ($channel !== false) {
            $cmd .= ' "' . $channel . '"';
        }
        $result = $this->send($cmd);
        if ($result->isResult(-1)) {
            throw new ChannelDownException('Hangup failed');
        }
    }
426077
protected function fireAfterCommandEvent($command, $result)
	{
		$eventName = $this->commandNameToEventName($command);

		$args = [$command, $result];

		$this->fireEvent($eventName, 'after', $args);
	}
519201
public function send(Event $event)
    {
        $message = $this->getEventMessage($event);
        $this->flush($message);
    }
277945
public function sendMessage(Message $message): void
    {
        // Ensure the message will always be sent to the default channel if asked for.
        if ($this->options['sticky_channel']) {
            $message->setChannel($this->options['channel']);
        }

        $payload = $this->preparePayload($message);

        $encoded = \json_encode($payload, JSON_UNESCAPED_UNICODE);

        if (false === $encoded) {
            throw new \RuntimeException(\sprintf('JSON encoding error %s: %s', \json_last_error(), \json_last_error_msg()));
        }

        $this->httpClient->post('', [], $encoded);
    }
1069819
public function sendGetCalendarsToApp(Event $event, array $options = []): void
    {
        $eventName = preg_replace('/^(Plugin)/', 'App', $event->getName());
        if (empty($eventName)) {
            return;
        }

        $ev = new Event($eventName, $this, [
            'options' => $options
        ]);

        EventManager::instance()->dispatch($ev);

        $event->result = $ev->result;
    }
1370025
@Handler
    public void onOutput(Output<ByteBuffer> event,
            PlainChannel plainChannel)
            throws InterruptedException, SSLException, ExecutionException {
        if (plainChannel.hub() != this) {
            return;
        }
        plainChannel.sendUpstream(event);
    }
45712
public function onPrivmsg(Event $event)
    {
        if ($this->debug === false) {
            return;
        }

        $msg = $event->getMessage();
        $target = $msg['targets'][0];
        $msg = $msg['params']['text'];

        $send = function ($msg) use ($event, $target) {
            $writeStream = $event->getWriteStream();
            $writeStream->ircPrivmsg($target, $msg);
        };

        $m = [];
        $match = function ($pattern, &$m) use ($msg) {
            return preg_match($pattern, $msg, $m);
        };

        if ($match('#^ishere (\S+)$#', $m)) {
            $send($this->isIn($m[1], $target) ? 'true' : 'false');
        } elseif ($match('#^users (\S+)$#', $m)) {
            $chan = $m[1];
            $nicks = $this->getUsers($chan);
            foreach ($nicks as &$nick) {
                $prefix = '';
                foreach (self::$modesNum as $mode => $modeNum) {
                    if ($this->is($modeNum, $nick, $chan)) {
                        $prefix .= array_search($mode, self::$modesPrefix);
                    }
                }
                $nick = $prefix.$nick;
            }
            $send($nicks ? join(', ', $nicks) : 'unable to find channel');
        } elseif ($match('#^channels (\S+)$#', $m)) {
            $channels = $this->getChannels($m[1]);
            $send($channels ? join(', ', $channels) : 'unable to find nick');
        } elseif ($match('#^users (\S+)$#', $m)) {
            $nicks = $this->getUsers($m[1]);
            $send($nicks ? join(', ', $nicks) : 'unable to find channel');
        } elseif ($match('#^random (\S+)$#', $m)) {
            $nick = $this->getRandomUser($m[1]);
            $send($nick ? $nick : 'unable to find channel');
        }
    }
229710
protected function runSingleServerEvent($event)
    {
        if ($this->schedule->serverShouldRun($event, $this->startedAt)) {
            $this->runEvent($event);
        } else {
            $this->line('<info>Skipping command (has already run on another server):</info> '.$event->getSummaryForDisplay());
        }
    }
43673
public function onMode(Event $event)
    {
        $msg = $event->getMessage();
        $params = $msg['params'];

        $isValidMessage =
            isset($params['channel'], $params['params']) &&
            preg_match('/(?:\+|-)[hovaq+-]+/i', $params['mode'])
        ;

        if (!$isValidMessage) {
            return;
        }

        $chan = $params['channel'];
        $nicks = explode(' ', $params['params']);
        $modes = str_split($params['mode'], 1);

        $operation = array_shift($modes); // + or -
        while ($char = array_shift($modes)) {
            $nick = array_shift($nicks);
            $mode = self::$modesNum[$char];

            $userMode = $this->storage->getUserMode($nick, $chan);
            if (!$userMode) {
                $userMode = self::REGULAR;
            }

            switch ($operation) {
                case '+':
                    $userMode |= $mode;
                    break;
                case '-':
                    $userMode ^= $mode;
                    break;
            }

            $this->storage->setUserMode($nick, $chan, $userMode);
        }
    }
1199878
public function publish($channel, $message)
    {
        foreach ($this->getSubscribersForChannel($channel) as $handler) {
            call_user_func($handler, $message);
        }
    }
244317
public function onCommand($event)
    {
        $this->data['commands'][] = array(
            'command' => $event->getCommand(),
            'arguments' => $event->getArguments(),
            'executiontime' => $event->getExecutionTime(),
        );
    }
196483
public function onPart(Event $event)
    {
        $msg = $event->getMessage();

        if (!isset($msg['nick'])) {
            return;
        }

        $nick = $msg['nick'];
        $chan = $msg['params']['channels'];

        $this->storage->removeUser($nick, $chan);
    }
1243816
public function dispatch($command): void
    {
        $this->commandStack[] = $command;

        if ($this->executing) {
            return;
        }

        $this->transactionManager->begin();
        try {
            while ($command = array_shift($this->commandStack)) {
                $this->invokeHandler($command);
            }
            $this->eventPublisher->publishEvents();
            $this->transactionManager->commit();
        } catch (Exception $e) {
            $this->transactionManager->rollback();
            throw $e;
        }
    }
481654
public function notify(string $event, array $arguments = null)
    {
        if (isset($this->events[$event])) {
            foreach ($this->events[$event] as $priorityKey => $callbackKey) {
                $output = $this->subscriptions[$callbackKey]($this, $arguments ?? []);
                if (isset($output['stop']) && true === $output['stop']) {
                    break;
                }
            }
        }
    }
931313
public function receiveEvent(Event $event): void
    {
        $event->freeze();
        $schema = $event::schema();
        $curie = $schema->getCurie();

        $vendor = $curie->getVendor();
        $package = $curie->getPackage();
        $category = $curie->getCategory();

        foreach ($schema->getMixinIds() as $mixinId) {
            $this->dispatch($mixinId, $event);
        }

        foreach ($schema->getMixinCuries() as $mixinCurie) {
            $this->dispatch($mixinCurie, $event);
        }

        $this->dispatch($schema->getCurieMajor(), $event);
        $this->dispatch($curie->toString(), $event);

        $this->dispatch(sprintf('%s:%s:%s:*', $vendor, $package, $category), $event);
        $this->dispatch(sprintf('%s:%s:*', $vendor, $package), $event);
        $this->dispatch(sprintf('%s:*', $vendor), $event);
        $this->dispatch('*', $event);
    }
437824
protected function sendCommandToServer(string $command): void
	{
		$this->lastCommand = $command;

		$this->connection->write($command);
	}