Send a tweet to everyone

@param array $tweet
@throws MaxPushesPerHourException
@throws \Mcfedr\AwsPushBundle\Exception\PlatformNotConfiguredException
976388
public function pushTweet($tweet)
    {
        if ($this->maxPushesPerHour > 0 && $this->cache) {
            $hourAgo = new \DateTime('- 1 hour');
            /** @var \DateTime[] $tweetTimes */
            $tweetTimes = $this->cache->fetch(static::CACHE_KEY) ?: [];
            foreach ($tweetTimes as $k => $time) {
                if ($time < $hourAgo) {
                    unset($tweetTimes[$k]);
                }
            }
            if (($count = count($tweetTimes)) >= $this->maxPushesPerHour) {
                throw new MaxPushesPerHourException("Cannot send push, $count have already been sent. The limit is {$this->maxPushesPerHour}");
            }
            $tweetTimes[] = new \DateTime();
            $this->cache->save(static::CACHE_KEY, $tweetTimes, 3600);
        }

        $m = $this->getMessageForTweet($tweet);

        if ($this->topicArn) {
            $this->messages->send($m, $this->topicArn);
        } else {
            $this->messages->broadcast($m);
        }
    }
278651
public function whenTweets($twitterUserIds, callable $whenTweets)
    {
        if (! is_array($twitterUserIds)) {
            $twitterUserIds = [$twitterUserIds];
        }

        $this->stream->setFollow($twitterUserIds);

        $this->stream->performOnStreamActivity($whenTweets);

        return $this;
    }
379539
def send(
            self,
            *,
            text: str,
    ) -> List[OutputRecord]:
        
        try:
            status = self.api.update_status(text)
            self.ldebug(f"Status object from tweet: {status}.")
            return [TweetRecord(record_data={"tweet_id": status._json["id"], "text": text})]

        except tweepy.TweepError as e:
            return [self.handle_error(
                message=(f"Bot {self.bot_name} encountered an error when "
                 f"sending post {text} without media:\n{e}\n"),
                error=e)]
1148456
public function sendMessage(Message $msg)
    {
        if (is_callable($this->sendMessageFunction)) {
            call_user_func_array($this->sendMessageFunction, [$msg]);
        }
    }
220764
private function createTweet(array $tweet, User $user)
    {
        $this->fields = [
            'id'             => $this->getValue('id', $tweet),
            'text'           => $this->getValue('text', $tweet),
            'source'         => $this->getValue('source', $tweet),
            'url'            => $this->getValue('url', $tweet),
            'retweet_count'  => $this->getValue('retweet_count', $tweet),
            'favorite_count' => $this->getValue('favorite_count', $tweet),
            'created_at'     => $this->getValue('created_at', $tweet),
            'hashtags'       => $this->listHashTags($tweet),
            'user'           => $user
        ];
    }
1181759
public function publishTweetWithImage(string $status, string $imageFile): void
    {
        $media = $this->callPost(self::IMAGE_UPLOAD_URL, [
            'media' => base64_encode(FileSystem::read($imageFile)),
        ]);

        $this->callPost(self::UPDATE_URL, [
            'status' => $status,
            'media_ids' => $media['media_id'],
        ]);
    }
221534
public function setHashtagButton($hashtag = null): void
	{
		$this->element->addClass('twitter-hashtag-button');

		// Build URL
		$url = new Url(self::TWITTER_TWEET_URL);
		$url->setQueryParameter('button_hashtag', $hashtag);
		$this->href = (string) $url;

		if ($hashtag) {
			$this->elementText = 'Tweet #' . $hashtag;
		}
	}
8762
private static Tweets addTweets(User user, String body, Date tweetDate, String tweetId)
    {
        Tweets tweet = new Tweets();
        tweet.setTweetId(tweetId);
        tweet.setBody(body);
        tweet.setTweetDate(tweetDate);
        user.getTweets().add(tweet);
        return tweet;
    }
1208538
private function send(array $thrifts)
    {
        foreach ($this->chunkSplit($thrifts) as $chunk) {
            /* @var $chunk ThriftSpan[] */
            $this->client->emitZipkinBatch($chunk);
        }
    }
