@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix the `What's New?` phabricatorbot handler.

Summary: `What's new` has been broken for awhile, I've updated it to use the `feed.query` text view.

Test Plan: Start up a bot and say "What's new?"

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: fas, epriestley, aran, Kage, demo

Differential Revision: https://secure.phabricator.com/D8118

authored by

Korvin Szanto and committed by
epriestley
29b29c10 eca7d3fe

+11 -110
+11 -110
src/infrastructure/daemon/bot/handler/PhabricatorBotWhatsNewHandler.php
··· 1 1 <?php 2 2 3 3 /** 4 - * Responds to "Whats new?" using the feed. 4 + * Responds to "Whats new?" with some recent feed content 5 5 * 6 6 * @group irc 7 7 */ ··· 10 10 private $floodblock = 0; 11 11 12 12 public function receiveMessage(PhabricatorBotMessage $message) { 13 - 14 13 switch ($message->getCommand()) { 15 14 case 'MESSAGE': 16 15 $message_body = $message->getBody(); 16 + $now = time(); 17 17 18 18 $prompt = '~what( i|\')?s new\?~i'; 19 19 if (preg_match($prompt, $message_body)) { 20 - if (time() < $this->floodblock) { 20 + if ($now < $this->floodblock) { 21 21 return; 22 22 } 23 - $this->floodblock = time() + 60; 24 - 25 - $this->getLatest($message); 23 + $this->floodblock = $now + 60; 24 + $this->reportNew($message); 26 25 } 27 26 break; 28 27 } 29 28 } 30 29 31 - public function getLatest(PhabricatorBotMessage $message) { 30 + public function reportNew(PhabricatorBotMessage $message) { 32 31 $latest = $this->getConduit()->callMethodSynchronous( 33 32 'feed.query', 34 33 array( 35 - 'limit' => 5 34 + 'limit' => 5, 35 + 'view' => 'text' 36 36 )); 37 37 38 - $phids = array(); 39 - foreach ($latest as $action) { 40 - if (isset($action['data']['actor_phid'])) { 41 - $uid = $action['data']['actor_phid']; 42 - } else { 43 - $uid = $action['authorPHID']; 38 + foreach ($latest as $feed_item) { 39 + if (isset($feed_item['text'])) { 40 + $this->replyTo($message, html_entity_decode($feed_item['text'])); 44 41 } 45 - 46 - switch ($action['class']) { 47 - case 'PhabricatorFeedStoryDifferential': 48 - $phids[] = $action['data']['revision_phid']; 49 - break; 50 - case 'PhabricatorFeedStoryAudit': 51 - $phids[] = $action['data']['commitPHID']; 52 - break; 53 - 54 - case 'PhabricatorFeedStoryManiphest': 55 - $phids[] = $action['data']['taskPHID']; 56 - break; 57 - 58 - default: 59 - $phids[] = $uid; 60 - break; 61 - } 62 - array_push($phids, $uid); 63 42 } 64 - 65 - $infs = $this->getConduit()->callMethodSynchronous( 66 - 'phid.query', 67 - array( 68 - 'phids'=>$phids 69 - )); 70 - 71 - $cphid = 0; 72 - foreach ($latest as $action) { 73 - if (isset($action['data']['actor_phid'])) { 74 - $uid = $action['data']['actor_phid']; 75 - } else { 76 - $uid = $action['authorPHID']; 77 - } 78 - switch ($action['class']) { 79 - case 'PhabricatorFeedStoryDifferential': 80 - $rinf = $infs[$action['data']['revision_phid']]; 81 - break; 82 - 83 - case 'PhabricatorFeedStoryAudit': 84 - $rinf = $infs[$action['data']['commitPHID']]; 85 - break; 86 - 87 - case 'PhabricatorFeedStoryManiphest': 88 - $rinf = $infs[$action['data']['taskPHID']]; 89 - break; 90 - 91 - default: 92 - $rinf = array('name'=>$action['class']); 93 - break; 94 - } 95 - $uinf = $infs[$uid]; 96 - 97 - $action = $this->getRhetoric($action['data']['action']); 98 - $user = $uinf['name']; 99 - $title = $rinf['fullName']; 100 - $uri = $rinf['uri']; 101 - $color = chr(3); 102 - $blue = $color.'12'; 103 - $gray = $color.'15'; 104 - $bold = chr(2); 105 - $reset = chr(15); 106 - // Disabling irc-specific styling, at least for now 107 - // $content = "{$bold}{$user}{$reset} {$gray}{$action} {$blue}{$bold}". 108 - // "{$title}{$reset} - {$gray}{$uri}{$reset}"; 109 - $content = "{$user} {$action} {$title} - {$uri}"; 110 - $this->replyTo($message, $content); 111 - } 112 - return; 113 43 } 114 44 115 - public function getRhetoric($input) { 116 - switch ($input) { 117 - case 'comment': 118 - case 'none': 119 - return 'commented on'; 120 - break; 121 - case 'update': 122 - return 'updated'; 123 - break; 124 - case 'commit': 125 - return 'closed'; 126 - break; 127 - case 'create': 128 - return 'created'; 129 - break; 130 - case 'concern': 131 - return 'raised concern for'; 132 - break; 133 - case 'abandon': 134 - return 'abandonned'; 135 - break; 136 - case 'accept': 137 - return 'accepted'; 138 - break; 139 - default: 140 - return $input; 141 - break; 142 - } 143 - } 144 45 }