This is my first irc bot made with PHP: idea is simple playing a game that forces you into searching for peopld just type !search bla and it will post in anotehr channel
note : $search_channel cld be turned into an array then while loop it to search into more than one channel
<?php
// Prevent PHP from stopping the script after 30 sec
set_time_limit(0);
//identifying vars
$host = "network";
$nick="php-bot";
$chan="#channel name";
$search_channel = "#channel to search in";
$no_talking = 0;
// Opening the socket
$socket = fsockopen($host, 6667);
// Send auth info
fputs($socket,"USER PHP_BOT bla MHB :bla PHP IRC BOT\n");
fputs($socket,"NICK $nick\n");
// WAIT FOR SIGN IN
while($logincount < 10) {
$logincount++;
$data = fgets($socket, 128);
echo nl2br($data);
// Separate all data
$ex = explode(' ', $data);
// Send PONG back to the server
if($ex[0] == "PING"){
fputs($socket, "PONG ".$ex[1]."\n");
}
flush();
}
//sleep 10 seconds before joining
sleep(10);
// Join channel
fputs($socket, "JOIN :".$chan."\n");
// Force an endless while
while(1) {
// Continue the rest of the script here
while($data = fgets($socket, 128)) {
echo nl2br($data);
// Separate all data
$ex = explode(' ', $data);
// Send PONG back to the server
if($ex[0] == "PING"){
fputs($socket, "PONG ".$ex[1]."\n");
}
//seperate username and hostname
preg_match('/^:(.*?)!(.*?)$/i', $ex[0], $matches);
$hostname = "!".$matches[2];
$username = $matches[1];
//placing what user says in a variable
$command = str_replace(array(chr(10), chr(13)), '', $ex[3]);
switch ($command) {
//welcome message
case ":!welc":
fputs($socket, "PRIVMSG ".$chan." :welcome to my channel channel...Soon we are going to have our new set of services here keep checking:) \n");
break;
//ending the script
case ":!end":
fputs($socket, "QUIT\n");
break;
//search for a game through !search
case ":!search":
//put what user says in a raw called $say_raw
$c=4;
$say_raw = "";
while (isset($ex[$c])){
$say_raw .= $ex[$c]." ";
$c++;
}
//send msg to another channel
fputs($socket, "PRIVMSG ".$search_channel." : ".$username." : searching".$say_raw."\n");
break;
default:
$no_talking++;
if ($no_talking % 60 == 0){
fputs($socket, "PRIVMSG ".$chan." :you can use search \n");
}
break;
}
flush();
}
sleep(1);
}
?>
well i was facing the same situation with quake net but when i added the sign in part it was fixed and i use my bot on quakenet please try it on some other network to see if its just quake or the bot
while($logincount < 10) {
$logincount++;
$data = fgets($socket, 128);
echo nl2br($data);
// Separate all data
$ex = explode(' ', $data);
// Send PONG back to the server
if($ex[0] == "PING"){
fputs($socket, "PONG ".$ex[1]."\n");
}
flush();
}