comparison irclib.py @ 180:102f895347ff

added a required "importance" argument to Bot.error() Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sat, 13 Feb 2010 16:32:28 +0100
parents c158ad24ef3c
children 4011838e098e
comparison
equal deleted inserted replaced
179:f6c6708c6c0e 180:102f895347ff
71 import types 71 import types
72 import threading 72 import threading
73 import traceback 73 import traceback
74 import math 74 import math
75 75
76 import say_levels
77
76 VERSION = 0, 4, 8 78 VERSION = 0, 4, 8
77 DEBUG = 0 79 DEBUG = 0
78 80
79 # TODO 81 # TODO
80 # ---- 82 # ----
174 stack = self.connection_stacks[server_str] 176 stack = self.connection_stacks[server_str]
175 if len(stack) > 0: 177 if len(stack) > 0:
176 stack[0][0](*stack[0][1]) 178 stack[0][0](*stack[0][1])
177 stack.pop(0) 179 stack.pop(0)
178 delay = self.connection_interval(server=server_str) 180 delay = self.connection_interval(server=server_str)
179 self.bot.error('==> Debug: waiting '+str(delay)+' seconds before next connection on '+server_str, debug=True) 181 self.bot.error(2, 'waiting '+str(delay)+' seconds before next connection on '+server_str, debug=True)
180 self.execute_delayed(delay, self._connection_loop, (server_str,)) 182 self.execute_delayed(delay, self._connection_loop, (server_str,))
181 else: 183 else:
182 self.connection_stacks.pop(server_str) 184 self.connection_stacks.pop(server_str)
183 185
184 186
291 try: 293 try:
292 self.process_once(timeout) 294 self.process_once(timeout)
293 except ServerNotConnectedError: 295 except ServerNotConnectedError:
294 self.bot.restart() 296 self.bot.restart()
295 except: 297 except:
296 self.bot.error('[Error] Unkonwn exception on IRC thread:\n'+traceback.format_exc(), send_to_admins=True) 298 self.bot.error(say_levels.error, 'Unkonwn exception on IRC thread:\n'+traceback.format_exc(), send_to_admins=True)
297 299
298 def disconnect_all(self, message="", volontary=True): 300 def disconnect_all(self, message="", volontary=True):
299 """Disconnects all connections.""" 301 """Disconnects all connections."""
300 for c in self.connections: 302 for c in self.connections:
301 c.disconnect(message, volontary=volontary) 303 c.disconnect(message, volontary=volontary)
471 473
472 def _ping(self): 474 def _ping(self):
473 self.irclibobj.execute_delayed(60, self._ping) 475 self.irclibobj.execute_delayed(60, self._ping)
474 if self.connected == False: 476 if self.connected == False:
475 return 477 return
476 self.irclibobj.bot.error('=> Debug: sending IRC ping', debug=True) 478 self.irclibobj.bot.error(1, 'sending IRC ping', debug=True)
477 self.ping(self.get_server_name()) 479 self.ping(self.get_server_name())
478 480
479 481
480 def _server_str(self): 482 def _server_str(self):
481 return self.server+':'+str(self.port) 483 return self.server+':'+str(self.port)
511 if nick_callback: 513 if nick_callback:
512 self.add_nick_callback(nick_callback) 514 self.add_nick_callback(nick_callback)
513 515
514 if self.used_by > 0: 516 if self.used_by > 0:
515 self.used_by += 1 517 self.used_by += 1
516 self.irclibobj.bot.error('===> Debug: using existing IRC connection for '+self.__str__()+', this connection is now used by '+str(self.used_by)+' bridges', debug=True) 518 self.irclibobj.bot.error(3, 'using existing IRC connection for '+self.__str__()+', this connection is now used by '+str(self.used_by)+' bridges', debug=True)
517 if self.really_connected: 519 if self.really_connected:
518 self._call_nick_callbacks(None) 520 self._call_nick_callbacks(None)
519 self.lock.release() 521 self.lock.release()
520 return self 522 return self
521 523
548 self._ping() 550 self._ping()
549 551
550 self.lock.acquire() 552 self.lock.acquire()
551 553
552 if self.socket != 'closed': 554 if self.socket != 'closed':
553 self.irclibobj.bot.error('===> Debug: opening new IRC connection for '+self.__str__(), debug=True) 555 self.irclibobj.bot.error(3, 'opening new IRC connection for '+self.__str__(), debug=True)
554 else: 556 else:
555 self.irclibobj.bot.error('===> Debug: reopening IRC connection for '+self.__str__(), debug=True) 557 self.irclibobj.bot.error(3, 'reopening IRC connection for '+self.__str__(), debug=True)
556 558
557 if self.ipv6: 559 if self.ipv6:
558 self.socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) 560 self.socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
559 else: 561 else:
560 self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 562 self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
586 for f in self.nick_callbacks: 588 for f in self.nick_callbacks:
587 i += 1 589 i += 1
588 f(error, arguments=arguments) 590 f(error, arguments=arguments)
589 self.nick_callbacks = [] 591 self.nick_callbacks = []
590 if i == 0: 592 if i == 0:
591 self.irclibobj.bot.error('=> Debug: no nick callback for "'+self.__str__()+'"', debug=True) 593 self.irclibobj.bot.error(1, 'no nick callback for "'+self.__str__()+'"', debug=True)
592 else: 594 else:
593 self.irclibobj.bot.error('=> Debug: called '+str(i)+' callback(s) for "'+self.__str__()+'"', debug=True) 595 self.irclibobj.bot.error(1, 'called '+str(i)+' callback(s) for "'+self.__str__()+'"', debug=True)
594 596
595 597
596 def add_nick_callback(self, callback): 598 def add_nick_callback(self, callback):
597 self.nick_callbacks.append(callback) 599 self.nick_callbacks.append(callback)
598 600