1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02: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:
epriestley 2011-12-21 09:56:20 -08:00
parent b258095124
commit 13155f8828
2 changed files with 39 additions and 1 deletions

View file

@ -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);
}

View file

@ -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}");
}
}