ircbot/Classes/Client/IrcClient.php

80 lines
1.7 KiB
PHP
Raw Normal View History

2010-11-21 23:48:11 +01:00
<?php
/**
* IrcClient class that contains all the Plugins
* @author jpt
* @package Client
* @depends Client_AbstractClient
*/
class Client_IrcClient extends Client_AbstractClient {
protected $got_001;
protected $joined;
protected $authed;
protected $nick;
protected $channels;
protected $lines;
/**
* Default constructor.
2010-11-28 01:04:35 +01:00
* @return void
2010-11-21 23:48:11 +01:00
*/
function __construct() {
$this->nick = "Serena";
$this->channels = array();
$this->lines = 0;
$this->got_001 = FALSE;
$this->joined = FALSE;
$this->authed = FALSE;
}
/**
* Does all the hard work.
* @param string $data
* @return string
*/
2010-11-28 01:04:35 +01:00
public function processContentObject($contentObject) {
var_dump($contentObject);
2010-11-28 01:04:35 +01:00
$data = $contentObject->rawData;
2010-11-21 23:48:11 +01:00
//echo "[RECV] ".$data;
$this->clientManager->sendToGroup("srv", "[#".$this->ID."] ".$data."\r\n\r\n");
$return = "";
if(strpos($data, "PING :") !== FALSE) $return .= str_replace("PING", "PONG", $data);
if(preg_match("/001/", $data)) $this->got_001 = TRUE;
$this->lines++;
if(!$this->authed && $this->lines > 1) {
$return .= "USER as as as :Asdfg\r\nNICK :" . $this->nick . "\r\n";
$this->authed = TRUE;
}
if($this->got_001 && !$this->joined) {
$this->joined = TRUE;
foreach($this->channels AS $channel) $return .= "JOIN " . $channel . "\r\n";
}
if(strpos($data, "hau ab") !== FALSE) {
$return .= "PRIVMSG ".$this->channels[0]." :roger that :D\r\n";
$return .= "QUIT :lol\r\n";
}
//if($return !== "") echo "[SEND] ".$return;
return $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"];
}
}
?>