public function receiveMessage(PhabricatorIRCMessage $message)
 {
     switch ($message->getCommand()) {
         case '422':
             // Error - no MOTD
         // Error - no MOTD
         case '376':
             // End of MOTD
             $nickpass = $this->getConfig('nickpass');
             if ($nickpass) {
                 $this->write('PRIVMSG', "nickserv :IDENTIFY {$nickpass}");
             }
             $join = $this->getConfig('join');
             if (!$join) {
                 throw new Exception("Not configured to join any channels!");
             }
             foreach ($join as $channel) {
                 $this->write('JOIN', $channel);
             }
             break;
         case 'PING':
             $this->write('PONG', $message->getRawData());
             break;
     }
 }
 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;
     }
 }
 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;
     }
 }
 public function receiveMessage(PhabricatorIRCMessage $message)
 {
     switch ($message->getCommand()) {
         case 'PING':
             $this->write('PONG', $message->getRawData());
             break;
     }
 }
 public function receiveMessage(PhabricatorIRCMessage $message)
 {
     switch ($message->getCommand()) {
         case '376':
             // End of MOTD
             $join = $this->getConfig('join');
             if (!$join) {
                 throw new Exception("Not configured to join any channels!");
             }
             foreach ($join as $channel) {
                 $this->write('JOIN', $channel);
             }
             break;
         case 'PING':
             $this->write('PONG', $message->getRawData());
             break;
     }
 }
 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;
     }
 }
 public function receiveMessage(PhabricatorIRCMessage $message)
 {
     switch ($message->getCommand()) {
         case 'PRIVMSG':
             $channel = $message->getChannel();
             if (!$channel) {
                 break;
             }
             $message = $message->getMessageText();
             $matches = null;
             $phids = array();
             $pattern = '@' . '(?<!/)(?:^|\\b)' . '(D|T|P|V)(\\d+)' . '(?:\\b|$)' . '@';
             $revision_ids = array();
             $task_ids = array();
             $paste_ids = array();
             $commit_names = array();
             $vote_ids = array();
             if (preg_match_all($pattern, $message, $matches, PREG_SET_ORDER)) {
                 foreach ($matches as $match) {
                     switch ($match[1]) {
                         case 'D':
                             $revision_ids[] = $match[2];
                             break;
                         case 'T':
                             $task_ids[] = $match[2];
                             break;
                         case 'P':
                             $paste_ids[] = $match[2];
                             break;
                         case 'V':
                             $vote_ids[] = $match[2];
                             break;
                     }
                 }
             }
             $pattern = '@' . '(?<!/)(?:^|\\b)' . '(r[A-Z]+[0-9a-z]{1,40})' . '(?:\\b|$)' . '@';
             if (preg_match_all($pattern, $message, $matches, PREG_SET_ORDER)) {
                 foreach ($matches as $match) {
                     $commit_names[] = $match[1];
                 }
             }
             $output = array();
             if ($revision_ids) {
                 $revisions = $this->getConduit()->callMethodSynchronous('differential.find', array('query' => 'revision-ids', 'guids' => $revision_ids));
                 foreach ($revisions as $revision) {
                     $output[$revision['phid']] = 'D' . $revision['id'] . ' ' . $revision['name'] . ' - ' . $revision['uri'];
                 }
             }
             if ($task_ids) {
                 foreach ($task_ids as $task_id) {
                     $task = $this->getConduit()->callMethodSynchronous('maniphest.info', array('task_id' => $task_id));
                     $output[$task['phid']] = 'T' . $task['id'] . ': ' . $task['title'] . ' (Priority: ' . $task['priority'] . ') - ' . $task['uri'];
                 }
             }
             if ($vote_ids) {
                 foreach ($vote_ids as $vote_id) {
                     $vote = $this->getConduit()->callMethodSynchronous('slowvote.info', array('poll_id' => $vote_id));
                     $output[$vote['phid']] = 'V' . $vote['id'] . ': ' . $vote['question'] . ' Come Vote ' . $vote['uri'];
                 }
             }
             if ($paste_ids) {
                 foreach ($paste_ids as $paste_id) {
                     $paste = $this->getConduit()->callMethodSynchronous('paste.info', array('paste_id' => $paste_id));
                     // Eventually I'd like to show the username of the paster as well,
                     // however that will need something like a user.username_from_phid
                     // since we (ideally) want to keep the bot to Conduit calls...and
                     // not call to Phabricator-specific stuff (like actually loading
                     // the User object and fetching his/her username.)
                     $output[$paste['phid']] = 'P' . $paste['id'] . ': ' . $paste['uri'] . ' - ' . $paste['title'];
                     if ($paste['language']) {
                         $output[$paste['phid']] .= ' (' . $paste['language'] . ')';
                     }
                 }
             }
             if ($commit_names) {
                 $commits = $this->getConduit()->callMethodSynchronous('diffusion.getcommits', array('commits' => $commit_names));
                 foreach ($commits as $commit) {
                     if (isset($commit['error'])) {
                         continue;
                     }
                     $output[$commit['commitPHID']] = $commit['uri'];
                 }
             }
             foreach ($output as $phid => $description) {
                 // Don't mention the same object more than once every 10 minutes, so
                 // we avoid spamming the chat over and over again for discsussions of
                 // a specific revision, for example.
                 $quiet_until = idx($this->recentlyMentioned, $phid, 0) + 60 * 10;
                 if (time() < $quiet_until) {
                     continue;
                 }
                 $this->recentlyMentioned[$phid] = time();
                 $this->write('PRIVMSG', "{$channel} :{$description}");
             }
             break;
     }
 }
 public function receiveMessage(PhabricatorIRCMessage $message)
 {
     switch ($message->getCommand()) {
         case 'PRIVMSG':
             $reply_to = $message->getReplyTo();
             if (!$reply_to) {
                 break;
             }
             $this->handleSymbols($message);
             $message = $message->getMessageText();
             $matches = null;
             $pattern = '@' . '(?<!/)(?:^|\\b)' . '(D|T|P|V|F)(\\d+)' . '(?:\\b|$)' . '@';
             $pattern_override = '/(^[^\\s]+)[,:] [DTPVF]\\d+/';
             $revision_ids = array();
             $task_ids = array();
             $paste_ids = array();
             $commit_names = array();
             $vote_ids = array();
             $file_ids = array();
             $matches_override = array();
             if (preg_match_all($pattern, $message, $matches, PREG_SET_ORDER)) {
                 if (preg_match($pattern_override, $message, $matches_override)) {
                     $reply_to = $matches_override[1];
                 }
                 foreach ($matches as $match) {
                     switch ($match[1]) {
                         case 'D':
                             $revision_ids[] = $match[2];
                             break;
                         case 'T':
                             $task_ids[] = $match[2];
                             break;
                         case 'P':
                             $paste_ids[] = $match[2];
                             break;
                         case 'V':
                             $vote_ids[] = $match[2];
                             break;
                         case 'F':
                             $file_ids[] = $match[2];
                             break;
                     }
                 }
             }
             $pattern = '@' . '(?<!/)(?:^|\\b)' . '(r[A-Z]+[0-9a-z]{1,40})' . '(?:\\b|$)' . '@';
             if (preg_match_all($pattern, $message, $matches, PREG_SET_ORDER)) {
                 foreach ($matches as $match) {
                     $commit_names[] = $match[1];
                 }
             }
             $output = array();
             if ($revision_ids) {
                 $revisions = $this->getConduit()->callMethodSynchronous('differential.query', array('query' => 'revision-ids', 'ids' => $revision_ids));
                 $revisions = array_select_keys(ipull($revisions, null, 'id'), $revision_ids);
                 foreach ($revisions as $revision) {
                     $output[$revision['phid']] = 'D' . $revision['id'] . ' ' . $revision['title'] . ' - ' . $revision['uri'];
                 }
             }
             if ($task_ids) {
                 foreach ($task_ids as $task_id) {
                     if ($task_id == 1000) {
                         $output[1000] = 'T1000: A nanomorph mimetic poly-alloy' . '(liquid metal) assassin controlled by Skynet: ' . 'http://en.wikipedia.org/wiki/T-1000';
                         continue;
                     }
                     $task = $this->getConduit()->callMethodSynchronous('maniphest.info', array('task_id' => $task_id));
                     $output[$task['phid']] = 'T' . $task['id'] . ': ' . $task['title'] . ' (Priority: ' . $task['priority'] . ') - ' . $task['uri'];
                 }
             }
             if ($vote_ids) {
                 foreach ($vote_ids as $vote_id) {
                     $vote = $this->getConduit()->callMethodSynchronous('slowvote.info', array('poll_id' => $vote_id));
                     $output[$vote['phid']] = 'V' . $vote['id'] . ': ' . $vote['question'] . ' Come Vote ' . $vote['uri'];
                 }
             }
             if ($file_ids) {
                 foreach ($file_ids as $file_id) {
                     $file = $this->getConduit()->callMethodSynchronous('file.info', array('id' => $file_id));
                     $output[$file['phid']] = $file['objectName'] . ": " . $file['uri'] . " - " . $file['name'];
                 }
             }
             if ($paste_ids) {
                 foreach ($paste_ids as $paste_id) {
                     $paste = $this->getConduit()->callMethodSynchronous('paste.info', array('paste_id' => $paste_id));
                     // Eventually I'd like to show the username of the paster as well,
                     // however that will need something like a user.username_from_phid
                     // since we (ideally) want to keep the bot to Conduit calls...and
                     // not call to Phabricator-specific stuff (like actually loading
                     // the User object and fetching his/her username.)
                     $output[$paste['phid']] = 'P' . $paste['id'] . ': ' . $paste['uri'] . ' - ' . $paste['title'];
                     if ($paste['language']) {
                         $output[$paste['phid']] .= ' (' . $paste['language'] . ')';
                     }
                 }
             }
             if ($commit_names) {
                 $commits = $this->getConduit()->callMethodSynchronous('diffusion.getcommits', array('commits' => $commit_names));
                 foreach ($commits as $commit) {
                     if (isset($commit['error'])) {
                         continue;
                     }
                     $output[$commit['commitPHID']] = $commit['uri'];
                 }
             }
             foreach ($output as $phid => $description) {
                 // Don't mention the same object more than once every 10 minutes
                 // in public channels, so we avoid spamming the chat over and over
                 // again for discsussions of a specific revision, for example. In
                 // direct-to-bot chat, respond to every object reference.
                 if ($this->isChannelName($reply_to)) {
                     if (empty($this->recentlyMentioned[$reply_to])) {
                         $this->recentlyMentioned[$reply_to] = array();
                     }
                     $quiet_until = idx($this->recentlyMentioned[$reply_to], $phid, 0) + 60 * 10;
                     if (time() < $quiet_until) {
                         // Remain quiet on this channel.
                         continue;
                     }
                     $this->recentlyMentioned[$reply_to][$phid] = time();
                 }
                 $this->write('PRIVMSG', "{$reply_to} :{$description}");
             }
             break;
     }
 }