Jump to content

Trollbot V0.1


Trip
 Share

Recommended Posts

fun little project php trollbot ... im not brilliant with php but enjoyed making this ... any suggestions to tidy up my code greatly appreciated :D

have fun and dont abuse this code :)

<?php

$chitchat = array("you cant beat windows 3.11", "linus torvalds is a blithering idiot", "stop haxing me i know you've got inside internet explorer!!", "internet explorer is soo win", "how do you install lunix?", "im stuck on trackback it says enter my login wtf?", "wait i bet you guys use lunix :D:D:D", "how does google work?", "my computer is an ibm mac", "i love bill jobs", "steve gates is my hero", "does anyone here use lunix?", "windows is far superior", "windows 95 was my personal fav", "oh fuckerty fuck", "hahahahahahaahahaha that wasn't funny", "you should really install gentoo :D", "i can compiles the lunix now", "im from the darknet", "uhoh bsod ffs when will ms remove this feature", "is there a cheat code for linux? rm???? idk im such a n00b?", "you will phaillz i will windowzzzz hahahahahaha", "firefox is a bucket of fail", "chrome sucks balls", "can u hack this ip for me ? ... 127.0.0.1", "im hacking your computer to get your passwords.", "have you tried restarting it three times?", "is it raining outside", "floppy disks will never die", "how can i fit a dvd on to a cd ??", "iphones suck", "i hate apples", "the only good mac is a macintosh coat", "wutchu up2 eneways??", "how do you install the skynet?", "I heard AMD processors are made of wood so I use mac like a real hackzor" , "AOL Is da shit, it so kicks ass in comparison to fiber." , "Heh, I downloaded a program onto my buddies pc to make his windorz boxor move the start icon, also renamed it to click my ass xP" , "Want to fuck with me? I'll hax0r your ass into tomorrow. My Ip is 198.162.0.100, haxs me pl0x." , "I use Lunix by Linyos Torovoltos" , "Telnet is my homeboi." , "Neurogansta and Haxors were awsome tape mixes.", "everyone knows osx is based on windows", "h4x0r in tha housizzle", "If at first you don't succeed call it version 1.0", "Never gonna give you up!", "lunix ftw");

date_default_timezone_set('GMT');
$booted = date(DATE_RFC822);
$trollcount = 0;

/**
* Trollbot! v0.1
*/


set_time_limit(0);
ini_set('display_errors', 'on');

$config = array(
  'server' => 'irc.lameserver.org',
  'port'   => 6667,
  'channel' => '#lamechannel',
  'name'   => 'smeghead',
  'nick'   => 'smeghead',
  'pass'   => '',
  'website' => 'p0rn.com'
);

class IRCBot {

	var $socket;
	var $ex = array();

	function __construct($config){
		$this->socket = fsockopen($config['server'], $config['port']);
		$this->login($config);
		$this->main($config);
	}

	function login($config){
		$this->send_data('USER', $config['nick'].' '.$config['website'].' '.$config['nick'].' :'.$config['name']);
		$this->send_data('NICK', $config['nick']);
		$this->join_channel($config['channel']);
	}

	function main($config){

		$data = fgets($this->socket, 256);
		echo nl2br($data);
		flush();
		$this->ex = explode(' ', $data);
		if($this->ex[0] == 'PING'){
		$this->send_data('PONG', $this->ex[1]);}
		$command = trim(str_replace(array(chr(10), chr(13)), ' ',$this->ex[3]));

		switch($command){
			case ":!stats":
				$this->send_data('PRIVMSG '.$config['channel'], 'Stats: (Boot time : '.$GLOBALS['booted'].')(Trolled '.$GLOBALS['trollcount'].' times)(Phrases : '.count($GLOBALS['chitchat']).')');
				break;			
			case ':!join':
				$this->join_channel($this->ex[4]);
				break;

			case ':!part':
				$this->send_data('PART '.$this->ex[4].' :', ' byebye!');
				break;

			case ':!say':
				$message = "";
				for($i=4; $i <= (count($this->ex)); $i++){
					$message .= $this->ex[$i]." ";}
				$this->send_data('PRIVMSG '.$config['channel'], $message);
				break;

			case ':!restart':
				echo "<meta http-equiv=\"refresh\" content=\"5\">";
				exit;

			case ':!shutdown':
				$this->send_data('QUIT', ' needs to recharge.');
				exit;

			case ':!add':
				$trollphrases = $GLOBALS['chitchat'];
				$phrase = "";
				for($i=4; $i <= (count($this->ex)); $i++){
					$phrase .= $this->ex[$i]." ";}

				array_push($trollphrases, $phrase);
				$GLOBALS['chitchat'] = $trollphrases;
				print "Added new phrase :<br>".$phrase.'<br>';
				break;

			case ':!troll':
				$trollphrases = $GLOBALS['chitchat'];
				$rand_arrayno = rand(0, (count($trollphrases)-1));
				$this->send_data('PRIVMSG '.$config['channel'], $trollphrases[$rand_arrayno]);
				$GLOBALS['trollcount'] = $GLOBALS['trollcount']+1;
				break;}

		$this->main($config);
	}
	function send_data($cmd, $msg = null){
		if($msg == null){
			fputs($this->socket, $cmd."\r\n");
			echo '<strong>'.$cmd.'</strong><br />';
		} else {
			fputs($this->socket, $cmd.' '.$msg."\r\n");
			echo '<strong>'.$cmd.' '.$msg.'</strong><br />';}
	}

	function join_channel($channel){
		if(is_array($channel)){
			foreach($channel as $chan){
				$this->send_data('JOIN', $chan);}
		} else {
			$this->send_data('JOIN', $channel);}
	} 
} 
$bot = new IRCBot($config);
?>

Edited by Trip
Link to comment
Share on other sites

Looks good. I do have a couple of suggestions though:

Your main function is used recursively and never returns. This is very memory inefficient and will fill php's call stack quickly. You should change it to use a infinite look instead.

The use of $GLOBALS makes me sad, especially since you are using a class and could have made the global variables a property of the class.

Link to comment
Share on other sites

i tried using $config to hold the phrases but couldn't seem to set them @ runtime ... php isn't my favoured language and i threw this together in a couple of nights

points taken tho ... ill try and improve on the code

... the infinite loop was in the original bit of source i used to make the bot

thanks for checking it though :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...