mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
Delay sending JOIN command until after MOTD finishes for IRC bot
Summary: Do JOIN in the protocol handler, after we receive 376 ("end of motd"). Test Plan: Ran bot, it joined a channel after receieving a 376 command. Reviewers: moos3, codeblock, aran, jungejason, tuomaspelkonen Reviewed By: moos3 CC: aran, moos3 Differential Revision: 855
This commit is contained in:
parent
30024a8d86
commit
fd0f4d9c52
3 changed files with 21 additions and 10 deletions
|
@ -35,6 +35,7 @@ final class PhabricatorIRCBot extends PhabricatorDaemon {
|
|||
private $readBuffer;
|
||||
|
||||
private $conduit;
|
||||
private $config;
|
||||
|
||||
public function run() {
|
||||
|
||||
|
@ -51,7 +52,6 @@ final class PhabricatorIRCBot extends PhabricatorDaemon {
|
|||
|
||||
$server = idx($config, 'server');
|
||||
$port = idx($config, 'port', 6667);
|
||||
$join = idx($config, 'join', array());
|
||||
$handlers = idx($config, 'handlers', array());
|
||||
$pass = idx($config, 'pass');
|
||||
$nick = idx($config, 'nick', 'phabot');
|
||||
|
@ -59,15 +59,13 @@ final class PhabricatorIRCBot extends PhabricatorDaemon {
|
|||
$ssl = idx($config, 'ssl', false);
|
||||
$nickpass = idx($config, 'nickpass');
|
||||
|
||||
$this->config = $config;
|
||||
|
||||
if (!preg_match('/^[A-Za-z0-9_`[{}^|\]\\-]+$/', $nick)) {
|
||||
throw new Exception(
|
||||
"Nickname '{$nick}' is invalid!");
|
||||
}
|
||||
|
||||
if (!$join) {
|
||||
throw new Exception("No channels to 'join' in config!");
|
||||
}
|
||||
|
||||
foreach ($handlers as $handler) {
|
||||
$obj = newv($handler, array($this));
|
||||
$this->handlers[] = $obj;
|
||||
|
@ -114,17 +112,17 @@ final class PhabricatorIRCBot extends PhabricatorDaemon {
|
|||
}
|
||||
|
||||
if ($nickpass) {
|
||||
$this->writeCommand("NickServ IDENTIFY ", "{$nickpass}");
|
||||
$this->writeCommand("NickServ IDENTIFY ", "{$nickpass}");
|
||||
}
|
||||
|
||||
$this->writeCommand('NICK', "{$nick}");
|
||||
foreach ($join as $channel) {
|
||||
$this->writeCommand('JOIN', "{$channel}");
|
||||
}
|
||||
|
||||
$this->runSelectLoop();
|
||||
}
|
||||
|
||||
public function getConfig($key, $default = null) {
|
||||
return idx($this->config, $key, $default);
|
||||
}
|
||||
|
||||
private function runSelectLoop() {
|
||||
do {
|
||||
$this->stillWorking();
|
||||
|
|
|
@ -39,6 +39,10 @@ abstract class PhabricatorIRCHandler {
|
|||
return $this->bot->getConduit();
|
||||
}
|
||||
|
||||
final protected function getConfig($key, $default = null) {
|
||||
return $this->bot->getConfig($key, $default);
|
||||
}
|
||||
|
||||
abstract public function receiveMessage(PhabricatorIRCMessage $message);
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,15 @@ class PhabricatorIRCProtocolHandler extends PhabricatorIRCHandler {
|
|||
|
||||
public function receiveMessage(PhabricatorIRCMessage $message) {
|
||||
switch ($message->getCommand()) {
|
||||
case '376': // End of MOTD
|
||||
$join = $this->getConfig('join');
|
||||
if (!$join) {
|
||||
throw new Exception("Not configured to join any channels!");
|
||||
}
|
||||
foreach ($join as $channel) {
|
||||
$this->write('JOIN', $channel);
|
||||
}
|
||||
break;
|
||||
case 'PING':
|
||||
$this->write('PONG', $message->getRawData());
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue