From 358b59ffa784ae7e02a115fc81239962336d19ea Mon Sep 17 00:00:00 2001 From: Eric Stern Date: Wed, 14 May 2014 11:21:38 -0700 Subject: [PATCH] If PhabricatorIRCBot encounters a 'nick used' error, try adding a number Summary: Someone stole my bot's name, so the bot couldn't (re)connect. This tries adding some text to the name if it encounters a 433 'nick in use' error Test Plan: Started a ton of bots: F154744 Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D9123 --- .../daemon/bot/adapter/PhabricatorIRCProtocolAdapter.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/infrastructure/daemon/bot/adapter/PhabricatorIRCProtocolAdapter.php b/src/infrastructure/daemon/bot/adapter/PhabricatorIRCProtocolAdapter.php index ad79748de1..c9d701d36e 100644 --- a/src/infrastructure/daemon/bot/adapter/PhabricatorIRCProtocolAdapter.php +++ b/src/infrastructure/daemon/bot/adapter/PhabricatorIRCProtocolAdapter.php @@ -8,6 +8,8 @@ final class PhabricatorIRCProtocolAdapter private $writeBuffer; private $readBuffer; + private $nickIncrement = 0; + public function getServiceType() { return 'IRC'; } @@ -183,6 +185,12 @@ final class PhabricatorIRCProtocolAdapter private function handleIRCProtocol(array $matches) { $data = $matches['data']; switch ($matches['command']) { + case '433': // Nickname already in use + // If we receive this error, try appending "-1", "-2", etc. to the nick + $this->nickIncrement++; + $nick = $this->getConfig('nick', 'phabot').'-'.$this->nickIncrement; + $this->write("NICK {$nick}"); + return true; case '422': // Error - no MOTD case '376': // End of MOTD $nickpass = $this->getConfig('nickpass');