I wrote my first command for random quotes on my chat:
- Code: Select all
// create the customized command
require_once "src/pfccommand.class.php";
class pfcCommand_quote extends pfcCommand
{
function run(&$xml_reponse, $clientid, $msg)
{
$c =& $this->c;
$nick = $c->nick;
$container =& $c->getContainerInstance();
$para = trim($msg);
$para = explode(" ",$para);
$URL = 'http://www.rationalmind.net/random.php?format=txt&';
if ($para[0] == '') {
$quote = explode("~~", trim(@file_get_contents($URL)));
} elseif ($para[0] =='topic') {
$quote = explode("~~", trim(@file_get_contents($URL.'topic='.$para[1])));
} elseif ($para[0] =='author') {
$quote = explode("~~", trim(@file_get_contents($URL.'author='.$para[1])));
} elseif ($para[0] =='mises') {
$quote = explode("~~", trim(@file_get_contents("http://www.mises.org/quote.aspx?format=txt")));
} elseif ($para[0] =='random') {
$quote = explode("~~", trim(@file_get_contents("http://www.timelessquotes.com/randq.php")));
}
$result = '"'.$quote[0].'" - '.$quote[1];
if (!$quote[0]) { $result = 'Not found!'; }
if (!$quote[0])
{
$cmd =& pfcCommand::Factory("error", $c);
$cmd->run($xml_reponse, $clientid, "Quote failed: " . $result);
}
else
{
$container->writeMsg($quote[1], $result);
}
if ($c->debug) pxlog("Cmd_quote[".$c->sessionid."]: msg=".$result, "chat", $c->getId());
}
}