From f12af0383665a2fec0eb2bfc4c2cce49f9d56dba Mon Sep 17 00:00:00 2001 From: Ricky Elrod Date: Thu, 3 Jan 2013 12:44:29 -0800 Subject: [PATCH] Make phabot never private message anyone. Summary: This replaces D4175 and makes it so phabot doesn't message anyone. The reasons for this are twofold: - It was possible to get information from the bot, by private messaging it, even if the bot was only in a +i channel (on a public network) -- meaning that if someone knew the nickname of the bot, they could obtain e.g. ticket names or diff titles. - The other time it messaged people was when you typed e.g. "somenick: T123". Most times when this is triggered, it's done so on accident. See discussion on the old revision (D4175). Test Plan: 15:29:33 ::: Irssi: Starting query in quartz with cb-phabot 15:29:38 T2 (nothing back) and 15:29:21 <@relrod> rublets: T1 15:29:21 < cb-phabot> T1: asdfasdf (Priority: Needs Triage) - http://local.elrod.me/T1 Reviewers: epriestley, btrahan, vrana Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4339 --- .../daemon/irc/PhabricatorIRCMessage.php | 5 --- .../PhabricatorIRCObjectNameHandler.php | 37 +++++++------------ 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/infrastructure/daemon/irc/PhabricatorIRCMessage.php b/src/infrastructure/daemon/irc/PhabricatorIRCMessage.php index 59feb900d0..8d3bb14153 100644 --- a/src/infrastructure/daemon/irc/PhabricatorIRCMessage.php +++ b/src/infrastructure/daemon/irc/PhabricatorIRCMessage.php @@ -31,11 +31,6 @@ final class PhabricatorIRCMessage { if ($target[0] == '#') { return $target; } - - $matches = null; - if (preg_match('/^:([^!]+)!/', $this->sender, $matches)) { - return $matches[1]; - } break; } return null; diff --git a/src/infrastructure/daemon/irc/handler/PhabricatorIRCObjectNameHandler.php b/src/infrastructure/daemon/irc/handler/PhabricatorIRCObjectNameHandler.php index 420621a170..4ed949db68 100644 --- a/src/infrastructure/daemon/irc/handler/PhabricatorIRCObjectNameHandler.php +++ b/src/infrastructure/daemon/irc/handler/PhabricatorIRCObjectNameHandler.php @@ -33,7 +33,6 @@ final class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler { '(D|T|P|V|F)(\d+)'. '(?:\b|$)'. '@'; - $pattern_override = '/(^[^\s]+)[,:] [DTPVF]\d+/'; $revision_ids = array(); $task_ids = array(); @@ -41,12 +40,8 @@ final class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler { $commit_names = array(); $vote_ids = array(); $file_ids = array(); - $matches_override = array(); if (preg_match_all($pattern, $message, $matches, PREG_SET_ORDER)) { - if (preg_match($pattern_override, $message, $matches_override)) { - $reply_to = $matches_override[1]; - } foreach ($matches as $match) { switch ($match[1]) { case 'D': @@ -180,27 +175,23 @@ final class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler { // 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. + // again for discsussions of a specific revision, for example. - 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(); + 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;