mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +01:00
Don't mention the same object in IRC more than once every 10 minutes
Summary: phabot gets spammy when discussing a specific revision. Test Plan: Added debugging code and produced a reasonable-looking chatlog: [1:15pm] phabotlocal joined the chat room. [1:15pm] epriestley: D5 [1:15pm] phabotlocal: D5 quack - http://local.aphront.com/D5 [1:15pm] epriestley: D5 [1:15pm] phabotlocal: Declining to mention PHID-DREV-d7940d0fe081e3ae5267 again (59s left). [1:15pm] epriestley: D5 [1:15pm] phabotlocal: Declining to mention PHID-DREV-d7940d0fe081e3ae5267 again (57s left). [1:15pm] CodeBlock: nice :D [1:15pm] epriestley: I should just leave that code in for maximum irony. [1:15pm] epriestley: D5 [1:15pm] phabotlocal: Declining to mention PHID-DREV-d7940d0fe081e3ae5267 again (9s left). [1:16pm] epriestley: D5 [1:16pm] phabotlocal: Declining to mention PHID-DREV-d7940d0fe081e3ae5267 again (2s left). [1:16pm] epriestley: D5 [1:16pm] phabotlocal: D5 quack - http://local.aphront.com/D5 [1:16pm] epriestley: D5 [1:16pm] phabotlocal: Declining to mention PHID-DREV-d7940d0fe081e3ae5267 again (57s left). [1:16pm] epriestley: rJUI100 [1:16pm] phabotlocal: http://local.aphront.com/rJUI100 [1:16pm] epriestley: rJUI100 [1:16pm] phabotlocal: Declining to mention PHID-CMIT-8fb731b171a27b8d477c again (55s left). [1:16pm] phabotlocal left the chat room. (Remote host closed the connection) Reviewed By: aran Reviewers: aran, codeblock, hsb, mroch CC: aran Differential Revision: 420
This commit is contained in:
parent
79b5343d6b
commit
0ad2b526bc
2 changed files with 21 additions and 3 deletions
|
@ -23,6 +23,12 @@
|
|||
*/
|
||||
class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler {
|
||||
|
||||
/**
|
||||
* Map of PHIDs to the last mention of them (as an epoch timestamp); prevents
|
||||
* us from spamming chat when a single object is discussed.
|
||||
*/
|
||||
private $recentlyMentioned = array();
|
||||
|
||||
public function receiveMessage(PhabricatorIRCMessage $message) {
|
||||
|
||||
switch ($message->getCommand()) {
|
||||
|
@ -82,7 +88,7 @@ class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler {
|
|||
'guids' => $revision_ids,
|
||||
));
|
||||
foreach ($revisions as $revision) {
|
||||
$output[] =
|
||||
$output[$revision['phid']] =
|
||||
'D'.$revision['id'].' '.$revision['name'].' - '.
|
||||
$revision['uri'];
|
||||
}
|
||||
|
@ -100,11 +106,21 @@ class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler {
|
|||
if (isset($commit['error'])) {
|
||||
continue;
|
||||
}
|
||||
$output[] = $commit['uri'];
|
||||
$output[$commit['commitPHID']] = $commit['uri'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($output as $description) {
|
||||
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();
|
||||
|
||||
$this->write('PRIVMSG', "{$channel} :{$description}");
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -8,5 +8,7 @@
|
|||
|
||||
phutil_require_module('phabricator', 'infrastructure/daemon/irc/handler/base');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorIRCObjectNameHandler.php');
|
||||
|
|
Loading…
Reference in a new issue