Send a private message to an IRC bot
我有一个PHP脚本来加入这个IRC服务器上的一个频道:irc.worldnet.net由于服务器的响应,我可以说我成功地加入了频道,并且bot在用户列表中。但是,此命令:
1 | MSG bot_nickname hello my friend ! |
发出"msg:unknown command"响应。A当我发送此行时:
1 | PRIVMSG bot_nickname : hello my friend ! |
机器人程序没有响应(我也没有任何错误消息)。我发送的命令有问题吗?
下面是我使用的PHP代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | <?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']." "; 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"; //displays it on the screen } ?> |
所以我听从了你的建议。这是我得到的日志:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | [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] :[email protected] 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] :[email protected] 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] :[email protected] 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 |
IRC服务器通常不发送空字符串。
如果您希望在bot位于通道中时发出命令,则应在知道它位于通道中(位于
另外,privmsg的语法如下:
1 | PRIVMSG <NICKNAME> :<MESSAGE> |
在