doolo00026 2012-09-29 11:55
浏览 53
已采纳

发送私人讯息给IRC机器人

I have a php script to join a channel on this IRC server: irc.worldnet.net Thanks to the server response I can say that I joined the channel successfully, and that the bot is in the users list. However, this command:

MSG bot_nickname hello my friend !

issues an 'msg: unknown command' response. An when I send this line:

PRIVMSG bot_nickname : hello my friend !

There is no response from the bot (I don't have any error message anyway). Is there something wrong with the commands I send ?

Here is the php code that I use:

<?php

$channel_sent = false;
$channel_joined = false;
$msg_sent = false;
set_time_limit(0);
ini_set('display_errors', 'on');

$config = array(
    'server' => 'irc.worldnet.net',
    'port' => 6667,
    'nick' => 'cesame'.rand(),
    'channel' => '#nc-irc-challs'
);

$server = array();
$server['SOCKET'] = @fsockopen($config['server'], $config['port'], $errno, $errstr, 2); 

if($server['SOCKET'])
{
    SendCommand("PASS NOPASS
");
    SendCommand("NICK " . $config['nick'] . "
"); 
    SendCommand("USER " . $config['nick'] . " USING PHP IRC
");    
    SendCommand("JOIN " . $config['channel'] . "
");

    while(!feof($server['SOCKET'])) {
            ReadServer();
            flush();
            sleep(1);
    }
}

function ReadServer(){
    global $server;
    global $config;
    global $channel_joined;
    global $channel_sent;
    global $msg_sent;
    $server['READ_BUFFER'] = fgets($server['SOCKET'], 1024);
    echo "[RECEIVE] ".$server['READ_BUFFER']."<br>
";  

    if(substr($server['READ_BUFFER'], 0, 6) == "PING :") { 
        SendCommand("PONG :".substr($server['READ_BUFFER'], 6)."
"); 
    }
    if(strpos($server['READ_BUFFER'], "#nc-irc-challs :End of /NAMES list")){
        $channel_joined = true;
    }
    if(trim($server['READ_BUFFER']) == "" && $channel_joined &&!$msg_sent) {
        SendCommand('PRIVMSG Daneel : .challenge_caesar start' . "
");
        $msg_sent = true;
    }
}

function SendCommand ($cmd)
{
    global $server; //Extends our $server array to this function
    @fwrite($server['SOCKET'], $cmd, strlen($cmd)); //sends the command to the server
    echo "[SEND] $cmd <br>"; //displays it on the screen
} 

?>

So I followed you advices. This is the logs that I Get:

[RECEIVE] :cesame1582!~cesame158@Wnet-59540.41.55.213.rev.sfr.net JOIN :#nc-irc-challs 
[RECEIVE] :Vidar.IRC.Worldnet.Net 332 cesame1582 #nc-irc-challs :NewbieContest -- http://www.newbiecontest.org/ (channel officiel : #newbiecontest) -- Rappel : aucune épreuve ne peut se résoudre en bruteforce. 
[RECEIVE] :Vidar.IRC.Worldnet.Net 333 cesame1582 #nc-irc-challs zours 1195848644 
[RECEIVE] :Vidar.IRC.Worldnet.Net 353 cesame1582 = #nc-irc-challs :cesame1582 \o_ @Eole +Daneel 
[RECEIVE] :Vidar.IRC.Worldnet.Net 366 cesame1582 #nc-irc-challs :End of /NAMES list. 
[SEND] PRIVMSG Daneel : .challenge_caesar start 
[RECEIVE] :Global!Services@Worldnet.Net NOTICE cesame1582 :[Logon News - Apr 07 2004] Use irc.worldnet.net to join our network, thanks | Dorenavant, utilisez irc.worldnet.net pour joindre notre reseau, merci. 
[RECEIVE] :Global!Services@Worldnet.Net NOTICE cesame1582 :[Logon News - Jan 07 2007] If you see a connection on port 23, 1080, 3128 or 8080 from 194.117.194.78 this is NOT an attack! It's our insecure proxy detector. 
[RECEIVE] :Global!Services@Worldnet.Net NOTICE cesame1582 :[Logon News - Feb 07 2007] Vous pouvez utiliser le port 7000 pour une connexion en SSL. You can use port 7000 with a secure SSL connection. 
[RECEIVE] :Global!Services@Worldnet.Net NOTICE cesame1582 :[Logon News - Oct 14 2009] Salons officiels du reseau Worldnet : #worldnet - #help pour de l'aide sur IRC et l'informatique en general. - ##opers pour les problemes réseau spécifiques à Worldnet. 
[RECEIVE] :Global!Services@Worldnet.Net NOTICE cesame1582 :[Random News - Apr 24 2004] Pour avoir de l'aide sur les commandes des services, visitez http://help.irc.worldnet.net 
[RECEIVE] :NickServ!Services@Worldnet.Net NOTICE cesame1582 :Your nick isn't registered. 
[RECEIVE] 
[RECEIVE] PING :Vidar.IRC.Worldnet.Net 
[SEND] PONG :Vidar.IRC.Worldnet.Net 
[RECEIVE] 
[RECEIVE] PING :Vidar.IRC.Worldnet.Net 
[SEND] PONG :Vidar.IRC.Worldnet.Net 
  • 写回答

1条回答 默认 最新

  • doufangxie0203 2012-09-29 12:08
    关注

    The IRC server generally does not send empty strings.

    If you want a command to be issued once the BOT is in the channel, you should be sending it as soon as you know it's in the channel, which is at the end of the /NAMES list, or once you receive the TOPIC.


    Also, the syntax for PRIVMSG is as follows:

    PRIVMSG <NICKNAME> :<MESSAGE>
    

    Without the space after the :. If the recieving end is set to respond to .command but gets  .command, that may be the problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记