All pastes #910153 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-02-19 19:55 UTC
rendered paste body
<?php
// Prevent PHP from stopping the script after 30 sec
set_time_limit(0);

class IRC_CLIENT {
	private $sock;
	private $run_loop = false;
	
	private $server_host;
	private $server_port;
	
	private $nick;
	
	
	public function isConnected(){
		return ($this->sock) ? true : false;
	}
	
	public function connectionConnect($server, $port=6667){
		$this->sock = fsockopen($server, $port);
		
		if(!$this->sock) return false;
		
		$this->server_host = $server;
		$this->server_port = $port;
		
		return true;
	}
	
	public function connectionRegister($nick, $username, $hostname, $servername, $realname){
		if(!$this->isConnected()) return false;
		
		
		if(!$this->sendCommand("USER $username $hostname $servername $realname"))
			return false;
		
		$this->setNick($nick);
		
		return true;
	}
	
	
	private function sendCommand($data, $suffix = "\n"){
		if(!$this->isConnected()) return false;
		echo "     SENDING DATA $data\n";
		$bytes_written = fputs($this->sock, $data.$suffix);
		if(!$bytes_written) return false;
		
		return true;
	}
	
	private function setNick($newNick){
		if(!$this->isConnected()) return false;
		
		$this->sendCommand("NICK $newNick");
	}
	
	public function joinChannel($channel){
		if(!$this->isConnected()) return false;
		
		if(substr($channel,0 ,1) != "#") return false;
		
		if(!$this->sendCommand("JOIN $channel"))
			return false;
			
		return true;
	}
	
	public function startListen(){
		$this->run_loop = true;
		$this->mainLoop();
	}
	public function stopListen(){
		$this->run_loop = false;
	}
	public function mainLoop($times=null){
		global $inf0;
		
		stream_set_timeout($this->sock, 1);
		while($this->run_loop){
			if($times != null){
				$times--;
				if($times == 0){
					$this->run_loop = false;
					continue;
				}
			}
			if(!$data = fgets($this->sock, 128)){
				continue;
			}
			
			echo "$data";
	        // Separate all data
	        $ex = explode(' ', $data);
	        for($i=0; $i<count($ex); $i++) $ex[$i] = trim($ex[$i]); 
	        
	        // Send PONG back to the server
	        if($ex[0] == "PING"){
	            $this->sendCommand("PONG ".$ex[1]);
	        }

			if(isset($last_cmd) && TIME() - $last_cmd < 2) continue;
			$last_cmd = TIME();
	
	        // Say something in the channel
	        $command = str_replace(array(chr(10), chr(13)), '', $ex[3]);
	        switch($command){
	        	case ":!l":
	        		$name = "";
	        		for($i=4; $i<count($ex); $i++)
	        			$name .= "{$ex[$i]} ";
	        		
	        		$this->sendCommand("PRIVMSG {$ex[2]} :".$name."is LRON!");
	            	break;
	            	
	        	case ":!help":
	        		foreach($inf0 as $line)
	        			$this->sendCommand("PRIVMSG {$ex[2]} :$line");
	        		
	        		break;

	        	case ":!contact":
	        		$name = "";
	        		for($i=4; $i<count($ex); $i++)
	        			$name .= "{$ex[$i]} ";
	        		
	        		$this->sendCommand("PRIVMSG {$ex[2]} :To contact Manchester Anonymous, e-mail Anonymous@irleet.com or call 07005993680");
	        		
	        		break;	


	        	case ":!when":
	        		$name = "";
	        		for($i=4; $i<count($ex); $i++)
	        			$name .= "{$ex[$i]} ";
	        		
	        		$this->sendCommand("PRIVMSG {$ex[2]} :The next protest is on 15th of March");
	        		
	        		break;	


	        	case ":!where":
	        		$name = "";
	        		for($i=4; $i<count($ex); $i++)
	        			$name .= "{$ex[$i]} ";
	        		
	        		$this->sendCommand("PRIVMSG {$ex[2]} :The manchester Scientology branch is at 258-260 Deansgate, Manchester, M3 4BG,");
	        		
	        		break;	

	        	case ":!rules":
	        		$name = "";
	        		for($i=4; $i<count($ex); $i++)
	        			$name .= "{$ex[$i]} ";
	        		
	        		$this->sendCommand("PRIVMSG {$ex[2]} :The Protest rules can be found at http://downwiththe.org.uk/w/index.php/Rules");
	        		
	        		break;	

	        	case ":!what":
	        		$name = "";
	        		for($i=4; $i<count($ex); $i++)
	        			$name .= "{$ex[$i]} ";
	        		
	        		$this->sendCommand("PRIVMSG {$ex[2]} :Anonymous is a group of people, unknown to eachother and the rest of the world, fighting against the crimes against humanity that the so called Church of Scientology has commited, See www.whyaretheydead.net");
	        		
	        		break;	

	        	case ":!wbm":
	        		$name = "";
	        		for($i=4; $i<count($ex); $i++)
	        			$name .= "{$ex[$i]} ";
	        		
	        		$this->sendCommand("PRIVMSG {$ex[2]} :Wise Beard Man may be our strongest allie in this fight, see www.xenutv.com for more information.");
	        		
	        		break;	
            
	        	case ":!killtheb0t123":
	        		$this->stopListen();
				echo "STOPPING BOT";
	        		break;
	        		
	        	default:
	        		$ex[3] = substr($ex[3], 1);
	        		$msg = "";
	        		for($i=3; $i<count($ex); $i++) $msg .= "{$ex[$i]} ";
	        		$msg_lower = strtolower($msg);
	        		
	        		$reply = "";
	        		switch(true){
	        			case strpos($msg_lower, "cp") !== false:
	        				$reply = $cp;
	        				break;
	        				
	        			case strpos($msg_lower, "i love you") !== false:
	        				$reply = "i love you too, but your an ugly ass";
	        				break;
	        				
	        			default:
	        				$reply = "";
					}
	        		if($reply != ""){
	        			$this->sendCommand("PRIVMSG {$ex[2]} :$reply");
	        		}
	        }
	        
	        usleep(1);
		}
		echo "\n\nDONE $times\n\n";
	}
}




$inf0[0] = <<<line
Welcome to the #Manchester helpfag, to find out more, use the following commands
line;
$inf0[1] = <<<line
!rules !what  !when  !where  !contact !wbm
line;



$irc = new IRC_CLIENT();
echo "Connecting...\n";
$irc->connectionConnect("irc.partyvan.org");

echo "Registering...\n";
$irc->connectionRegister("Info", "Manchesterfag", "xenu.net", "irc.partyvan.org", "lol");
$irc->mainLoop(7);

echo "Joining channel...\n";
$irc->joinChannel("#Bottest");
$irc->mainLoop(5);
echo "And now listening\n";
$irc->startListen();
?>