Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F431223
PhabricatorBotSymbolHandler.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
PhabricatorBotSymbolHandler.php
View Options
<?php
/**
* Watches for "where is <symbol>?"
*/
final
class
PhabricatorBotSymbolHandler
extends
PhabricatorBotHandler
{
public
function
receiveMessage
(
PhabricatorBotMessage
$message
)
{
switch
(
$message
->
getCommand
())
{
case
'MESSAGE'
:
$text
=
$message
->
getBody
();
$matches
=
null
;
if
(!
preg_match
(
'/where(?: in the world)? is (
\S
+?)
\?
/i'
,
$text
,
$matches
))
{
break
;
}
$symbol
=
$matches
[
1
];
$results
=
$this
->
getConduit
()->
callMethodSynchronous
(
'diffusion.findsymbols'
,
array
(
'name'
=>
$symbol
,
));
$default_uri
=
$this
->
getURI
(
'/diffusion/symbol/'
.
$symbol
.
'/'
);
if
(
count
(
$results
)
>
1
)
{
$response
=
pht
(
"Multiple symbols named '%s': %s"
,
$symbol
,
$default_uri
);
}
else
if
(
count
(
$results
)
==
1
)
{
$result
=
head
(
$results
);
$response
=
$result
[
'type'
].
' '
.
$result
[
'name'
].
' '
.
'('
.
$result
[
'language'
].
'): '
.
nonempty
(
$result
[
'uri'
],
$default_uri
);
}
else
{
$response
=
pht
(
"No symbol '%s' found anywhere."
,
$symbol
);
}
$this
->
replyTo
(
$message
,
$response
);
break
;
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 3, 12:09 PM (1 d, 23 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
60354
Default Alt Text
PhabricatorBotSymbolHandler.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment