Mercurial > xib
comparison bridge.py @ 226:0d85049ac68d
switch to IRC join callbacks in bridge.py and participant.py
Signed-off-by: Charly COSTE <changaco@changaco.net>
| author | Charly COSTE <changaco@changaco.net> |
|---|---|
| date | Sun, 07 Mar 2010 18:52:48 +0100 |
| parents | 1a82d5d40d90 |
| children | 5f1e9211af03 |
comparison
equal
deleted
inserted
replaced
| 225:da8fbaf69242 | 226:0d85049ac68d |
|---|---|
| 74 self.bot.error(say_levels.error, 'failed to connect to the IRC chan of bridge '+str(self)+'\nreason: '+reason, send_to_admins=True) | 74 self.bot.error(say_levels.error, 'failed to connect to the IRC chan of bridge '+str(self)+'\nreason: '+reason, send_to_admins=True) |
| 75 self.stop(message='Failed to connect to the IRC chan, stopping bridge', log=False) | 75 self.stop(message='Failed to connect to the IRC chan, stopping bridge', log=False) |
| 76 | 76 |
| 77 | 77 |
| 78 def _irc_nick_callback(self, error): | 78 def _irc_nick_callback(self, error): |
| 79 if error == None: | 79 if not error: |
| 80 if self.mode == None: | 80 if not self.mode: |
| 81 return | 81 return |
| 82 self.irc_connection.join(self.irc_room) | 82 self.irc_connection.join(self.irc_room, callback=self._irc_join_callback) |
| 83 self.bot.error(3, 'successfully connected on IRC side of bridge "'+str(self)+'"', debug=True) | 83 |
| 84 self.say(say_levels.notice, 'bridge "'+str(self)+'" is running in '+self.mode+' mode', on_xmpp=False) | |
| 85 if self.mode not in ['normal', 'bypass']: | |
| 86 self.show_participants_list_on(protocols=['irc']) | |
| 87 else: | 84 else: |
| 88 self.mode = None | 85 self.mode = None |
| 89 self.say(say_levels.error, 'failed to connect to the IRC chan, leaving ...', on_irc=False) | 86 self.say(say_levels.error, 'failed to connect to the IRC chan, leaving ...', on_irc=False) |
| 90 if error in ['nicknameinuse', 'nickcollision']: | 87 if error in ['nicknameinuse', 'nickcollision']: |
| 91 reason = '"'+self.bot.nickname+'" is already used or reserved on the IRC server' | 88 reason = '"'+self.bot.nickname+'" is already used or reserved on the IRC server' |
| 96 else: | 93 else: |
| 97 reason = error | 94 reason = error |
| 98 self._join_irc_failed(reason) | 95 self._join_irc_failed(reason) |
| 99 | 96 |
| 100 | 97 |
| 98 def _irc_join_callback(self, channel, error): | |
| 99 if not error: | |
| 100 self.bot.error(3, 'successfully joined IRC side of bridge "'+str(self)+'"', debug=True) | |
| 101 self.say(say_levels.notice, 'bridge "'+str(self)+'" is running in '+self.mode+' mode', on_xmpp=False) | |
| 102 if self.mode not in ['normal', 'bypass']: | |
| 103 self.show_participants_list_on(protocols=['irc']) | |
| 104 | |
| 105 else: | |
| 106 self._join_irc_failed(error) | |
| 107 | |
| 108 | |
| 101 def _RemoteServerNotFound_handler(self): | 109 def _RemoteServerNotFound_handler(self): |
| 102 server = xmpp.protocol.JID(self.xmpp_room_jid).getDomain() | 110 server = xmpp.protocol.JID(self.xmpp_room_jid).getDomain() |
| 103 bridges = self.bot.iter_bridges(patterns=[server]) | 111 bridges = self.bot.iter_bridges(patterns=[server]) |
| 104 error = [say_levels.warning, 'The MUC server '+server+' seems to be down, the bot will try to recreate all bridges related to this server in 5 minutes'] | 112 error = [say_levels.warning, 'The MUC server '+server+' seems to be down, the bot will try to recreate all bridges related to this server in 5 minutes'] |
| 105 self.bot.restart_bridges_delayed(bridges, 300, error) | 113 self.bot.restart_bridges_delayed(bridges, 300, error) |
| 128 | 136 |
| 129 | 137 |
| 130 def add_participant(self, from_protocol, nickname, real_jid=None): | 138 def add_participant(self, from_protocol, nickname, real_jid=None): |
| 131 """Add a participant to the bridge.""" | 139 """Add a participant to the bridge.""" |
| 132 if (from_protocol == 'irc' and nickname == self.bot.nickname) or (from_protocol == 'xmpp' and nickname == self.bot.nickname): | 140 if (from_protocol == 'irc' and nickname == self.bot.nickname) or (from_protocol == 'xmpp' and nickname == self.bot.nickname): |
| 133 self.bot.error(3, 'not adding self ('+self.bot.nickname+') to bridge "'+str(self)+'"', debug=True) | |
| 134 return | 141 return |
| 135 try: | 142 try: |
| 136 p = self.get_participant(nickname) | 143 p = self.get_participant(nickname) |
| 137 if p.protocol != from_protocol: | 144 if p.protocol != from_protocol: |
| 138 if from_protocol == 'irc' and isinstance(p.irc_connection, ServerConnection) and p.irc_connection.logged_in and p.irc_connection.real_nickname == nickname or from_protocol == 'xmpp' and isinstance(p.xmpp_c, xmpp.client.Client) and isinstance(p.muc, xmpp.muc) and p.xmpp_c.nickname == nickname: | 145 if from_protocol == 'irc' and isinstance(p.irc_connection, ServerConnection) and p.irc_connection.logged_in and p.irc_connection.real_nickname == nickname or from_protocol == 'xmpp' and isinstance(p.xmpp_c, xmpp.client.Client) and isinstance(p.muc, xmpp.muc) and p.xmpp_c.nickname == nickname: |
