Esempio n. 1
0
 function webhook()
 {
     $telegram = app('telegram')->bot();
     $message = $telegram->getWebhookUpdates()->getMessage();
     if (!$message || !$message->getFrom()) {
         return response('OK');
     }
     AsukaDB::createOrUpdateUser($message->getFrom());
     if (Helpers::isGroup($message->getChat())) {
         // Store this group if it's a new group or the title was updated
         if ($message->getGroupChatCreated() || $message->getSupergroupChatCreated() || $message->getNewChatParticipant()) {
             AsukaDB::createOrUpdateGroup($message->getChat());
         }
         if ($message->getNewChatTitle()) {
             AsukaDB::updateGroup($message->getChat());
         }
         // Check if this group is authorised to use the bot
         if (!Helpers::groupIsAuthorized($message->getChat())) {
             return response('OK');
         }
     }
     if (AsukaDB::getUser($message->getFrom()->getId())->ignored) {
         return response('OK');
     }
     $telegram->commandsHandler(true);
     return response('OK');
 }
Esempio n. 2
0
        </div>
        <table class="table table-bordered">
            <thead>
            <tr>
                <th>ID</th>
                <th>From</th>
                <th>Content</th>
                <th>Date</th>
                <th>Comment</th>
            </tr>
            </thead>
            <tbody>
            @foreach ($quotes as $quote)
                <tr id="{{ $quote->id }}">
                    <?php 
$quotee = \Asuka\Http\AsukaDB::getUser($quote->user_id);
$citation = $quotee->first_name;
if ($quotee->last_name) {
    $citation .= sprintf(' %s', $quotee->last_name);
}
if ($quotee->username) {
    $citation .= sprintf(' (@%s)', $quotee->username);
}
?>
                    <td><a href="#{{ $quote->id }}">{{ $quote->id }}</a></td>
                    <td>{{ $citation }}</td>
                    <td>{{ $quote->content }}</td>
                    <td>{{ date('D, jS M Y H:i:s T', $quote->message_timestamp) }}</td>
                    <td>{{ $quote->comment ?: 'N/A' }}</td>
                    @endforeach
                </tr>
Esempio n. 3
0
 public function handle($arguments)
 {
     $message = $this->getUpdate()->getMessage();
     // Detect a reply and add it as a quote
     $quoteSource = $message->getReplyToMessage();
     if ($quoteSource) {
         if (!Helpers::isGroup($message->getChat())) {
             $this->reply('You can only add quotes in a group.');
             return;
         }
         if (Helpers::userIsMe($quoteSource->getFrom())) {
             $this->reply('You cannot quote me >:)');
             return;
         }
         if (Helpers::isCommand($quoteSource)) {
             $this->reply('Don\'t be silly, why would you quote commands?');
             return;
         }
         if (Helpers::usersAreSame($message->getFrom(), $quoteSource->getFrom())) {
             $this->reply('Why would you quote yourself? What are you, some kind of loner?');
             return;
         }
         if (!$message->isType('text')) {
             $this->reply(sprintf('I cannot quote %s messages, please send me a text message.', $message->detectType()));
             return;
         }
         $result = AsukaDB::createQuote($message);
         if ($result) {
             $this->reply(sprintf('Quote saved as #%d', $result), ['reply_to_message_id' => $quoteSource->getMessageId()]);
         }
         return;
     }
     if ($arguments) {
         $arguments = explode(' ', $arguments);
         $quoteId = intval(preg_replace('/[^0-9]/', '', $arguments[0]));
         if (!$quoteId) {
             $this->reply('Please supply a numeric quote ID.');
             return;
         }
         $quote = AsukaDB::getQuote($quoteId);
     } else {
         // Random quote
         $quote = AsukaDB::getQuote();
     }
     if (!$quote) {
         $quoteCount = app('db')->connection()->table('quotes')->count() + 1;
         /* Since when were SQL COUNTs 0-indexed? */
         if ($quoteCount === 0) {
             $this->reply('I don\'t have any quotes saved yet!');
         } elseif (isset($quoteId) && ($quoteId < 1 || $quoteId > $quoteCount)) {
             $this->reply(sprintf('Invalid quote ID. Valid values are between 1 and %d.', $quoteCount));
         } else {
             $this->reply('No quote found!');
         }
         return;
     }
     $response = sprintf('<b>%s</b>' . PHP_EOL, Helpers::escapeMarkdown($quote->content));
     $quotee = AsukaDB::getUser($quote->user_id);
     $quoter = AsukaDB::getUser($quote->added_by_id);
     $citation = $quotee->first_name;
     if ($quotee->last_name) {
         $citation .= sprintf(' %s', $quotee->last_name);
     }
     if ($quotee->username) {
         $citation .= sprintf(' (%s)', $quotee->username);
     }
     $response .= sprintf('-- <i>%s, %s (#%d)</i>' . PHP_EOL, Helpers::escapeMarkdown($citation), date('D, jS M Y H:i:s T', $quote->message_timestamp), $quote->id);
     $addedBy = $quoter->first_name;
     if ($quoter->last_name) {
         $addedBy .= sprintf(' %s', $quoter->last_name);
     }
     if ($quoter->username) {
         $addedBy .= sprintf(' (%s)', $quoter->username);
     }
     $response .= sprintf(PHP_EOL . 'Added by %s' . PHP_EOL, Helpers::escapeMarkdown($addedBy));
     if ($quote->comment) {
         $response .= sprintf('Comment: %s', Helpers::escapeMarkdown($quote->comment));
     }
     $this->reply($response, ['disable_web_page_preview' => true, 'parse_mode' => 'HTML']);
 }