diff --git a/resources/ircbot/example_config.json b/resources/ircbot/example_config.json index 6ce5d3ac3c..476d81d643 100644 --- a/resources/ircbot/example_config.json +++ b/resources/ircbot/example_config.json @@ -9,6 +9,7 @@ "PhabricatorIRCProtocolHandler", "PhabricatorIRCObjectNameHandler", "PhabricatorIRCLogHandler", + "PhabricatorIRCWhatsNewHandler", "PhabricatorIRCDifferentialNotificationHandler" ], diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 427ba31cf8..c5e5506332 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -565,6 +565,7 @@ phutil_register_library_map(array( 'PhabricatorIRCMessage' => 'infrastructure/daemon/irc/message', 'PhabricatorIRCObjectNameHandler' => 'infrastructure/daemon/irc/handler/objectname', 'PhabricatorIRCProtocolHandler' => 'infrastructure/daemon/irc/handler/protocol', + 'PhabricatorIRCWhatsNewHandler' => 'infrastructure/daemon/irc/handler/whatsnew', 'PhabricatorImageTransformer' => 'applications/files/transform', 'PhabricatorInfrastructureTestCase' => 'infrastructure/__tests__', 'PhabricatorJavelinLinter' => 'infrastructure/lint/linter/javelin', @@ -1315,6 +1316,7 @@ phutil_register_library_map(array( 'PhabricatorIRCLogHandler' => 'PhabricatorIRCHandler', 'PhabricatorIRCObjectNameHandler' => 'PhabricatorIRCHandler', 'PhabricatorIRCProtocolHandler' => 'PhabricatorIRCHandler', + 'PhabricatorIRCWhatsNewHandler' => 'PhabricatorIRCHandler', 'PhabricatorInfrastructureTestCase' => 'PhabricatorTestCase', 'PhabricatorJavelinLinter' => 'ArcanistLinter', 'PhabricatorLintEngine' => 'PhutilLintEngine', diff --git a/src/infrastructure/daemon/irc/handler/objectname/PhabricatorIRCObjectNameHandler.php b/src/infrastructure/daemon/irc/handler/objectname/PhabricatorIRCObjectNameHandler.php index 9ff8f142c0..cce35032ab 100644 --- a/src/infrastructure/daemon/irc/handler/objectname/PhabricatorIRCObjectNameHandler.php +++ b/src/infrastructure/daemon/irc/handler/objectname/PhabricatorIRCObjectNameHandler.php @@ -109,11 +109,11 @@ class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler { if ($task_ids) { foreach ($task_ids as $task_id) { - if ($task_id == 1000) { - $output[1000] = 'T1000: A nanomorph mimetic poly-alloy' - .'(liquid metal) assassin controlled by Skynet: ' - .'http://en.wikipedia.org/wiki/T-1000'; - continue; + if ($task_id == 1000) { + $output[1000] = 'T1000: A nanomorph mimetic poly-alloy' + .'(liquid metal) assassin controlled by Skynet: ' + .'http://en.wikipedia.org/wiki/T-1000'; + continue; } $task = $this->getConduit()->callMethodSynchronous( 'maniphest.info', @@ -136,7 +136,7 @@ class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler { ' Come Vote '.$vote['uri']; } } - + if ($file_ids) { foreach ($file_ids as $file_id) { $file = $this->getConduit()->callMethodSynchronous( diff --git a/src/infrastructure/daemon/irc/handler/whatsnew/PhabricatorIRCWhatsNewHandler.php b/src/infrastructure/daemon/irc/handler/whatsnew/PhabricatorIRCWhatsNewHandler.php new file mode 100644 index 0000000000..0dd10e4c4a --- /dev/null +++ b/src/infrastructure/daemon/irc/handler/whatsnew/PhabricatorIRCWhatsNewHandler.php @@ -0,0 +1,143 @@ +getCommand()) { + case 'PRIVMSG': + $reply_to = $message->getReplyTo(); + if (!$reply_to) { + break; + } + + $message = $message->getMessageText(); + + $prompt = '~what( i|\')?s new\?~i'; + if (preg_match($prompt, $message)) { + $this->getLatest($reply_to); + } + break; + } + } + + public function getLatest($reply_to) { + $latest = $this->getConduit()->callMethodSynchronous( + 'feed.query', + array( + 'limit'=>5 + )); + + $phids = array(); + foreach ($latest as $action) { + if (isset($action['data']['actor_phid'])) { + $uid = $action['data']['actor_phid']; + } + else { + $uid = $action['authorPHID']; + } + + switch ($action['class']) { + case 'PhabricatorFeedStoryDifferential': + array_push($phids,$action['data']['revision_phid']); + break; + + case 'PhabricatorFeedStoryManiphest': + array_push($phids,$action['data']['taskPHID']); + break; + + default: + array_push($phids,$uid); + break; + } + array_push($phids,$uid); + } + + $infs = $this->getConduit()->callMethodSynchronous( + 'phid.query', + array( + 'phids'=>$phids + )); + + $cphid = 0; + foreach ($latest as $action) { + if (isset($action['data']['actor_phid'])) { + $uid = $action['data']['actor_phid']; + } + else { + $uid = $action['authorPHID']; + } + switch ($action['class']) { + case 'PhabricatorFeedStoryDifferential': + $rinf = $infs[$action['data']['revision_phid']]; + break; + + case 'PhabricatorFeedStoryManiphest': + $rinf = $infs[$action['data']['taskPHID']]; + break; + + default: + $rinf = array('name'=>$action['class']); + break; + } + $uinf = $infs[$uid]; + + $action = $this->getRhetoric($action['data']['action']); + $user = $uinf['name']; + $title = $rinf['fullName']; + $uri = $rinf['uri']; + $color = chr(3); + $blue = $color.'12'; + $gray = $color.'15'; + $bold = chr(2); + $reset = chr(15); + $content = "{$bold}{$user}{$reset} {$gray}{$action} {$blue}{$bold}". + "{$title}{$reset} - {$gray}{$uri}{$reset}"; + $this->write('PRIVMSG',"{$reply_to} :{$content}"); + } + return; + } + + public function getRhetoric($input) { + switch ($input) { + case "none": + return 'commented on'; + break; + case "update": + return 'updated'; + break; + case "create": + return 'created'; + break; + case "abandon": + return 'abandonned'; + break; + case "accept": + return 'accepted'; + break; + default: + return $input; + break; + } + } +} diff --git a/src/infrastructure/daemon/irc/handler/whatsnew/__init__.php b/src/infrastructure/daemon/irc/handler/whatsnew/__init__.php new file mode 100644 index 0000000000..066864dcd0 --- /dev/null +++ b/src/infrastructure/daemon/irc/handler/whatsnew/__init__.php @@ -0,0 +1,12 @@ +