1008118
public function send($event, $vars)
    {
        /** @var NotificationEmail[] $notifications */
        $notifications = $this->getNotificationsEmail($event);

        $sites = $this->getContainer()->get('sonata.page.manager.site')->findAll();

        $vars['site'] = $sites[0];
        $vars['compo_core_settings'] = $this->getContainer()->get('compo_core.manager')->getSettings();
        $vars['compo_notification_email_settings'] = $this->getContainer()->get('sylius.settings_manager')->load(
            'compo_notification_email_settings'
        );

        $results = [];

        foreach ($notifications as $notification) {
            $recipients = $this->prepareEmails($notification->getRecipient(), $vars);

            foreach ($recipients as $email) {
                if (!$email) {
                    continue;
                }

                $subject = $this->renderTemplate($notification->getSubject(), $vars);
                $body = $this->renderTemplate($notification->getBody(), $vars);

                $sender = $notification->getSender();

                if (!$sender) {
                    $sender = $this->getDefaultSender();
                }

                if (!$sender) {
                    continue;
                }

                $from = $sender->getUsername();

                if ('smtp' === mb_strtolower($sender->getTransport())) {
                    $transport = (new \Swift_SmtpTransport($sender->getHostname(), $sender->getPort()))
                        ->setUsername($sender->getUsername())
                        ->setPassword($sender->getPassword());
                    $transport->setAuthMode(mb_strtolower($sender->getAuthMode()));
                    $transport->setEncryption(mb_strtolower($sender->getEncryption()));
                    $mailer = new \Swift_Mailer($transport);
                } else {
                    //$transport = new \Swift_SendmailTransport();
                    $mailer = $this->getContainer()->get('mailer');
                }

                /** @var \Swift_Message $message */
                $message = $mailer->createMessage();

                $message->setSubject($subject)
                    ->setFrom($from, $sender->getName())
                    ->setTo($email)
                    ->setBody($body, 'text/html');

                $mailer->send($message);

                $results[] = [
                    'notification' => $notification,
                    'vars' => $vars,
                    'recipient' => $email,
                    'subject' => $subject,
                    'body' => $body,
                ];
            }
        }

        $notificationsSms = $this->getNotificationsSms($event);

        foreach ($notificationsSms as $notification) {
            $recipients = $this->prepareEmails($notification->getRecipient(), $vars);

            foreach ($recipients as $email) {
                if (!$email) {
                    continue;
                }

                $transport = new SmsRuTransport();

                $body = $this->renderTemplate($notification->getBody(), $vars);

                $sender = $notification->getSender();

                $transport->setUsername($sender->getUsername());
                $transport->setPassword($sender->getPassword());
                $transport->setSender($sender->getSender());

                $transport->send($email, $body);

                $results[] = [
                    'notification' => $notification,
                    'vars' => $vars,
                    'recipient' => $email,
                    'subject' => '',
                    'body' => $body,
                ];
            }
        }

        return $results;
    }
78404
private function sendTransmission(array $payload)
    {
        try {
            /** @noinspection PhpUndefinedVariableInspection */
            $promise = $this->sparkpost->transmissions->post($payload);

            if ($promise instanceof SparkPostResponse) {
                $response = $promise;
            } else {
                $response = $promise->wait();
            }
        } catch (AnyException $exception) {
            throw $this->createAndDispatchTransportException(
                'Failed to send transmission to SparkPost',
                $exception
            );
        }

        if (!isset($response->getBody()['results'])) {
            throw $this->createAndDispatchTransportException(
                'Failed to send transmission to SparkPost',
                new Exception(json_encode($response->getBody()))
            );
        }

        return $response;
    }
1249980
public function send($responses)
    {
        if (!is_array($responses)) {
            $responses = array($responses);
        }

        foreach ($responses as $response) {
            $response .= "\r\n";
            fwrite($this->socket, $response);
            $this->log->debug('<-- ' . $response);

            if (isset($this->config['unflood'])) {
                usleep($this->config['unflood']);
            }
        }
    }
