Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F96133448
PhabricatorBotLogHandler.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Dec 22, 23:57
Size
1 KB
Mime Type
text/x-php
Expires
Tue, Dec 24, 23:57 (1 d, 19 h)
Engine
blob
Format
Raw Data
Handle
23129322
Attached To
rPH Phabricator
PhabricatorBotLogHandler.php
View Options
<?php
/**
* Logs chatter.
*
* @group irc
*/
final
class
PhabricatorBotLogHandler
extends
PhabricatorBotHandler
{
private
$futures
=
array
();
public
function
receiveMessage
(
PhabricatorBotMessage
$message
)
{
switch
(
$message
->
getCommand
())
{
case
'MESSAGE'
:
$reply_to
=
$message
->
getReplyTo
();
if
(!
$reply_to
)
{
break
;
}
if
(!
$message
->
isPublic
())
{
// Don't log private messages, although maybe we should for debugging?
break
;
}
$logs
=
array
(
array
(
'channel'
=>
$reply_to
,
'type'
=>
'mesg'
,
'epoch'
=>
time
(),
'author'
=>
$message
->
getSender
(),
'message'
=>
$message
->
getBody
(),
),
);
$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
(
$reply_to
).
'/'
);
$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
);
}
}
}
}
Event Timeline
Log In to Comment