Page MenuHomePhabricator
Paste P1067

PhabricatorBotObjectNameHandler.php
ActivePublic

Authored by dctrwatson on Feb 15 2014, 12:41 AM.
<?php
/**
* Watches for "tell me about <slug>"
* and "phabot remember <slug> as: <text>"
*
* @group irc
*/
final class PhabricatorBotDocHandler extends PhabricatorBotHandler {
public function receiveMessage(PhabricatorBotMessage $message) {
switch ($message->getCommand()) {
case 'MESSAGE':
$matches = null;
$text = $message->getBody();
$pattern = '@^tell me about (.*)$@';
if (preg_match($pattern, $text, $matches)) {
try {
$result = $this->getConduit()->callMethodSynchronous(
'phriction.info',
array(
'slug' => 'docbot/'.$matches[1],
));
} catch (ConduitClientException $ex) {
phlog($ex);
$result = null;
}
$response = array();
if ($result) {
$content = phutil_split_lines(
$result['content'],
$retain_newlines = false
);
foreach ($content as $line) {
$response = array_merge($response, str_split($line, 400));
if (count($response) >= 3) {
break;
}
}
} else {
$response[] = "Nothing to say about ".$slug;
}
foreach (array_slice($response, 0, 3) as $output) {
$this->replyTo($message, html_entity_decode($output));
}
break;
}
$pattern =
'@'.
$this->getConfig('nick', 'phabot').
' remember '.
'(.*?)'.
' as:'.
'(.*)$'.
'@';
if (preg_match($pattern, $text, $matches)) {
$result = $this->getConduit()->callMethodSynchronous(
'phriction.edit',
array(
'slug' => 'docbot/'.$matches[1],
'content' => $matches[2],
));
$slug = explode('/', trim($result['slug'], '/'));
$output = "Saved as '${slug[1]}' at ${result['uri']}";
$this->replyTo($message, $output);
break;
}
break;
}
}
private function lookupDoc($slug) {
}
}

Event Timeline

dctrwatson changed the title of this paste from untitled to PhabricatorBotObjectNameHandler.php.
dctrwatson updated the paste's language from autodetect to autodetect.