PHP - IRC 私信功能帮助

发布于 2024-10-03 09:47:47 字数 1479 浏览 8 评论 0原文

由于某种原因,我的机器人不会向 IRC 频道上的 % 的人发送私信。这是我的脚本:

<?php

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

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

这是我收到的日志:

:[email protected] PRIVMSG Rawr30566 :VERSION

我什至尝试删除帖子数据并将这部分替换为:

$msg = $_POST['message'];

随着

$msg = hello;

频道上的其他人没有收到私人消息。

For some reason my bot wont private message a % of people on the IRC Channel. Here is my script:

<?php

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

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

Here is the log on what I recieve:

:[email protected] PRIVMSG Rawr30566 :VERSION

I have even tried removing the Post data and replaced this part with this:

$msg = $_POST['message'];

With

$msg = hello;

The other people on the channel does not get a private message.

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

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

发布评论

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

评论(1

小兔几 2024-10-10 09:47:47

这是你的整个剧本吗? $users 未设置任何内容;您可能想将其设置为用户名数组。 $round 也未设置;您可能只想调用内置的 round() 函数。如果您在 for 循环中添加调试行,您至少可以知道哪些用户(如果有)应该接收消息:

for ($i = 0; $i <= $target; $i++) {
    echo "Sending message to ${users[$i]}\n";
    fwrite($ircSocket, "PRIVMSG " . $users[$i] . " :" . $msg . "\n");
}

IRC 协议内容看起来是正确的。您担心的接收日志与此无关; IRC 服务器上的 StatServ 正在向您的机器人发送 CTCP VERSION 请求。通常,客户端会响应其名称和版本,StatServ 可能会将其记录下来,以便操作员可以查看网络上常见的客户端

Is this your entire script? $users isn't set to anything; you probably meant to set it to an array of usernames. $round also isn't set; you probably meant to just call the built-in round() function. If you add a debugging line in the for loop you can at least tell which users (if any) should be getting messages:

for ($i = 0; $i <= $target; $i++) {
    echo "Sending message to ${users[$i]}\n";
    fwrite($ircSocket, "PRIVMSG " . $users[$i] . " :" . $msg . "\n");
}

The IRC protocol stuff looks right. The receive log you were worried about doesn't have anything to do with it; StatServ on the IRC server is sending your bot a CTCP VERSION request. Normally clients respond with their name and version, and StatServ probably logs it so opers can see what clients are common on the network

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