[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/infrastructure/daemon/bot/handler/ -> PhabricatorBotWhatsNewHandler.php (source)

   1  <?php
   2  
   3  /**
   4   * Responds to "Whats new?" with some recent feed content
   5   */
   6  final class PhabricatorBotWhatsNewHandler extends PhabricatorBotHandler {
   7  
   8    private $floodblock = 0;
   9  
  10    public function receiveMessage(PhabricatorBotMessage $message) {
  11      switch ($message->getCommand()) {
  12        case 'MESSAGE':
  13          $message_body = $message->getBody();
  14          $now = time();
  15  
  16          $prompt = '~what( i|\')?s new\?~i';
  17          if (preg_match($prompt, $message_body)) {
  18            if ($now < $this->floodblock) {
  19              return;
  20            }
  21            $this->floodblock = $now + 60;
  22            $this->reportNew($message);
  23          }
  24          break;
  25      }
  26    }
  27  
  28    public function reportNew(PhabricatorBotMessage $message) {
  29      $latest = $this->getConduit()->callMethodSynchronous(
  30        'feed.query',
  31        array(
  32          'limit' => 5,
  33          'view'  => 'text',
  34        ));
  35  
  36      foreach ($latest as $feed_item) {
  37        if (isset($feed_item['text'])) {
  38          $this->replyTo($message, html_entity_decode($feed_item['text']));
  39        }
  40      }
  41    }
  42  
  43  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1