4 files changed +58
-37
lines changed Original file line number Diff line number Diff line change 8
8
"handlers" : [
9
9
" PhabricatorIRCProtocolHandler" ,
10
10
" PhabricatorIRCObjectNameHandler" ,
11
+ " PhabricatorIRCSymbolHandler" ,
11
12
" PhabricatorIRCLogHandler" ,
12
13
" PhabricatorIRCWhatsNewHandler" ,
13
14
" PhabricatorIRCDifferentialNotificationHandler" ,
Original file line number Diff line number Diff line change 888
888
'PhabricatorIRCMessage ' => 'infrastructure/daemon/irc/PhabricatorIRCMessage.php ' ,
889
889
'PhabricatorIRCObjectNameHandler ' => 'infrastructure/daemon/irc/handler/PhabricatorIRCObjectNameHandler.php ' ,
890
890
'PhabricatorIRCProtocolHandler ' => 'infrastructure/daemon/irc/handler/PhabricatorIRCProtocolHandler.php ' ,
891
+ 'PhabricatorIRCSymbolHandler ' => 'infrastructure/daemon/irc/handler/PhabricatorIRCSymbolHandler.php ' ,
891
892
'PhabricatorIRCWhatsNewHandler ' => 'infrastructure/daemon/irc/handler/PhabricatorIRCWhatsNewHandler.php ' ,
892
893
'PhabricatorImageTransformer ' => 'applications/files/PhabricatorImageTransformer.php ' ,
893
894
'PhabricatorInfrastructureTestCase ' => 'infrastructure/__tests__/PhabricatorInfrastructureTestCase.php ' ,
2254
2255
'PhabricatorIRCMacroHandler ' => 'PhabricatorIRCHandler ' ,
2255
2256
'PhabricatorIRCObjectNameHandler ' => 'PhabricatorIRCHandler ' ,
2256
2257
'PhabricatorIRCProtocolHandler ' => 'PhabricatorIRCHandler ' ,
2258
+ 'PhabricatorIRCSymbolHandler ' => 'PhabricatorIRCHandler ' ,
2257
2259
'PhabricatorIRCWhatsNewHandler ' => 'PhabricatorIRCHandler ' ,
2258
2260
'PhabricatorInfrastructureTestCase ' => 'PhabricatorTestCase ' ,
2259
2261
'PhabricatorInlineCommentController ' => 'PhabricatorController ' ,
Original file line number Diff line number Diff line change @@ -22,8 +22,6 @@ public function receiveMessage(PhabricatorIRCMessage $message) {
22
22
break ;
23
23
}
24
24
25
- $ this ->handleSymbols ($ message );
26
-
27
25
$ message = $ message ->getMessageText ();
28
26
$ matches = null ;
29
27
@@ -198,39 +196,4 @@ public function receiveMessage(PhabricatorIRCMessage $message) {
198
196
}
199
197
}
200
198
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
-
236
199
}
Original file line number Diff line number Diff line change
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