From: <da...@us...> - 2003-08-06 14:09:58
|
Update of /cvsroot/binaryphp/binaryphp/examples In directory sc8-pr-cvs1:/tmp/cvs-serv27671/examples Modified Files: irc.php Log Message: Fixed irc bot, php_var.cpp, substr()... Index: irc.php =================================================================== RCS file: /cvsroot/binaryphp/binaryphp/examples/irc.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** irc.php 5 Aug 2003 05:58:00 -0000 1.2 --- irc.php 6 Aug 2003 14:09:55 -0000 1.3 *************** *** 1,26 **** <?php ! $sock = socket_create(AF_INET, SOCK_STREAM, 0); ! $connection = socket_connect($sock, 'irc.freenode.net', 6667); ! socket_write($sock, "USER TestBOT TestBOT TestBOT :TestBOT\r\n"); ! socket_write($sock, "NICK TestBOT \r\n"); ! socket_write($sock,"JOIN #binaryphp \r\n"); ! while ($data = socket_read($sock, 2046)) ! { ! echo $data, "\n"; ! $temp = explode(':', $data); ! $temp2 = explode('!', $temp[1]); ! $temp3 = explode(' ', $temp2[1]); ! $admin = 'Amaranth'; ! $args = explode(' ,', $temp2[2]); ! if($args[0][0] == '!') { ! $text = substr($args[0], 1, 4); ! if($text == 'ping') ! socket_write($sock, 'PRIVMSG ' . $temp3[2] . ' :' . $temp2[0] . ": PONG!\r\n"); ! ! elseif($text == 'quit' && $temp[0] == $admin)) ! socket_write($sock, 'QUIT :Seeya ' $temp3[2] . "\r\n"); } - } ?> --- 1,24 ---- <?php ! $sock = socket_create(AF_INET, SOCK_STREAM, 0); ! $connection = socket_connect($sock, 'irc.freenode.net', 6667); ! socket_write($sock, "USER TestBOT TestBOT TestBOT :TestBOT\r\n"); ! socket_write($sock, "NICK TestBOT \r\n"); ! socket_write($sock,"JOIN #binaryphp \r\n"); ! while ($data = socket_read($sock, 2048)) { ! $temp = explode(':', $data); ! $temp2 = explode('!', $temp[1]); ! $temp3 = explode(' ', $temp2[1], 4); ! $nick = $temp2[0]; ! $act = $temp3[1]; ! $recp = $temp3[2]; ! if($act == 'PRIVMSG') ! { ! echo '<', $nick, '> ', trim($temp[2]), "\n"; ! $bleh = explode(' ', trim($temp[2])); ! if($bleh[0] == '+punch') ! socket_write($sock, 'PRIVMSG ' . $recp . ' :' . "\x01" . 'ACTION punches ' . $bleh[1] . ' in the face.' . "\x01\r\n"); ! } } ?> |