Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F113279
PhabricatorBotObjectNameHandler.php
All Users
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
dctrwatson
Feb 15 2014, 12:41 AM
2014-02-15 00:41:27 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
PhabricatorBotObjectNameHandler.php
View Options
<?php
/**
* Watches for "tell me about <slug>"
* and "phabot remember <slug> as: <text>"
*
* @group irc
*/
final
class
PhabricatorBotDocHandler
extends
PhabricatorBotHandler
{
public
function
receiveMessage
(
PhabricatorBotMessage
$message
)
{
switch
(
$message
->
getCommand
())
{
case
'MESSAGE'
:
$matches
=
null
;
$text
=
$message
->
getBody
();
$pattern
=
'@^tell me about (.*)$@'
;
if
(
preg_match
(
$pattern
,
$text
,
$matches
))
{
try
{
$result
=
$this
->
getConduit
()->
callMethodSynchronous
(
'phriction.info'
,
array
(
'slug'
=>
'docbot/'
.
$matches
[
1
],
));
}
catch
(
ConduitClientException
$ex
)
{
phlog
(
$ex
);
$result
=
null
;
}
$response
=
array
();
if
(
$result
)
{
$content
=
phutil_split_lines
(
$result
[
'content'
],
$retain_newlines
=
false
);
foreach
(
$content
as
$line
)
{
$response
=
array_merge
(
$response
,
str_split
(
$line
,
400
));
if
(
count
(
$response
)
>=
3
)
{
break
;
}
}
}
else
{
$response
[]
=
"Nothing to say about "
.
$slug
;
}
foreach
(
array_slice
(
$response
,
0
,
3
)
as
$output
)
{
$this
->
replyTo
(
$message
,
html_entity_decode
(
$output
));
}
break
;
}
$pattern
=
'@'
.
$this
->
getConfig
(
'nick'
,
'phabot'
).
' remember '
.
'(.*?)'
.
' as:'
.
'(.*)$'
.
'@'
;
if
(
preg_match
(
$pattern
,
$text
,
$matches
))
{
$result
=
$this
->
getConduit
()->
callMethodSynchronous
(
'phriction.edit'
,
array
(
'slug'
=>
'docbot/'
.
$matches
[
1
],
'content'
=>
$matches
[
2
],
));
$slug
=
explode
(
'/'
,
trim
(
$result
[
'slug'
],
'/'
));
$output
=
"Saved as '${slug[1]}' at ${result['uri']}"
;
$this
->
replyTo
(
$message
,
$output
);
break
;
}
break
;
}
}
private
function
lookupDoc
(
$slug
)
{
}
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/bw/ot/pqnkfrgfgy43ia7h
Default Alt Text
PhabricatorBotObjectNameHandler.php (2 KB)
Attached To
Mode
P1067 PhabricatorBotObjectNameHandler.php
Attached
Detach File
Event Timeline
Log In to Comment