1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 15:22:41 +01:00

Lock down bot adapter API slightly

Summary:
  - Reduce visibiliy of config.
  - Add a typehint.

Test Plan: Ran campfire/irc bots and chatted with them.

Reviewers: indiefan

Reviewed By: indiefan

CC: aran, amerigomasini

Differential Revision: https://secure.phabricator.com/D4923
This commit is contained in:
epriestley 2013-02-14 05:07:50 -08:00
parent 7b133b8bf2
commit ec306497f5
4 changed files with 19 additions and 14 deletions

View file

@ -4,13 +4,18 @@
* Defines the api for protocol adapters for @{class:PhabricatorBot}
*/
abstract class PhabricatorBaseProtocolAdapter {
protected $config;
private $config;
public function setConfig($config) {
$this->config = $config;
return $this;
}
public function getConfig($key, $default = null) {
return idx($this->config, $key, $default);
}
/**
* Performs any connection logic necessary for the protocol
*/

View file

@ -1,7 +1,7 @@
<?php
final class PhabricatorCampfireProtocolAdapter
extends PhabricatorBaseProtocolAdapter {
extends PhabricatorBaseProtocolAdapter {
private $readBuffers;
private $authtoken;
@ -12,10 +12,10 @@ extends PhabricatorBaseProtocolAdapter {
private $inRooms = array();
public function connect() {
$this->server = idx($this->config, 'server');
$this->authtoken = idx($this->config, 'authtoken');
$ssl = idx($this->config, 'ssl', false);
$rooms = idx($this->config, 'join');
$this->server = $this->getConfig('server');
$this->authtoken = $this->getConfig('authtoken');
$ssl = $this->getConfig('ssl', false);
$rooms = $this->getConfig('join');
// First, join the room
if (!$rooms) {

View file

@ -1,7 +1,7 @@
<?php
final class PhabricatorIRCProtocolAdapter
extends PhabricatorBaseProtocolAdapter {
extends PhabricatorBaseProtocolAdapter {
private $socket;
@ -13,12 +13,12 @@ extends PhabricatorBaseProtocolAdapter {
'PRIVMSG' => 'MESSAGE');
public function connect() {
$nick = idx($this->config, 'nick', 'phabot');
$server = idx($this->config, 'server');
$port = idx($this->config, 'port', 6667);
$pass = idx($this->config, 'pass');
$ssl = idx($this->config, 'ssl', false);
$user = idx($this->config, 'user', $nick);
$nick = $this->getConfig('nick', 'phabot');
$server = $this->getConfig('server');
$port = $this->getConfig('port', 6667);
$pass = $this->getConfig('pass');
$ssl = $this->getConfig('ssl', false);
$user = $this->getConfig('user', $nick);
if (!preg_match('/^[A-Za-z0-9_`[{}^|\]\\-]+$/', $nick)) {
throw new Exception(

View file

@ -39,7 +39,7 @@ abstract class PhabricatorBotHandler {
return;
}
public function replyTo($original_message, $body) {
public function replyTo(PhabricatorBotMessage $original_message, $body) {
if ($original_message->getCommand() != 'MESSAGE') {
throw new Exception(
"Handler is trying to reply to something which is not a message!");