コード例 #1
0
 public function receiveMessage(PhabricatorIRCMessage $message)
 {
     switch ($message->getCommand()) {
         case 'PRIVMSG':
             $reply_to = $message->getReplyTo();
             if (!$reply_to) {
                 break;
             }
             if (!$this->isChannelName($reply_to)) {
                 // Don't log private messages, although maybe we should for debugging?
                 break;
             }
             $logs = array(array('channel' => $reply_to, 'type' => 'mesg', 'epoch' => time(), 'author' => $message->getSenderNickname(), 'message' => $message->getMessageText()));
             $this->futures[] = $this->getConduit()->callMethod('chatlog.record', array('logs' => $logs));
             $prompts = array('/where is the (chat)?log\\?/i', '/where am i\\?/i', '/what year is (this|it)\\?/i');
             $tell = false;
             foreach ($prompts as $prompt) {
                 if (preg_match($prompt, $message->getMessageText())) {
                     $tell = true;
                     break;
                 }
             }
             if ($tell) {
                 $response = $this->getURI('/chatlog/channel/' . phutil_escape_uri($reply_to) . '/');
                 $this->write('PRIVMSG', "{$reply_to} :{$response}");
             }
             break;
     }
 }
コード例 #2
0
 public function receiveMessage(PhabricatorIRCMessage $message)
 {
     if (!$this->init()) {
         return;
     }
     switch ($message->getCommand()) {
         case 'PRIVMSG':
             $reply_to = $message->getReplyTo();
             if (!$reply_to) {
                 break;
             }
             $message = $message->getMessageText();
             $matches = null;
             if (!preg_match($this->regexp, $message, $matches)) {
                 return;
             }
             $macro = $matches[1];
             $ascii = idx($this->macros[$macro], 'ascii');
             if ($ascii === false) {
                 return;
             }
             if (!$ascii) {
                 $this->macros[$macro]['ascii'] = $this->rasterize($this->macros[$macro], $this->getConfig('macro.size', 48), $this->getConfig('macro.aspect', 0.66));
                 $ascii = $this->macros[$macro]['ascii'];
             }
             foreach ($ascii as $line) {
                 $this->buffer[$reply_to][] = $line;
             }
             break;
     }
 }
コード例 #3
0
 public function receiveMessage(PhabricatorIRCMessage $message)
 {
     switch ($message->getCommand()) {
         case 'PRIVMSG':
             $reply_to = $message->getReplyTo();
             if (!$reply_to) {
                 break;
             }
             $message = $message->getMessageText();
             $prompt = '~what( i|\')?s new\\?~i';
             if (preg_match($prompt, $message)) {
                 if (time() < $this->floodblock) {
                     return;
                 }
                 $this->floodblock = time() + 60;
                 $this->getLatest($reply_to);
             }
             break;
     }
 }
コード例 #4
0
 private function handleSymbols(PhabricatorIRCMessage $message)
 {
     $reply_to = $message->getReplyTo();
     $text = $message->getMessageText();
     $matches = null;
     if (!preg_match('/where(?: in the world)? is (\\S+?)\\?/i', $text, $matches)) {
         return;
     }
     $symbol = $matches[1];
     $results = $this->getConduit()->callMethodSynchronous('diffusion.findsymbols', array('name' => $symbol));
     $default_uri = $this->getURI('/diffusion/symbol/' . $symbol . '/');
     if (count($results) > 1) {
         $response = "Multiple symbols named '{$symbol}': {$default_uri}";
     } else {
         if (count($results) == 1) {
             $result = head($results);
             $response = $result['type'] . ' ' . $result['name'] . ' ' . '(' . $result['language'] . '): ' . nonempty($result['uri'], $default_uri);
         } else {
             $response = "No symbol '{$symbol}' found anywhere.";
         }
     }
     $this->write('PRIVMSG', "{$reply_to} :{$response}");
 }