mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +01:00
Add symbol integration to the IRC bot
Summary: Allow the bot to answer the question "where is X?", where X is a symbol. Test Plan: phabotlocal joined the chat room. epriestley: phabotlocal: where is DarkConsole? phabotlocal left the chat room. (Remote host closed the connection) phabotlocal joined the chat room. epriestley: phabotlocal: where is DarkConsole? phabotlocal left the chat room. (Remote host closed the connection) phabotlocal joined the chat room. epriestley: phabotlocal: where is DarkConsole? phabotlocal: class DarkConsole (php): http://local.aphront.com/diffusion/SUBC/browse/src/aphront/console/api/DarkConsole.php$22 epriestley: thanks phabotlocal that is vastly more useful phabotlocal left the chat room. (Remote host closed the connection) Reviewers: btrahan, jungejason Reviewed By: jungejason CC: aran, jungejason Maniphest Tasks: T315 Differential Revision: https://secure.phabricator.com/D1261
This commit is contained in:
parent
b258095124
commit
13155f8828
2 changed files with 39 additions and 1 deletions
|
@ -43,6 +43,10 @@ abstract class PhabricatorIRCHandler {
|
|||
return $this->bot->getConfig($key, $default);
|
||||
}
|
||||
|
||||
final protected function getURI($path) {
|
||||
return $this->bot->getConfig('conduit.uri').$path;
|
||||
}
|
||||
|
||||
abstract public function receiveMessage(PhabricatorIRCMessage $message);
|
||||
|
||||
}
|
||||
|
|
|
@ -38,9 +38,10 @@ class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler {
|
|||
break;
|
||||
}
|
||||
|
||||
$this->handleSymbols($message);
|
||||
|
||||
$message = $message->getMessageText();
|
||||
$matches = null;
|
||||
$phids = array();
|
||||
|
||||
$pattern =
|
||||
'@'.
|
||||
|
@ -178,4 +179,37 @@ class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private function handleSymbols(PhabricatorIRCMessage $message) {
|
||||
$channel = $message->getChannel();
|
||||
$text = $message->getMessageText();
|
||||
|
||||
$matches = null;
|
||||
if (!preg_match('/where is (\S+?)\?/i', $text, $matches)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$symbol = $matches[1];
|
||||
$results = $this->getConduit()->callMethodSynchronous(
|
||||
'diffusion.findsymbols',
|
||||
array(
|
||||
'name' => $symbol,
|
||||
));
|
||||
|
||||
if (count($results) > 1) {
|
||||
$uri = $this->getURI('/diffusion/symbol/'.$symbol.'/');
|
||||
$response = "Multiple symbols named '{$symbol}': {$uri}";
|
||||
} else if (count($results) == 1) {
|
||||
$result = head($results);
|
||||
$response =
|
||||
$result['type'].' '.
|
||||
$result['name'].' '.
|
||||
'('.$result['language'].'): '.
|
||||
$result['uri'];
|
||||
} else {
|
||||
$response = "No symbol '{$symbol}' found anywhere.";
|
||||
}
|
||||
|
||||
$this->write('PRIVMSG', "{$channel} :{$response}");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue