All pastes #465983 Raw Edit

Something

public text v1 · immutable
#465983 ·published 2007-04-30 19:09 UTC
rendered paste body
<?php
  $config = array();
  
  $config['Server'] = 'manticore.uk.eu.SwiftIRC.net';
  $config['Nick'] = 'DragonBot';
  $config['Port'] = 6667;
  $config['Channel'] = '#runeorb';
  $config['Name'] = 'DragonBot';
  
  // Connect to the IRC Server
  
  // Run forever, no timeouts
  set_time_limit(0);
  
  // Connection array
  
  $con = array();
  
  // Start bot
  
  init();
  
  function init() {
   
   global $con, $config;
   $firstTime = true;
  
  $con['socket'] = fsockopen($config['Server'], $config['Port']);
  
   // Check connection
   
     if(!$con['socket']) {
		echo "Could not connect too ".$config['Server']." on port ".$config['Port'].".";
	} else {
		cmd_send("USER ". $config['Nick'] ." runeorb.net runeorb.net : ". $config['Name']);
		cmd_send("NICK ". $config['Nick'] ." runeorb.net");
	}
	
	   // Read incoming data.
	
	     while(!feof($con['socket'])) {
			// Get a line and get rid of whitespace
			
			$con['buffer']['all'] = trim(fgets($con['socket'], 4096));
			
			// Print the line/buffer to the console
			
			  print date("[d/m @ H:i]")."<- ". $con['buffer']['all'] ."n";
			  
			   // If server is PINGing PONG, let the server no the bot is active.
			   
			   if(substr($con['buffer']['all'], 0, 6) == 'PING :') {
			     // PONG
				   cmd_send('PONG :'.substr($con['buffer']['all'], 6));
				 // If first time at this point, join channel
				  if($firstTime == true) {
					cmd_send("JOIN ". $config['Channel']);
					
					$firstTime = false;
				} 
				
			} elseif($old_buffer != $con['buffer']['all']) {
					fputs($con['socket'], $command."\r\n");
					print (date("[d/m @ H:i]"). "-> ". $command. "nr");
					
				} $old_buffer = $con['buffer']['all'];
			
		}
	}
	
	function cmd_send($command) {
		global $con, $config, $time;
		  fputs($con['socket'], $command."\n\r");
		  print (date("[d/m @ H:i]") ."-> ". $command. "\n\r");
	}
  ?>