Timeout recovery should avoid getting the bot throttled now :)
authorDan
Sun, 07 Dec 2008 08:45:54 -0500
changeset 31 d75124700259
parent 30 2cfcd2801e5a
child 32 236fd4f65752
Timeout recovery should avoid getting the bot throttled now :)
enanobot.php
libirc.php
--- a/enanobot.php	Sun Dec 07 01:55:03 2008 -0500
+++ b/enanobot.php	Sun Dec 07 08:45:54 2008 -0500
@@ -175,7 +175,7 @@
     }
     $part_cache = array();
   }
-  else if ( in_array($message['nick'], $privileged_list) && preg_match('/^Shutdown(?: (.+))$/i', $message['message'], $match) && $message['action'] == 'PRIVMSG' )
+  else if ( in_array($message['nick'], $privileged_list) && preg_match('/^Shutdown(?: (.+))?$/i', $message['message'], $match) && $message['action'] == 'PRIVMSG' )
   {
     $GLOBALS['_shutdown'] = true;
     $quitmessage = empty($match[1]) ? "Remote bot shutdown ordered by {$message['nick']}" : $match[1];
@@ -195,7 +195,7 @@
 function enanobot_timeout_event($irc)
 {
   // uh-oh.
-  $irc->close();
+  $irc->close('client ping timeout (restarting connection)');
   if ( defined('LIBIRC_DEBUG') )
   {
     $now = date('r');
@@ -220,9 +220,11 @@
       if ( defined('LIBIRC_DEBUG') )
       {
         $now = date('r');
-        echo "!!! [$now] Reconnection succesful, ghosting old login\n";
+        echo "!!! [$now] Reconnection successful, ghosting old login (waiting 5 seconds to avoid throttling)\n";
       }
+      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");
       fclose($conn);
+      sleep(5);
       break;
     }
     else
--- a/libirc.php	Sun Dec 07 01:55:03 2008 -0500
+++ b/libirc.php	Sun Dec 07 08:45:54 2008 -0500
@@ -424,7 +424,7 @@
     $this->quitted = true;
     // Part all channels
     if ( !$partmsg )
-      $partmsg = 'IRC bot powered by PHP/' . PHP_VERSION . ' libirc/' . REQUEST_IRC_VERSION;
+      $partmsg = 'Closing connection (no reason given)';
     
     foreach ( $this->channels as $channel )
     {