comparison bridge.py @ 193:c2a8586e64b5

handle IRC inviteonlychan event, improved error messages Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sun, 21 Feb 2010 15:38:42 +0100
parents 12fa9bb73b1d
children e4ceefab8ba5
comparison
equal deleted inserted replaced
192:12fa9bb73b1d 193:c2a8586e64b5
66 self.irc_connection.connect(nick_callback=self._irc_nick_callback, charsets=self.irc_charsets) 66 self.irc_connection.connect(nick_callback=self._irc_nick_callback, charsets=self.irc_charsets)
67 67
68 self.bot.error(say_levels.notice, 'bridge "'+str(self)+'" is running in '+self.mode+' mode and a say_level of "'+str(self.say_level)+'"') 68 self.bot.error(say_levels.notice, 'bridge "'+str(self)+'" is running in '+self.mode+' mode and a say_level of "'+str(self.say_level)+'"')
69 69
70 70
71 def _join_irc_failed(self): 71 def _join_irc_failed(self, reason):
72 self.bot.error(say_levels.error, 'failed to connect to the IRC chan of bridge "'+str(self)+'", stopping bridge', send_to_admins=True) 72 self.bot.error(say_levels.error, 'failed to connect to the IRC chan of bridge '+str(self)+'\nreason: '+reason, send_to_admins=True)
73 self.stop(message='failed to connect to the IRC chan') 73 self.stop(message='Failed to connect to the IRC chan, stopping bridge', log=False)
74 74
75 75
76 def _irc_nick_callback(self, error, arguments=[]): 76 def _irc_nick_callback(self, error, arguments=[]):
77 if error == None: 77 if error == None:
78 if self.mode == None: 78 if self.mode == None:
83 if self.mode not in ['normal', 'bypass']: 83 if self.mode not in ['normal', 'bypass']:
84 self.show_participants_list_on(protocols=['irc']) 84 self.show_participants_list_on(protocols=['irc'])
85 else: 85 else:
86 self.mode = None 86 self.mode = None
87 self.say(say_levels.error, 'failed to connect to the IRC chan, leaving ...', on_irc=False) 87 self.say(say_levels.error, 'failed to connect to the IRC chan, leaving ...', on_irc=False)
88 try: 88 if error in ['nicknameinuse', 'nickcollision']:
89 if error == 'nicknameinuse': 89 reason = '"'+self.bot.nickname+'" is already used or reserved on the IRC server'
90 raise Exception('[Error] "'+self.bot.nickname+'" is already used in the IRC chan or reserved on the IRC server of bridge "'+str(self)+'"') 90 elif error == 'erroneusnickname':
91 elif error == 'nickcollision': 91 reason = '"'+self.bot.nickname+'" got "erroneusnickname"'
92 raise Exception('[Error] "'+self.bot.nickname+'" is already used or reserved on the IRC server of bridge "'+str(self)+'"') 92 elif error == 'nicknametoolong':
93 elif error == 'erroneusnickname': 93 reason = '"'+self.bot.nickname+'" got "nicknametoolong", limit seems to be '+str(arguments[0])
94 raise Exception('[Error] "'+self.bot.nickname+'" got "erroneusnickname" on bridge "'+str(self)+'"') 94 else:
95 elif error == 'nicknametoolong': 95 reason = error
96 raise Exception('[Error] "'+self.bot.nickname+'" got "nicknametoolong" on bridge "'+str(self)+'", limit seems to be '+str(arguments[0])) 96 self._join_irc_failed(reason)
97 else:
98 raise Exception('[Error] unknown error for "'+self.bot.nickname+'" on bridge "'+str(self)+'"')
99 except:
100 trace = traceback.format_exc()
101 self._join_irc_failed()
102 97
103 98
104 def _RemoteServerNotFound_handler(self): 99 def _RemoteServerNotFound_handler(self):
105 server = xmpp.protocol.JID(self.xmpp_room_jid).getDomain() 100 server = xmpp.protocol.JID(self.xmpp_room_jid).getDomain()
106 bridges = self.bot.findBridges([server]) 101 bridges = self.bot.findBridges([server])
126 except xmpp.muc.RemoteServerNotFound: 121 except xmpp.muc.RemoteServerNotFound:
127 self._RemoteServerNotFound_handler() 122 self._RemoteServerNotFound_handler()
128 except: 123 except:
129 trace = traceback.format_exc() 124 trace = traceback.format_exc()
130 self.bot.error(say_levels.error, 'failed to connect to the XMPP room of bridge "'+str(self)+'", stopping bridge\n'+trace, send_to_admins=True) 125 self.bot.error(say_levels.error, 'failed to connect to the XMPP room of bridge "'+str(self)+'", stopping bridge\n'+trace, send_to_admins=True)
131 self.stop(message='failed to connect to the XMPP room') 126 self.stop(message='Failed to connect to the XMPP room, stopping bridge')
132 127
133 128
134 def addParticipant(self, from_protocol, nickname, real_jid=None, irc_id=None): 129 def addParticipant(self, from_protocol, nickname, real_jid=None, irc_id=None):
135 """Add a participant to the bridge.""" 130 """Add a participant to the bridge."""
136 if (from_protocol == 'irc' and nickname == self.bot.nickname) or (from_protocol == 'xmpp' and nickname == self.bot.nickname): 131 if (from_protocol == 'irc' and nickname == self.bot.nickname) or (from_protocol == 'xmpp' and nickname == self.bot.nickname):
338 333
339 else: 334 else:
340 self.bot.error(1, 'Bad decision tree, p.protocol='+p.protocol+' left_protocol='+left_protocol+'\np.xmpp_c='+str(p.xmpp_c)+'\np.irc_connection='+str(p.irc_connection), debug=True) 335 self.bot.error(1, 'Bad decision tree, p.protocol='+p.protocol+' left_protocol='+left_protocol+'\np.xmpp_c='+str(p.xmpp_c)+'\np.irc_connection='+str(p.irc_connection), debug=True)
341 336
342 337
343 def restart(self): 338 def restart(self, log=True):
344 """Restart the bridge""" 339 """Restart the bridge"""
345 340
346 # Tell admins
347 self.bot.error(-1, 'Restarting bridge '+str(self), send_to_admins=True)
348
349 # Stop the bridge 341 # Stop the bridge
350 self.stop(message='Restarting bridge') 342 self.stop(message='Restarting bridge', log=log)
351 343
352 # Recreate the bridge 344 # Recreate the bridge
353 self.init2() 345 self.init2()
354 346
355 347
373 if 'xmpp' in protocols: 365 if 'xmpp' in protocols:
374 irc_participants_nicknames = self.get_participants_nicknames_list(protocols=['irc']) 366 irc_participants_nicknames = self.get_participants_nicknames_list(protocols=['irc'])
375 self.say(say_levels.info, 'Participants on IRC: '+' '.join(irc_participants_nicknames), on_irc=False) 367 self.say(say_levels.info, 'Participants on IRC: '+' '.join(irc_participants_nicknames), on_irc=False)
376 368
377 369
378 def stop(self, message='Stopping bridge'): 370 def stop(self, message='Stopping bridge', log=True):
379 """Stop the bridge""" 371 """Stop the bridge"""
380 372
381 # Close IRC connection if not used by an other bridge, just leave the room otherwise 373 # Close IRC connection if not used by an other bridge, just leave the room otherwise
382 if isinstance(self.irc_connection, ServerConnection): 374 if isinstance(self.irc_connection, ServerConnection):
383 self.irc_connection.used_by -= 1 375 self.irc_connection.used_by -= 1
395 387
396 # Delete participants objects 388 # Delete participants objects
397 for p in self.participants: 389 for p in self.participants:
398 p.leave(message) 390 p.leave(message)
399 self.participants = [] 391 self.participants = []
392
393 if log:
394 self.bot.error(-1, message+' '+str(self), send_to_admins=True)
400 395
401 396
402 def __str__(self): 397 def __str__(self):
403 return self.irc_room+'@'+self.irc_server+' <-> '+self.xmpp_room_jid 398 return self.irc_room+'@'+self.irc_server+' <-> '+self.xmpp_room_jid
404 399