function react_to_ping($socket, $input) { $parts = explode(' ', $input); irc_send($socket, 'PONG ' . $parts[1]); }
{ $scan = glob('modules/*'); foreach ($scan as $path) { if (preg_match('/\\.php$/', $path)) { require_once $path; } } } function register_callback($callback) { array_push($GLOBALS['callbacks'], $callback); } require_modules(); $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $success = socket_connect($socket, HOST, PORT); irc_send($socket, 'NICK ' . NICKNAME); irc_send($socket, 'USER ' . NICKNAME . ' 0 * :' . NICKNAME); do { $input = socket_read($socket, 2048, PHP_NORMAL_READ); if ($input === false) { break; } echo 'input: ', $input; if (!$joined && string_contains($input, 'MODE')) { irc_send($socket, 'JOIN ' . CHANNEL); } else { foreach ($callbacks as $callback) { $callback($socket, $input); } } } while (true);
<?php register_callback(function ($socket, $input) { if (message_part($input) === ':.sadness') { irc_send($socket, 'PRIVMSG ' . CHANNEL . ' http://phpsadness.com/sad/' . rand(1, 52)); } });