Mercurial > xib
changeset 132:6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Fri, 15 Jan 2010 17:04:45 +0100 |
parents | 46af7f2744a9 |
children | e662ff6ecf50 |
files | bridge.py participant.py |
diffstat | 2 files changed, 37 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/bridge.py +++ b/bridge.py @@ -178,33 +178,40 @@ class Bridge: return p + def createDuplicatesOn(self, protocols): + for p in self.participants: + if p.protocol == 'xmpp' and 'irc' in protocols: + p.createDuplicateOnIRC() + elif p.protocol == 'irc' and 'xmpp' in protocols: + p.createDuplicateOnXMPP() + + def changeMode(self, new_mode): if new_mode == self.mode: return 'Mode is already equal to '+self.mode - unhandled = 'Error: unhandled mode changing from '+self.mode+' to '+new_mode + old_mode = self.mode + self.mode = new_mode + + unhandled = False if new_mode in ['normal', 'bypass']: - if self.mode[-7:] == 'limited': + if old_mode[-7:] == 'limited': # From [{normal,bypass}-]limited to {normal,bypass} - pass # duplicates of XMPP users are created below + self.createDuplicatesOn(['irc']) - elif self.mode == 'minimal': - # From minimal to {normal,bypass} - # create duplicates of IRC users, duplicates of XMPP users are created below - for p in self.participants: - if p.protocol == 'irc': - p.createDuplicateOnXMPP() + elif old_mode in ['minimal', 'normal']: + # From {minimal,normal} to {normal,bypass} + self.createDuplicatesOn(['irc', 'xmpp']) + + elif old_mode == 'bypass': + # From bypass to normal + pass # Handled below else: # Unhandled mode changing - return unhandled - - # create duplicates of XMPP users - for p in self.participants: - if p.protocol == 'xmpp': - p.createDuplicateOnIRC() + unhandled = True elif new_mode[-7:] == 'limited': @@ -225,15 +232,24 @@ class Bridge: elif new_mode == 'minimal': for p in self.participants: - p.leave('Bridge is switching to limited mode') + p.leave('Bridge is switching to minimal mode') else: # Unhandled mode changing - return unhandled + unhandled = True + + if unhandled: + self.mode = old_mode + return 'Error: unhandled mode changing from '+self.mode+' to '+new_mode - self.mode = new_mode - self.bot.error('===> Bridge is switching from '+self.mode+' to '+new_mode+' mode.') - self.say('[Notice] Bridge is switching from '+self.mode+' to '+new_mode+' mode.') + if old_mode == 'bypass': + # From bypass to * + for p in self.participants: + if p.nickname != p.duplicate_nickname: + p.leave('Bridge is switching to '+new_mode+' mode') + + self.bot.error('===> Bridge is switching from '+old_mode+' to '+new_mode+' mode.') + self.say('[Notice] Bridge is switching from '+old_mode+' to '+new_mode+' mode.') def getParticipant(self, nickname):