Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F98234949
PhabricatorIRCLogHandler.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
Sat, Jan 11, 08:00
Size
2 KB
Mime Type
text/x-php
Expires
Mon, Jan 13, 08:00 (2 d)
Engine
blob
Format
Raw Data
Handle
23532716
Attached To
rPH Phabricator
PhabricatorIRCLogHandler.php
View Options
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Looks for Dxxxx, Txxxx and links to them.
*
* @group irc
*/
final
class
PhabricatorIRCLogHandler
extends
PhabricatorIRCHandler
{
private
$futures
=
array
();
public
function
receiveMessage
(
PhabricatorIRCMessage
$message
)
{
switch
(
$message
->
getCommand
())
{
case
'PRIVMSG'
:
$reply_to
=
$message
->
getReplyTo
();
if
(!
$reply_to
)
{
break
;
}
if
(!
$this
->
isChannelName
(
$reply_to
))
{
// Don't log private messages, although maybe we should for debugging?
break
;
}
$logs
=
array
(
array
(
'channel'
=>
$reply_to
,
'type'
=>
'mesg'
,
'epoch'
=>
time
(),
'author'
=>
$message
->
getSenderNickname
(),
'message'
=>
$message
->
getMessageText
(),
),
);
$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
->
getMessageText
()))
{
$tell
=
true
;
break
;
}
}
if
(
$tell
)
{
$response
=
$this
->
getURI
(
'/chatlog/channel/'
.
phutil_escape_uri
(
$reply_to
).
'/'
);
$this
->
write
(
'PRIVMSG'
,
"{$reply_to} :{$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