What's New flood protection

Summary:
Added what's new flood protection and fixed array_push issues.
Also added rhetoric for "Commit"

Test Plan: say "What's new?" twice within one minute

Reviewers: epriestley

CC: aran, epriestley

Differential Revision: https://secure.phabricator.com/D1684
This commit is contained in:
Korvin Szanto
2012-02-23 19:16:18 -08:00
parent 5e39522ac4
commit 31cbb7fbe2

View File

@@ -23,7 +23,10 @@
*/ */
final class PhabricatorIRCWhatsNewHandler extends PhabricatorIRCHandler { final class PhabricatorIRCWhatsNewHandler extends PhabricatorIRCHandler {
private $floodblock = 0;
public function receiveMessage(PhabricatorIRCMessage $message) { public function receiveMessage(PhabricatorIRCMessage $message) {
switch ($message->getCommand()) { switch ($message->getCommand()) {
case 'PRIVMSG': case 'PRIVMSG':
$reply_to = $message->getReplyTo(); $reply_to = $message->getReplyTo();
@@ -35,6 +38,11 @@ final class PhabricatorIRCWhatsNewHandler extends PhabricatorIRCHandler {
$prompt = '~what( i|\')?s new\?~i'; $prompt = '~what( i|\')?s new\?~i';
if (preg_match($prompt, $message)) { if (preg_match($prompt, $message)) {
if (time() < $this->floodblock) {
return;
}
$this->floodblock = time() + 60;
$this->getLatest($reply_to); $this->getLatest($reply_to);
} }
break; break;
@@ -59,15 +67,15 @@ final class PhabricatorIRCWhatsNewHandler extends PhabricatorIRCHandler {
switch ($action['class']) { switch ($action['class']) {
case 'PhabricatorFeedStoryDifferential': case 'PhabricatorFeedStoryDifferential':
array_push($phids,$action['data']['revision_phid']); $phids[] = $action['data']['revision_phid'];
break; break;
case 'PhabricatorFeedStoryManiphest': case 'PhabricatorFeedStoryManiphest':
array_push($phids,$action['data']['taskPHID']); $phids[] = $action['data']['taskPHID'];
break; break;
default: default:
array_push($phids,$uid); $phids[] = $uid;
break; break;
} }
array_push($phids,$uid); array_push($phids,$uid);
@@ -120,19 +128,22 @@ final class PhabricatorIRCWhatsNewHandler extends PhabricatorIRCHandler {
public function getRhetoric($input) { public function getRhetoric($input) {
switch ($input) { switch ($input) {
case "none": case 'none':
return 'commented on'; return 'commented on';
break; break;
case "update": case 'update':
return 'updated'; return 'updated';
break; break;
case "create": case 'commit':
return 'committed';
break;
case 'create':
return 'created'; return 'created';
break; break;
case "abandon": case 'abandon':
return 'abandonned'; return 'abandonned';
break; break;
case "accept": case 'accept':
return 'accepted'; return 'accepted';
break; break;
default: default: