PHP-IRC 函数

发布于 2024-10-03 02:16:07 字数 1331 浏览 7 评论 0原文

我一直在考虑并尝试让我的 IRC 机器人向频道上的 % 用户发送私人消息,但它不起作用。

这是我的脚本,当你看到它时你就会明白它:

<?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");
}
?>

每当我尝试重新编码时,这里是错误: 解析错误:语法错误,意外的 $end in C:\xampp\htdocs\irc.php on line 55

我正在尝试创建一个百分比系统,它将 IRC 频道上的用户百分比随机播放到随机播放系统上的一组私人消息。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

错爱 2024-10-10 02:16:07

意外的 $end 表示已到达文件末尾,并且所有块 ({}) 均未关闭。是的,开括号比闭括号多;你忘记在某处关闭一个。根据缩进,我认为您打算在 if 语句之后关闭内部 while 循环:

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
}

仅通过浏览代码,我没有发现任何明显的错误该方法,但我实际上没有尝试过

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

北方。的韩爷 2024-10-10 02:16:07

你忘记了“}”
如果($ircSocket){

you forget the '}' for
if ($ircSocket) {

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文