@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use a custom quit message when gracefully shutting down the IRC bot

Summary: Fixes T3173. This doesn't actually fix T3173 but I'm going to redirect that. It does make the bot quit IRC gracefully, with a nicer quit message, which can be customized.

Test Plan: Got a bot to quit IRC with nice messages.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T3173

Differential Revision: https://secure.phabricator.com/D10257

+36 -5
+3
src/infrastructure/daemon/bot/PhabricatorBot.php
··· 83 83 ->connect(); 84 84 85 85 $this->runLoop(); 86 + 87 + $this->protocolAdapter->disconnect(); 86 88 } 87 89 88 90 public function getConfig($key, $default = null) { ··· 104 106 $handler->runBackgroundTasks(); 105 107 } 106 108 } while (!$this->shouldExit()); 109 + 107 110 } 108 111 109 112 public function writeMessage(PhabricatorBotMessage $message) {
+7
src/infrastructure/daemon/bot/adapter/PhabricatorBaseProtocolAdapter.php
··· 22 22 abstract public function connect(); 23 23 24 24 /** 25 + * Disconnect from the service. 26 + */ 27 + public function disconnect() { 28 + return; 29 + } 30 + 31 + /** 25 32 * This is the spout for messages coming in from the protocol. 26 33 * This will be called in the main event loop of the bot daemon 27 34 * So if if doesn't implement some sort of blocking timeout
+26 -5
src/infrastructure/daemon/bot/adapter/PhabricatorIRCProtocolAdapter.php
··· 71 71 72 72 $ok = @stream_select($read, $write, $except, $timeout_sec = 1); 73 73 if ($ok === false) { 74 - throw new Exception( 75 - 'socket_select() failed: '.socket_strerror(socket_last_error())); 74 + // We may have been interrupted by a signal, like a SIGINT. Try 75 + // selecting again. If the second select works, conclude that the failure 76 + // was most likely because we were signaled. 77 + $ok = @stream_select($read, $write, $except, $timeout_sec = 0); 78 + if ($ok === false) { 79 + throw new Exception('stream_select() failed!'); 80 + } 76 81 } 77 82 78 83 if ($read) { ··· 102 107 $len = fwrite($this->socket, $this->writeBuffer); 103 108 if ($len === false) { 104 109 throw new Exception('fwrite() failed!'); 110 + } else if ($len === 0) { 111 + break; 105 112 } else { 106 113 $messages[] = id(new PhabricatorBotMessage()) 107 114 ->setCommand('LOG') ··· 250 257 $data); 251 258 } 252 259 253 - public function __destruct() { 254 - $this->write('QUIT Goodbye.'); 255 - fclose($this->socket); 260 + public function disconnect() { 261 + // NOTE: FreeNode doesn't show quit messages if you've recently joined a 262 + // channel, presumably to prevent some kind of abuse. If you're testing 263 + // this, you may need to stay connected to the network for a few minutes 264 + // before it works. If you disconnect too quickly, the server will replace 265 + // your message with a "Client Quit" message. 266 + 267 + $quit = $this->getConfig('quit', pht('Shutting down.')); 268 + $this->write("QUIT :{$quit}"); 269 + 270 + // Flush the write buffer. 271 + while (strlen($this->writeBuffer)) { 272 + $this->getNextMessages(0); 273 + } 274 + 275 + @fclose($this->socket); 276 + $this->socket = null; 256 277 } 257 278 }