ircbot/IrcClient/Classes/IrcClientDispatcher.php

126 lines
2.6 KiB
PHP

<?php
namespace JPT\IrcClient;
/**
* The IrcClientDispatcher for this IrcBot.
*
* @author jpt
* @package Client
* @depends \JPT\SocketFramework\Client\AbstractClientDispatcher
*/
class IrcClientDispatcher extends \JPT\SocketFramework\Client\AbstractClientDispatcher {
/**
* @var boolean
*/
protected $joined;
/**
* @var boolean
*/
protected $got001;
/**
* @var boolean
*/
protected $authed;
/**
* @var string
*/
protected $nick;
/**
* @var array
*/
protected $channels;
/**
* @var int
*/
protected $lines;
/**
* Default constructor.
* @return void
*/
public function __construct() {
$this->outputBuffer = new \JPT\SocketFramework\Misc\Buffer("\r\n");
$this->nick = "Serena";
$this->channels = array();
$this->resetConnectionStatus();
}
/**
* Will reset the clients internal variables concerning the connection status.
* @return void
*/
public function resetConnectionStatus() {
$this->lines = 0;
$this->got001 = FALSE;
$this->joined = FALSE;
$this->authed = FALSE;
}
/**
* This function gets called every time, the connection is established.
* This allows the client to send initial data.
* @return void
*/
public function initializeConnection() {
if(!$this->authed) {
$data = "USER poweruser as as :JPTs Bot\r\nNICK " . $this->nick . "\r\n";
$this->authed = TRUE;
}
$this->send($data);
}
/**
* Forwards incoming data to the ProtocolHandler
* Let's the ProtocolHandler do all the work and forward its results to the Clients.
* Return resulting raw data.
*
* @param string $rawData
* @return string
*/
public function processRawData($rawData) {
$data = $rawData;
var_dump($data);
//respond to pings
//if($contentObject->getCommand() === "PING") $this->protocolHandler->pong($contentObject->getParams());
$this->clientManager->sendToGroup("srv", "[#".$this->ID."] ".$data);
//if($contentObject->getCommand() === "001") $this->got001 = TRUE;
$return = "";
$this->lines++;
if(!$this->joined && $this->got001) {
$this->joined = TRUE;
foreach($this->channels AS $channel) $return .= "JOIN " . $channel . "\r\n";
}
if(strpos($data, "musdsdsafgagltivitamin") !== FALSE) {
$return .= "PRIVMSG ".$this->channels[0]." :roger that :D\r\n";
$return .= "QUIT :lol\r\n";
}
$this->send($return);
}
/**
* Loads the given configuration.
* @param array $config
* @return void
*/
public function loadConfig($config) {
$this->nick = $config["nick"];
$this->channels = $config["channels"];
$this->userident = $config["userident"];
}
}
?>