diff --git a/src/infrastructure/daemon/irc/handler/base/PhabricatorIRCHandler.php b/src/infrastructure/daemon/irc/handler/base/PhabricatorIRCHandler.php index 069c33c434..157978fc84 100644 --- a/src/infrastructure/daemon/irc/handler/base/PhabricatorIRCHandler.php +++ b/src/infrastructure/daemon/irc/handler/base/PhabricatorIRCHandler.php @@ -47,6 +47,10 @@ abstract class PhabricatorIRCHandler { return $this->bot->getConfig('conduit.uri').$path; } + final protected function isChannelName($name) { + return (strpos($name, '#') === 0); + } + abstract public function receiveMessage(PhabricatorIRCMessage $message); public function runBackgroundTasks() { diff --git a/src/infrastructure/daemon/irc/handler/objectname/PhabricatorIRCObjectNameHandler.php b/src/infrastructure/daemon/irc/handler/objectname/PhabricatorIRCObjectNameHandler.php index de771d4e2b..52e27208c7 100644 --- a/src/infrastructure/daemon/irc/handler/objectname/PhabricatorIRCObjectNameHandler.php +++ b/src/infrastructure/daemon/irc/handler/objectname/PhabricatorIRCObjectNameHandler.php @@ -1,7 +1,7 @@ getCommand()) { case 'PRIVMSG': - $channel = $message->getChannel(); - if (!$channel) { + $reply_to = $message->getReplyTo(); + if (!$reply_to) { break; } @@ -164,23 +164,37 @@ class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler { foreach ($output as $phid => $description) { - // Don't mention the same object more than once every 10 minutes, so - // we avoid spamming the chat over and over again for discsussions of - // a specific revision, for example. - $quiet_until = idx($this->recentlyMentioned, $phid, 0) + (60 * 10); - if (time() < $quiet_until) { - continue; - } - $this->recentlyMentioned[$phid] = time(); + // Don't mention the same object more than once every 10 minutes + // in public channels, so we avoid spamming the chat over and over + // again for discsussions of a specific revision, for example. In + // direct-to-bot chat, respond to every object reference. - $this->write('PRIVMSG', "{$channel} :{$description}"); + if ($this->isChannelName($reply_to)) { + if (empty($this->recentlyMentioned[$reply_to])) { + $this->recentlyMentioned[$reply_to] = array(); + } + + $quiet_until = idx( + $this->recentlyMentioned[$reply_to], + $phid, + 0) + (60 * 10); + + if (time() < $quiet_until) { + // Remain quiet on this channel. + continue; + } + + $this->recentlyMentioned[$reply_to][$phid] = time(); + } + + $this->write('PRIVMSG', "{$reply_to} :{$description}"); } break; } } private function handleSymbols(PhabricatorIRCMessage $message) { - $channel = $message->getChannel(); + $reply_to = $message->getReplyTo(); $text = $message->getMessageText(); $matches = null; @@ -209,7 +223,7 @@ class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler { $response = "No symbol '{$symbol}' found anywhere."; } - $this->write('PRIVMSG', "{$channel} :{$response}"); + $this->write('PRIVMSG', "{$reply_to} :{$response}"); } } diff --git a/src/infrastructure/daemon/irc/message/PhabricatorIRCMessage.php b/src/infrastructure/daemon/irc/message/PhabricatorIRCMessage.php index aaab3b2daa..a9cfe22f0f 100644 --- a/src/infrastructure/daemon/irc/message/PhabricatorIRCMessage.php +++ b/src/infrastructure/daemon/irc/message/PhabricatorIRCMessage.php @@ -1,7 +1,7 @@ command; } - public function getChannel() { + public function getReplyTo() { + switch ($this->getCommand()) { + case 'PRIVMSG': + $target = $this->getTarget(); + if ($target[0] == '#') { + return $target; + } + + $matches = null; + if (preg_match('/^:([^!]+)!/', $this->sender, $matches)) { + return $matches[1]; + } + break; + } + return null; + } + + public function getTarget() { switch ($this->getCommand()) { case 'PRIVMSG': $matches = null;