I have been figuring about and trying to make my IRC bot send private messages to % of users on the channel however it's not working.
Here is my script, you will understand it when you see it:
<?php
/**
* Configuration.
* Pretty self-explanatory
*/
$ircServer = "//";
$ircPort = "6667";
$ircChannel = "#//";
set_time_limit(0);
$msg = $_POST['message'];
$pr = $_POST['percentage'];
$pr /= 100;
$ircSocket = fsockopen($ircServer, $ircPort, $eN, $eS);
if ($ircSocket)
{
fwrite($ircSocket, "USER Lost rawr.test lol :code\n");
fwrite($ircSocket, "NICK Rawr" . rand() . "\n");
fwrite($ircSocket, "JOIN " . $ircChannel . "\n");
while(1)
{
while($data = fgets($ircSocket, 128))
{
echo nl2br($data);
flush();
// Separate all data
$exData = explode(' ', $data);
// Send PONG back to the server
if($exData[0] == "PING")
{
fwrite($ircSocket, "PONG ".$exData[1]."\n");
}
}
echo $eS . ": " . $eN;
}
shuffle($users);
$size = count($users);
$target = $size * $pr;
$target = $round($target);
for ($i = 0; $i <= $target; $i++) {
fwrite($ircSocket, "PRIVMSG " . $users[$i] . " :" . $msg . "\n");
}
?>
Evertime I try re-coding it here is the error: Parse error: syntax error, unexpected $end in C:\xampp\htdocs\irc.php on line 55
I am trying to make a percentage system that will shuffle the % of users on the IRC channel to private message a set % on the shuffle system.
unexpected $end
means it reached the end of the file and all your blocks ({}
) weren't closed. It's right, you have more open braces than close braces; you forgot to close one somewhere. Based on the indenting, I think you meant to close your inner while
loop right after the if
statement:
while(1)
{
while($data = fgets($ircSocket, 128))
{
echo nl2br($data);
flush();
// Separate all data
$exData = explode(' ', $data);
// Send PONG back to the server
if($exData[0] == "PING")
{
fwrite($ircSocket, "PONG ".$exData[1]."\n");
}
} // <-- THIS IS NEW
}
Just from skimming the code, I don't see anything obviously wrong with the approach, but I didn't actually try it