864
public function setTwitterImage($twitterImage, $locale = null)
    {
        $this->translate($locale, false)->setTwitterImage($twitterImage);
        $this->mergeNewTranslations();

        return $this;
    }
1295866
public function sendByUserId(int $userId, string $msg, ?string $dest = null, bool $flush = false) : void
    {
        $msg = $this->composeMsg($msg, $dest);

        foreach ($this->subscriptionTable->findActive()->where('user_id', $userId) as $row)
        {
            $this->sendNotification($row, $msg, false);
        }

        if ($flush)
        {
            $this->flush();
        }
    }
530884
protected function send($text)
    {
        $this->logger->debug('Sending: ' . $text);
        $this->lastCommandId = uniqid(__CLASS__);
        $action = new \PAMI\Message\Action\AGIAction($this->channel, $text, $this->lastCommandId);
        $this->lastAgiResult = false;
        $response = $this->pamiClient->send($action);
        if (!$response->isSuccess()) {
            throw new \PAGI\Exception\ChannelDownException($response->getMessage());
        }
        while ($this->lastAgiResult === false) {
            $this->pamiClient->process();
            usleep(1000);
        }
        return $this->getResultFromResultString($this->lastAgiResult);
    }
1352698
public function send(array $headers = array())
    {
        //if no socket
        if (!$this->socket) {
            //then connect
            $this->connect();
        }

        $headers    = $this->getHeaders($headers);
        $body       = $this->getBody();

        //add from
        if (!$this->call('MAIL FROM:<' . $this->username . '>', 250, 251)) {
            $this->disconnect();
            //throw exception
            Exception::i()
                ->setMessage(Exception::SMTP_ADD_EMAIL)
                ->addVariable($this->username)
                ->trigger();
        }

        //add to
        foreach ($this->to as $email => $name) {
            if (!$this->call('RCPT TO:<' . $email . '>', 250, 251)) {
                $this->disconnect();
                //throw exception
                Exception::i()
                    ->setMessage(Exception::SMTP_ADD_EMAIL)
                    ->addVariable($email)
                    ->trigger();
            }
        }

        //add cc
        foreach ($this->cc as $email => $name) {
            if (!$this->call('RCPT TO:<' . $email . '>', 250, 251)) {
                $this->disconnect();
                //throw exception
                Exception::i()
                    ->setMessage(Exception::SMTP_ADD_EMAIL)
                    ->addVariable($email)
                    ->trigger();
            }
        }

        //add bcc
        foreach ($this->bcc as $email => $name) {
            if (!$this->call('RCPT TO:<' . $email . '>', 250, 251)) {
                $this->disconnect();
                //throw exception
                Exception::i()
                    ->setMessage(Exception::SMTP_ADD_EMAIL)
                    ->addVariable($email)
                    ->trigger();
            }
        }

        //start compose
        if (!$this->call('DATA', 354)) {
            $this->disconnect();
            //throw exception
            Exception::i(Exception::SMTP_DATA)->trigger();
        }

        //send header data
        foreach ($headers as $name => $value) {
            $this->push($name.': '.$value);
        }

        //send body data
        foreach ($body as $line) {
            if (strpos($line, '.') === 0) {
                // Escape lines prefixed with a '.'
                $line = '.' . $line;
            }

            $this->push($line);
        }

        //tell server this is the end
        if (!$this->call(".", 250)) {
            $this->disconnect();
            //throw exception
            Exception::i(Exception::SMTP_DATA)->trigger();
        }

        //reset (some reason without this, this class spazzes out)
        $this->push('RSET');

        return $headers;
    }
461666
public function send(string $to, Sms $sms, array $params = []): bool
    {
        $content = $sms->content($this->agent_name);
        if (!$content) {
            throw new SmsException('The agent : ' . $this->agent_name . ' not supported by SMS');
        }
        $full_content = $this->getFullContent($content, $params);
        $this->result->setStatus(true)->setContent($full_content)->setParams($params);
        return true;
    }