Skip to content

Commit ec19c33

Browse files
dctrwatsonepriestley
authored and
epriestley
committedJan 15, 2013
Break IRCSymbolHandler from IRCObjectNameHandler
Summary: Allows to easily disable responding to "where is..." Test Plan: Run ircbot with and without the handler Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4444
1 parent 7857508 commit ec19c33

File tree

4 files changed

+58
-37
lines changed

4 files changed

+58
-37
lines changed
 

‎resources/ircbot/example_config.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"handlers" : [
99
"PhabricatorIRCProtocolHandler",
1010
"PhabricatorIRCObjectNameHandler",
11+
"PhabricatorIRCSymbolHandler",
1112
"PhabricatorIRCLogHandler",
1213
"PhabricatorIRCWhatsNewHandler",
1314
"PhabricatorIRCDifferentialNotificationHandler",

‎src/__phutil_library_map__.php

+2
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,7 @@
888888
'PhabricatorIRCMessage' => 'infrastructure/daemon/irc/PhabricatorIRCMessage.php',
889889
'PhabricatorIRCObjectNameHandler' => 'infrastructure/daemon/irc/handler/PhabricatorIRCObjectNameHandler.php',
890890
'PhabricatorIRCProtocolHandler' => 'infrastructure/daemon/irc/handler/PhabricatorIRCProtocolHandler.php',
891+
'PhabricatorIRCSymbolHandler' => 'infrastructure/daemon/irc/handler/PhabricatorIRCSymbolHandler.php',
891892
'PhabricatorIRCWhatsNewHandler' => 'infrastructure/daemon/irc/handler/PhabricatorIRCWhatsNewHandler.php',
892893
'PhabricatorImageTransformer' => 'applications/files/PhabricatorImageTransformer.php',
893894
'PhabricatorInfrastructureTestCase' => 'infrastructure/__tests__/PhabricatorInfrastructureTestCase.php',
@@ -2254,6 +2255,7 @@
22542255
'PhabricatorIRCMacroHandler' => 'PhabricatorIRCHandler',
22552256
'PhabricatorIRCObjectNameHandler' => 'PhabricatorIRCHandler',
22562257
'PhabricatorIRCProtocolHandler' => 'PhabricatorIRCHandler',
2258+
'PhabricatorIRCSymbolHandler' => 'PhabricatorIRCHandler',
22572259
'PhabricatorIRCWhatsNewHandler' => 'PhabricatorIRCHandler',
22582260
'PhabricatorInfrastructureTestCase' => 'PhabricatorTestCase',
22592261
'PhabricatorInlineCommentController' => 'PhabricatorController',

‎src/infrastructure/daemon/irc/handler/PhabricatorIRCObjectNameHandler.php

-37
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ public function receiveMessage(PhabricatorIRCMessage $message) {
2222
break;
2323
}
2424

25-
$this->handleSymbols($message);
26-
2725
$message = $message->getMessageText();
2826
$matches = null;
2927

@@ -198,39 +196,4 @@ public function receiveMessage(PhabricatorIRCMessage $message) {
198196
}
199197
}
200198

201-
private function handleSymbols(PhabricatorIRCMessage $message) {
202-
$reply_to = $message->getReplyTo();
203-
$text = $message->getMessageText();
204-
205-
$matches = null;
206-
if (!preg_match('/where(?: in the world)? is (\S+?)\?/i',
207-
$text, $matches)) {
208-
return;
209-
}
210-
211-
$symbol = $matches[1];
212-
$results = $this->getConduit()->callMethodSynchronous(
213-
'diffusion.findsymbols',
214-
array(
215-
'name' => $symbol,
216-
));
217-
218-
$default_uri = $this->getURI('/diffusion/symbol/'.$symbol.'/');
219-
220-
if (count($results) > 1) {
221-
$response = "Multiple symbols named '{$symbol}': {$default_uri}";
222-
} else if (count($results) == 1) {
223-
$result = head($results);
224-
$response =
225-
$result['type'].' '.
226-
$result['name'].' '.
227-
'('.$result['language'].'): '.
228-
nonempty($result['uri'], $default_uri);
229-
} else {
230-
$response = "No symbol '{$symbol}' found anywhere.";
231-
}
232-
233-
$this->write('PRIVMSG', "{$reply_to} :{$response}");
234-
}
235-
236199
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/**
4+
* Watches for "where is <symbol>?"
5+
*
6+
* @group irc
7+
*/
8+
final class PhabricatorIRCSymbolHandler extends PhabricatorIRCHandler {
9+
10+
public function receiveMessage(PhabricatorIRCMessage $message) {
11+
12+
switch ($message->getCommand()) {
13+
case 'PRIVMSG':
14+
$reply_to = $message->getReplyTo();
15+
if (!$reply_to) {
16+
break;
17+
}
18+
19+
$text = $message->getMessageText();
20+
21+
$matches = null;
22+
if (!preg_match('/where(?: in the world)? is (\S+?)\?/i',
23+
$text, $matches)) {
24+
break;
25+
}
26+
27+
$symbol = $matches[1];
28+
$results = $this->getConduit()->callMethodSynchronous(
29+
'diffusion.findsymbols',
30+
array(
31+
'name' => $symbol,
32+
));
33+
34+
$default_uri = $this->getURI('/diffusion/symbol/'.$symbol.'/');
35+
36+
if (count($results) > 1) {
37+
$response = "Multiple symbols named '{$symbol}': {$default_uri}";
38+
} else if (count($results) == 1) {
39+
$result = head($results);
40+
$response =
41+
$result['type'].' '.
42+
$result['name'].' '.
43+
'('.$result['language'].'): '.
44+
nonempty($result['uri'], $default_uri);
45+
} else {
46+
$response = "No symbol '{$symbol}' found anywhere.";
47+
}
48+
49+
$this->write('PRIVMSG', "{$reply_to} :{$response}");
50+
51+
break;
52+
}
53+
}
54+
55+
}

0 commit comments

Comments
 (0)
Failed to load comments.