diff --git a/resources/ircbot/example_config.json b/resources/ircbot/example_config.json index b2bbf5210d..0e246ce536 100644 --- a/resources/ircbot/example_config.json +++ b/resources/ircbot/example_config.json @@ -8,6 +8,7 @@ "handlers" : [ "PhabricatorIRCProtocolHandler", "PhabricatorIRCObjectNameHandler", + "PhabricatorIRCSymbolHandler", "PhabricatorIRCLogHandler", "PhabricatorIRCWhatsNewHandler", "PhabricatorIRCDifferentialNotificationHandler", diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 752605dd96..f359bf9ad1 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -888,6 +888,7 @@ phutil_register_library_map(array( 'PhabricatorIRCMessage' => 'infrastructure/daemon/irc/PhabricatorIRCMessage.php', 'PhabricatorIRCObjectNameHandler' => 'infrastructure/daemon/irc/handler/PhabricatorIRCObjectNameHandler.php', 'PhabricatorIRCProtocolHandler' => 'infrastructure/daemon/irc/handler/PhabricatorIRCProtocolHandler.php', + 'PhabricatorIRCSymbolHandler' => 'infrastructure/daemon/irc/handler/PhabricatorIRCSymbolHandler.php', 'PhabricatorIRCWhatsNewHandler' => 'infrastructure/daemon/irc/handler/PhabricatorIRCWhatsNewHandler.php', 'PhabricatorImageTransformer' => 'applications/files/PhabricatorImageTransformer.php', 'PhabricatorInfrastructureTestCase' => 'infrastructure/__tests__/PhabricatorInfrastructureTestCase.php', @@ -2254,6 +2255,7 @@ phutil_register_library_map(array( 'PhabricatorIRCMacroHandler' => 'PhabricatorIRCHandler', 'PhabricatorIRCObjectNameHandler' => 'PhabricatorIRCHandler', 'PhabricatorIRCProtocolHandler' => 'PhabricatorIRCHandler', + 'PhabricatorIRCSymbolHandler' => 'PhabricatorIRCHandler', 'PhabricatorIRCWhatsNewHandler' => 'PhabricatorIRCHandler', 'PhabricatorInfrastructureTestCase' => 'PhabricatorTestCase', 'PhabricatorInlineCommentController' => 'PhabricatorController', diff --git a/src/infrastructure/daemon/irc/handler/PhabricatorIRCObjectNameHandler.php b/src/infrastructure/daemon/irc/handler/PhabricatorIRCObjectNameHandler.php index 4ed949db68..ba551d1d33 100644 --- a/src/infrastructure/daemon/irc/handler/PhabricatorIRCObjectNameHandler.php +++ b/src/infrastructure/daemon/irc/handler/PhabricatorIRCObjectNameHandler.php @@ -22,8 +22,6 @@ final class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler { break; } - $this->handleSymbols($message); - $message = $message->getMessageText(); $matches = null; @@ -198,39 +196,4 @@ final class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler { } } - 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}"); - } - } diff --git a/src/infrastructure/daemon/irc/handler/PhabricatorIRCSymbolHandler.php b/src/infrastructure/daemon/irc/handler/PhabricatorIRCSymbolHandler.php new file mode 100644 index 0000000000..8b4343d3ed --- /dev/null +++ b/src/infrastructure/daemon/irc/handler/PhabricatorIRCSymbolHandler.php @@ -0,0 +1,55 @@ +?" + * + * @group irc + */ +final class PhabricatorIRCSymbolHandler extends PhabricatorIRCHandler { + + public function receiveMessage(PhabricatorIRCMessage $message) { + + switch ($message->getCommand()) { + case 'PRIVMSG': + $reply_to = $message->getReplyTo(); + if (!$reply_to) { + break; + } + + $text = $message->getMessageText(); + + $matches = null; + if (!preg_match('/where(?: in the world)? is (\S+?)\?/i', + $text, $matches)) { + break; + } + + $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}"); + + break; + } + } + +}