All pastes #1819622 Raw Edit

Anonymous

public text v1 · immutable
#1819622 ·published 2010-03-02 18:06 UTC
rendered paste body
--- erepbot.py.orig     2010-03-02 18:05:10.110958135 +0100                                 
+++ erepbot.py  2010-03-02 18:07:53.216208404 +0100                                         
@@ -36,6 +36,8 @@                                                                           
 from urllib2 import urlopen                                                                
                                                                                            
 class ERepBot(SingleServerIRCBot):                                                         
+    stop = False                                                                           
+                                                                                           
     def __init__(self, db, channels, nickname, server, port=6667):                         
         SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)            
         self.initial_channels = channels                                                   
@@ -116,6 +118,7 @@                                                                         
         if cmd == "disconnect" and nick.lower().startswith('hostilian'):
             self.disconnect()
         elif cmd == "die" and nick.lower() in [ 'hostilian', 'gojko_bozic', ]:
+            self.stop = True
             self.die()
         elif cmd == 'stfu' and nick.lower().startswith('hostilian') and is_channel(t):
             if not t in self.stfu_channels:
@@ -500,10 +503,12 @@

     db = shelve.open('vukovi.db')
     bot = ERepBot(db, channels, nickname, server, port)
-    try:
-        bot.start()
-    finally:
-        db.close()
+    while not bot.stop:
+        try:
+            bot.start()
+        except:
+            print '%s: Exception occured, restarting bot'
+    db.close()

 if __name__ == "__main__":
     main()