Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F96133061
PhabricatorBotHandler.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:47
Size
1 KB
Mime Type
text/x-php
Expires
Tue, Dec 24, 23:47 (1 d, 18 h)
Engine
blob
Format
Raw Data
Handle
23129286
Attached To
rPH Phabricator
PhabricatorBotHandler.php
View Options
<?php
/**
* Responds to IRC messages. You plug a bunch of these into a
* @{class:PhabricatorBot} to give it special behavior.
*
* @group irc
*/
abstract
class
PhabricatorBotHandler
{
private
$bot
;
final
public
function
__construct
(
PhabricatorBot
$irc_bot
)
{
$this
->
bot
=
$irc_bot
;
}
final
protected
function
writeMessage
(
PhabricatorBotMessage
$message
)
{
$this
->
bot
->
writeMessage
(
$message
);
return
$this
;
}
final
protected
function
getConduit
()
{
return
$this
->
bot
->
getConduit
();
}
final
protected
function
getConfig
(
$key
,
$default
=
null
)
{
return
$this
->
bot
->
getConfig
(
$key
,
$default
);
}
final
protected
function
getURI
(
$path
)
{
$base_uri
=
new
PhutilURI
(
$this
->
bot
->
getConfig
(
'conduit.uri'
));
$base_uri
->
setPath
(
$path
);
return
(
string
)
$base_uri
;
}
abstract
public
function
receiveMessage
(
PhabricatorBotMessage
$message
);
public
function
runBackgroundTasks
()
{
return
;
}
public
function
replyTo
(
$original_message
,
$body
)
{
if
(
$original_message
->
getCommand
()
!=
'MESSAGE'
)
{
throw
new
Exception
(
"Handler is trying to reply to something which is not a message!"
);
}
$reply
=
id
(
new
PhabricatorBotMessage
())
->
setCommand
(
'MESSAGE'
);
if
(
$original_message
->
isPublic
())
{
// This is a public target, like a chatroom. Send the response to the
// chatroom.
$reply
->
setTarget
(
$original_message
->
getTarget
());
}
else
{
// This is a private target, like a private message. Send the response
// back to the sender (presumably, we are the target).
$reply
->
setTarget
(
$original_message
->
getSender
())
->
setPublic
(
false
);
}
$reply
->
setBody
(
$body
);
return
$this
->
writeMessage
(
$reply
);
}
}
Event Timeline
Log In to Comment