Page MenuHomec4science

PhabricatorBotHandler.php
No OneTemporary

File Metadata

Created
Sun, Dec 22, 23:47

PhabricatorBotHandler.php

<?php
/**
* Responds to IRC messages. You plug a bunch of these into a
* @{class:PhabricatorBot} to give it special behavior.
*
* @group irc
*/
abstract class PhabricatorBotHandler {
private $bot;
final public function __construct(PhabricatorBot $irc_bot) {
$this->bot = $irc_bot;
}
final protected function writeMessage(PhabricatorBotMessage $message) {
$this->bot->writeMessage($message);
return $this;
}
final protected function getConduit() {
return $this->bot->getConduit();
}
final protected function getConfig($key, $default = null) {
return $this->bot->getConfig($key, $default);
}
final protected function getURI($path) {
$base_uri = new PhutilURI($this->bot->getConfig('conduit.uri'));
$base_uri->setPath($path);
return (string)$base_uri;
}
abstract public function receiveMessage(PhabricatorBotMessage $message);
public function runBackgroundTasks() {
return;
}
public function replyTo($original_message, $body) {
if ($original_message->getCommand() != 'MESSAGE') {
throw new Exception(
"Handler is trying to reply to something which is not a message!");
}
$reply = id(new PhabricatorBotMessage())
->setCommand('MESSAGE');
if ($original_message->isPublic()) {
// This is a public target, like a chatroom. Send the response to the
// chatroom.
$reply->setTarget($original_message->getTarget());
} else {
// This is a private target, like a private message. Send the response
// back to the sender (presumably, we are the target).
$reply->setTarget($original_message->getSender())
->setPublic(false);
}
$reply->setBody($body);
return $this->writeMessage($reply);
}
}

Event Timeline