mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 19:40:55 +01:00
IRC Bot what's new directive
Summary: Added "What's new?" to the ircbot ====Matches ```What is new? What's new? Whats new``` Test Plan: <`Korvin> what is new? <korvinbot-local> Derpen created D1: Herped the derp - http://phabricator.net/D1 It shows five. Reviewers: epriestley Reviewed By: epriestley CC: epriestley, aran Differential Revision: https://secure.phabricator.com/D1666
This commit is contained in:
parent
af295e0b26
commit
5e39522ac4
5 changed files with 164 additions and 6 deletions
|
@ -9,6 +9,7 @@
|
|||
"PhabricatorIRCProtocolHandler",
|
||||
"PhabricatorIRCObjectNameHandler",
|
||||
"PhabricatorIRCLogHandler",
|
||||
"PhabricatorIRCWhatsNewHandler",
|
||||
"PhabricatorIRCDifferentialNotificationHandler"
|
||||
],
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Responds to "Whats new?" using the feed.
|
||||
*
|
||||
* @group irc
|
||||
*/
|
||||
final class PhabricatorIRCWhatsNewHandler extends PhabricatorIRCHandler {
|
||||
|
||||
public function receiveMessage(PhabricatorIRCMessage $message) {
|
||||
switch ($message->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;
|
||||
}
|
||||
}
|
||||
}
|
12
src/infrastructure/daemon/irc/handler/whatsnew/__init__.php
Normal file
12
src/infrastructure/daemon/irc/handler/whatsnew/__init__.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'infrastructure/daemon/irc/handler/base');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorIRCWhatsNewHandler.php');
|
Loading…
Reference in a new issue