Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F443645
PhabricatorBotLogHandler.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
PhabricatorBotLogHandler.php
View Options
<?php
/**
* Logs chatter.
*/
final
class
PhabricatorBotLogHandler
extends
PhabricatorBotHandler
{
private
$futures
=
array
();
public
function
receiveMessage
(
PhabricatorBotMessage
$message
)
{
switch
(
$message
->
getCommand
())
{
case
'MESSAGE'
:
$target
=
$message
->
getTarget
();
if
(!
$target
->
isPublic
())
{
// Don't log private messages, although maybe we should for debugging?
break
;
}
$target_name
=
$target
->
getName
();
$logs
=
array
(
array
(
'channel'
=>
$target_name
,
'type'
=>
'mesg'
,
'epoch'
=>
time
(),
'author'
=>
$message
->
getSender
()->
getName
(),
'message'
=>
$message
->
getBody
(),
'serviceName'
=>
$this
->
getServiceName
(),
'serviceType'
=>
$this
->
getServiceType
(),
),
);
$this
->
futures
[]
=
$this
->
getConduit
()->
callMethod
(
'chatlog.record'
,
array
(
'logs'
=>
$logs
,
));
$prompts
=
array
(
'/where is the (chat)?log
\?
/i'
,
'/where am i
\?
/i'
,
'/what year is (this|it)
\?
/i'
,
);
$tell
=
false
;
foreach
(
$prompts
as
$prompt
)
{
if
(
preg_match
(
$prompt
,
$message
->
getBody
()))
{
$tell
=
true
;
break
;
}
}
if
(
$tell
)
{
$response
=
$this
->
getURI
(
'/chatlog/channel/'
.
phutil_escape_uri
(
$target_name
).
'/'
);
$this
->
replyTo
(
$message
,
$response
);
}
break
;
}
}
public
function
runBackgroundTasks
()
{
foreach
(
$this
->
futures
as
$key
=>
$future
)
{
try
{
if
(
$future
->
isReady
())
{
unset
(
$this
->
futures
[
$key
]);
}
}
catch
(
Exception
$ex
)
{
unset
(
$this
->
futures
[
$key
]);
phlog
(
$ex
);
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, May 4, 10:56 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
64844
Default Alt Text
PhabricatorBotLogHandler.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment