comparison bridge.py @ 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 922858915907
comparison
equal deleted inserted replaced
131:46af7f2744a9 132:6a6885dbed25
176 irc_participants_nicknames = self.get_participants_nicknames_list(protocols=['irc']) 176 irc_participants_nicknames = self.get_participants_nicknames_list(protocols=['irc'])
177 self.say('[Info] Participants on IRC: '+' '.join(irc_participants_nicknames), on_irc=False) 177 self.say('[Info] Participants on IRC: '+' '.join(irc_participants_nicknames), on_irc=False)
178 return p 178 return p
179 179
180 180
181 def createDuplicatesOn(self, protocols):
182 for p in self.participants:
183 if p.protocol == 'xmpp' and 'irc' in protocols:
184 p.createDuplicateOnIRC()
185 elif p.protocol == 'irc' and 'xmpp' in protocols:
186 p.createDuplicateOnXMPP()
187
188
181 def changeMode(self, new_mode): 189 def changeMode(self, new_mode):
182 if new_mode == self.mode: 190 if new_mode == self.mode:
183 return 'Mode is already equal to '+self.mode 191 return 'Mode is already equal to '+self.mode
184 192
185 unhandled = 'Error: unhandled mode changing from '+self.mode+' to '+new_mode 193 old_mode = self.mode
194 self.mode = new_mode
195
196 unhandled = False
186 197
187 if new_mode in ['normal', 'bypass']: 198 if new_mode in ['normal', 'bypass']:
188 199
189 if self.mode[-7:] == 'limited': 200 if old_mode[-7:] == 'limited':
190 # From [{normal,bypass}-]limited to {normal,bypass} 201 # From [{normal,bypass}-]limited to {normal,bypass}
191 pass # duplicates of XMPP users are created below 202 self.createDuplicatesOn(['irc'])
192 203
193 elif self.mode == 'minimal': 204 elif old_mode in ['minimal', 'normal']:
194 # From minimal to {normal,bypass} 205 # From {minimal,normal} to {normal,bypass}
195 # create duplicates of IRC users, duplicates of XMPP users are created below 206 self.createDuplicatesOn(['irc', 'xmpp'])
196 for p in self.participants: 207
197 if p.protocol == 'irc': 208 elif old_mode == 'bypass':
198 p.createDuplicateOnXMPP() 209 # From bypass to normal
210 pass # Handled below
199 211
200 else: 212 else:
201 # Unhandled mode changing 213 # Unhandled mode changing
202 return unhandled 214 unhandled = True
203
204 # create duplicates of XMPP users
205 for p in self.participants:
206 if p.protocol == 'xmpp':
207 p.createDuplicateOnIRC()
208 215
209 elif new_mode[-7:] == 'limited': 216 elif new_mode[-7:] == 'limited':
210 217
211 i = 0 218 i = 0
212 for p in self.participants: 219 for p in self.participants:
223 self.say('[Info] Participants on XMPP: '+' '.join(xmpp_participants_nicknames), on_xmpp=False) 230 self.say('[Info] Participants on XMPP: '+' '.join(xmpp_participants_nicknames), on_xmpp=False)
224 return 231 return
225 232
226 elif new_mode == 'minimal': 233 elif new_mode == 'minimal':
227 for p in self.participants: 234 for p in self.participants:
228 p.leave('Bridge is switching to limited mode') 235 p.leave('Bridge is switching to minimal mode')
229 236
230 else: 237 else:
231 # Unhandled mode changing 238 # Unhandled mode changing
232 return unhandled 239 unhandled = True
233 240
234 self.mode = new_mode 241 if unhandled:
235 self.bot.error('===> Bridge is switching from '+self.mode+' to '+new_mode+' mode.') 242 self.mode = old_mode
236 self.say('[Notice] Bridge is switching from '+self.mode+' to '+new_mode+' mode.') 243 return 'Error: unhandled mode changing from '+self.mode+' to '+new_mode
244
245 if old_mode == 'bypass':
246 # From bypass to *
247 for p in self.participants:
248 if p.nickname != p.duplicate_nickname:
249 p.leave('Bridge is switching to '+new_mode+' mode')
250
251 self.bot.error('===> Bridge is switching from '+old_mode+' to '+new_mode+' mode.')
252 self.say('[Notice] Bridge is switching from '+old_mode+' to '+new_mode+' mode.')
237 253
238 254
239 def getParticipant(self, nickname): 255 def getParticipant(self, nickname):
240 """Returns a participant object if there is a participant using nickname in the bridge. Raises a NoSuchParticipantException otherwise.""" 256 """Returns a participant object if there is a participant using nickname in the bridge. Raises a NoSuchParticipantException otherwise."""
241 self.lock.acquire() 257 self.lock.acquire()