I’m using a IRC bot written in procedural PHP that was originally created by Phil, and now I’m using it for learning purpose. The bot works, it sets the IRC server and joins the channels that were set, it can also handle simple commands and respond something back into the channel.
But I’m trying to create a command whenever somebody writes “!call wakey wakey it’s time to wake up now” then the bot sends a message inside the channel with a list of usernames and the message that was written after “!call” in a newline after posting the list with names.
For example:
Current users in the channel are:
foo
bar
foobar
barfoo
Person A says: !call does anyone know where I can find my teddy-bear?
Bot responds: foo, bar, foobar, barfoo
Bot responds: does anyone know where I can find my teddy-bear?
What is does, is that is will be triggered if “!call” is at the start of a message. Then it will call a function get_data_call which will take the message from the channel and split the !call and the message and the function only returns the message back or returns false. so far it works, I did get the message stored in a variable.
Now what my problem is:
Now I must send a “NAMES ” command to the IRC server, which then returns a list of usernames that are currently in the channel that the bot is in. But I can’t seem to catch that list, I do see that I get a message back from the server and I’ve tried to use something like that but I’m sure this not the exact way to do it (otherwise it would work):
while (!feof($sock))
{
$readCall = fread($sock, 4024);
if ($readCall === true)
{
while (strpos($readCall, ':irc.rizon.no') !== false)
{
echo "irc.rizon.no found!";
break;
}
}
else
{
echo "readCall returns false.";
break;
}
}
This doesn’t work and will always return false.
The full code can be found here: http://pastebin.com/edit.php?i=F2bAdDmS
I hope somebody on this wonderful site can help me with this, I will really appreciate that.
Thank you.
//Xenios
strpos()will return a positive integer, or 0, when a match is found. You should try instead using a!== falsein your condition, becausestrpos()can return 0 if a match is found in the first character.