enanobot.php
changeset 31 d75124700259
parent 30 2cfcd2801e5a
child 38 e6a4b7f91e91
equal deleted inserted replaced
30:2cfcd2801e5a 31:d75124700259
   173       $GLOBALS[$chan_name]->msg("Bot resumed by {$message['nick']}.", true);
   173       $GLOBALS[$chan_name]->msg("Bot resumed by {$message['nick']}.", true);
   174       $irc->privmsg('ChanServ', "OP {$chan_data[0]} $nick");
   174       $irc->privmsg('ChanServ', "OP {$chan_data[0]} $nick");
   175     }
   175     }
   176     $part_cache = array();
   176     $part_cache = array();
   177   }
   177   }
   178   else if ( in_array($message['nick'], $privileged_list) && preg_match('/^Shutdown(?: (.+))$/i', $message['message'], $match) && $message['action'] == 'PRIVMSG' )
   178   else if ( in_array($message['nick'], $privileged_list) && preg_match('/^Shutdown(?: (.+))?$/i', $message['message'], $match) && $message['action'] == 'PRIVMSG' )
   179   {
   179   {
   180     $GLOBALS['_shutdown'] = true;
   180     $GLOBALS['_shutdown'] = true;
   181     $quitmessage = empty($match[1]) ? "Remote bot shutdown ordered by {$message['nick']}" : $match[1];
   181     $quitmessage = empty($match[1]) ? "Remote bot shutdown ordered by {$message['nick']}" : $match[1];
   182     $irc->close($quitmessage, true);
   182     $irc->close($quitmessage, true);
   183     return 'BREAK';
   183     return 'BREAK';
   193 }
   193 }
   194 
   194 
   195 function enanobot_timeout_event($irc)
   195 function enanobot_timeout_event($irc)
   196 {
   196 {
   197   // uh-oh.
   197   // uh-oh.
   198   $irc->close();
   198   $irc->close('client ping timeout (restarting connection)');
   199   if ( defined('LIBIRC_DEBUG') )
   199   if ( defined('LIBIRC_DEBUG') )
   200   {
   200   {
   201     $now = date('r');
   201     $now = date('r');
   202     echo "!!! [$now] Connection timed out; waiting 10 seconds and reconnecting\n";
   202     echo "!!! [$now] Connection timed out; waiting 10 seconds and reconnecting\n";
   203   }
   203   }
   218     if ( $conn )
   218     if ( $conn )
   219     {
   219     {
   220       if ( defined('LIBIRC_DEBUG') )
   220       if ( defined('LIBIRC_DEBUG') )
   221       {
   221       {
   222         $now = date('r');
   222         $now = date('r');
   223         echo "!!! [$now] Reconnection succesful, ghosting old login\n";
   223         echo "!!! [$now] Reconnection successful, ghosting old login (waiting 5 seconds to avoid throttling)\n";
   224       }
   224       }
       
   225       fputs($conn, "QUIT :This bot needs better exception handling. But until then I'm going to need to make repeated TCP connection attempts when my ISP craps out. Sorry :-/\r\n");
   225       fclose($conn);
   226       fclose($conn);
       
   227       sleep(5);
   226       break;
   228       break;
   227     }
   229     }
   228     else
   230     else
   229     {
   231     {
   230       if ( defined('LIBIRC_DEBUG') )
   232       if ( defined('LIBIRC_DEBUG') )