PHP - IRC Bot Not sending message Help

佐手、 提交于 2019-12-02 07:03:23

问题


Currently I am making a IRC that sends a message onto the IRC main channel. Here is my code:

<?php


$ircServer = "xxxx";
$ircPort = "6667";
$ircChannel = "#bots";

set_time_limit(0);

$msg = $_GET['msg'];

$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");
    fwrite($ircSocket, "PRIVMSG " . $channel . " :" . $msg = $_GET['msg'] . "\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;
}
}
?>

<html><body>
<h4>IRC Bot Tester</h4>
<form action="irc.php" method="post"> 
Command: <input type="text" name="msg" />
<input type="submit" />
</form>
</body></html>

My problem is the BOT is not sending any messages to the channel, as you see I used post + get data for the message info sent to the channel.

Here is the log what I recieve:

:irc.underworld.no 366 Rawr30517 #bots :End of /NAMES list. :irc.underworld.no 411 Rawr30517 :No recipient given (PRIVMSG) : 0: 0PING :irc.underworld.no

I do not know which part causes the this:

recipient given (PRIVMSG) : 0: 0PING

Thanks if anyone could help me. I am trying to simply post a message to the bot and the bot delivers the message to the main channel.


回答1:


Change:

$msg = $_GET['msg'];
...
fwrite($ircSocket, "PRIVMSG " . $channel . " :" . $msg = $_GET['msg'] . "\n");

To:

$msg = $_POST['msg'];
...
fwrite($ircSocket, "PRIVMSG " . $ircChannel . " :" . $msg . "\n");



回答2:


fwrite($ircSocket, "PRIVMSG " . $ircChannel . " " . $msg = $_GET['msg'] . "\n");

To:

fwrite($ircSocket, "PRIVMSG " . $ircChannel . " " .$msg. "\n");


来源:https://stackoverflow.com/questions/4227518/php-irc-bot-not-sending-message-help

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!