Jump to content

IRC Bot


OUTLAW3D

Recommended Posts

Ok, so I am making an IRC bot in PHP and I want it to perform an action like /me slaps you but I can't get it to work. A friend said to do this:

 

fputs($socket, "PRIVMSG ".$ex[2]." :\001ACTION".$ex[4]." :\001\r\n");

 

That doesn't work though. I want the bot to accept a name and then perform an action like I say "!slap that_guy" and the bot will say "bot slaps that_guy".

 

Here is my source so far:

 

<?php

set_time_limit(0);

$socket = fsockopen("irc.thedefaced.org", 6667);

fputs($socket, "USER mini-me dark-coders.co.uk MM :mini-me\n");
fputs($socket, "NICK mini-me\n");

fputs($socket, "JOIN #Dark-Coders\n");

while(1)
{
    while($data = fgets($socket, 128))
{
    echo nl2br($data);
	flush();

	$ex = explode(' ', $data);

	if($ex[0] == "PING")
	{
	    fputs($socket, "PONG ".$ex[1]."\n");
	}

	$command = str_replace(array(chr(10), chr(13)), '', $ex[3]);
	if($command == ":!quit")
	{
	    fputs($socket, "PRIVMSG ".$ex[2]." :Later guys!\n");
		die();
	}

	$md5 = md5($ex[4]);
	if($command == ":!md5")
	{
	    fputs($socket, "PRIVMSG ".$ex[2]." :$md5\n");
	}

	$say = $ex[4];
	if($command == ":!say")
	{
	    fputs($socket, "PRIVMSG ".$ex[2]." :$say\n");
	}
}
}
?>

 

If you understand what I'm asking, do you think you could help me out?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.