# HG changeset patch # User Dan # Date 1230787114 18000 # Node ID 1855846cbdabef7febed8d35b80de0793e6e1adb # Parent 4027a5b47db5ba164c30e2d22738f0e19fca6cc3 Added CTCP support and an associated module diff -r 4027a5b47db5 -r 1855846cbdab enanobot.php --- a/enanobot.php Wed Dec 31 21:54:19 2008 -0500 +++ b/enanobot.php Thu Jan 01 00:18:34 2009 -0500 @@ -76,6 +76,8 @@ require('config.php'); require('database.php'); +$enanobot_version = '0.5-unstable'; + @ini_set('display_errors', 'on'); error_reporting(E_ALL); @@ -182,6 +184,20 @@ $irc->close($quitmessage, true); return 'BREAK'; } + else if ( in_array($message['nick'], $privileged_list) && preg_match('/^re(?:hash|load)?(?:config)?(?: |$)/', $message['message']) ) + { + require('config.php'); + $GLOBALS['privileged_list'] = $privileged_list; + $GLOBALS['alert_list'] = $alert_list; + $irc->privmsg($message['nick'], "Reloaded privileged_list and alert_list. privileged = " . str_replace("\n", '', print_r($privileged_list, true)) . "; alert = " . str_replace("\n", '', print_r($alert_list, true))); + } + else if ( substr($message['message'], 0, 1) == "\x01" && substr($message['message'], -1) == "\x01" ) + { + $msg = trim($message['message'], "\x01"); + list($ctcp) = explode(' ', $msg); + $params = substr($msg, strlen($ctcp)+1); + eval(eb_fetch_hook('event_ctcp')); + } else if ( $message['action'] == 'PRIVMSG' ) { eval(eb_fetch_hook('event_privmsg')); diff -r 4027a5b47db5 -r 1855846cbdab libirc.php --- a/libirc.php Wed Dec 31 21:54:19 2008 -0500 +++ b/libirc.php Thu Jan 01 00:18:34 2009 -0500 @@ -239,6 +239,23 @@ } /** + * Sends a notice. + * @param string Nick or channel + * @param string Message + */ + + public function notice($nick, $message) + { + $message = str_replace("\r\n", "\n", $message); + $message = explode("\n", $message); + foreach ( $message as $line ) + { + $line = $this->filter_message($line); + $this->put("NOTICE $nick :$line\r\n"); + } + } + + /** * Parse bold (...) tags and color tags in a text into IRC speak, and process /me commands. Colors are ..., specify background with .... Valid colors are white, black, navy, green, red, maroon, purple, orange, yellow, lime, teal, aqua, cyan, blue, pink, grey, and silver * @param string Text to filter * @return string diff -r 4027a5b47db5 -r 1855846cbdab modules/ctcp.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/ctcp.php Thu Jan 01 00:18:34 2009 -0500 @@ -0,0 +1,27 @@ +notice($message['nick'], "\x01PING $params\x01"); + break; + case 'VERSION': + global $nick, $enanobot_version; + $irc->notice($message['nick'], "\x01VERSION $nick-$enanobot_version on PHP/" . PHP_VERSION . " (" . PHP_OS . ")\x01"); + break; + default: + eval(eb_fetch_hook('event_custom_ctcp')); + break; + } + $now = date('r'); + foreach ( $alert_list as $alertme ) + { + $irc->privmsg($alertme, "Received CTCP \"$ctcp\" from {$message['nick']}, " . $now); + } +} diff -r 4027a5b47db5 -r 1855846cbdab modules/echo.php --- a/modules/echo.php Wed Dec 31 21:54:19 2008 -0500 +++ b/modules/echo.php Thu Jan 01 00:18:34 2009 -0500 @@ -17,16 +17,16 @@ { global $privileged_list; - if ( in_array($message['nick'], $privileged_list) && preg_match("/^\!echo-([^\007, \r\n\a\t]+) /", $message['message'], $match) ) + if ( in_array($message['nick'], $privileged_list) && preg_match("/^(?:\!echo-|\/msg )([^\007, \r\n\a\t]+) /", $message['message'], $match) ) { global $libirc_channels; $channel_name =& $match[1]; if ( isset($libirc_channels[$channel_name]) && is_object($libirc_channels[$channel_name]) ) { - $libirc_channels[$channel_name]->msg(eb_censor_words(preg_replace("/^\!echo-([^\007, \r\n\a\t]+) /", '', $message['message'])), true); + $libirc_channels[$channel_name]->msg(eb_censor_words(preg_replace("/^(?:\!echo-|\/msg )((?:#|&)[^\007, \r\n\a\t]+) /", '', $message['message'])), true); } } - else if ( in_array($message['nick'], $privileged_list) && preg_match("/^\!pm ([^\007, \r\n\a\t]+) (.+)/", $message['message'], $match) ) + else if ( in_array($message['nick'], $privileged_list) && preg_match("/^(?:\!pm|\/msg) ([^\007, \r\n\a\t]+) (.+)/", $message['message'], $match) ) { global $irc; $irc->privmsg($match[1], eb_censor_words($match[2]));