comparison participant.py @ 203:2a81c480439a

renamed camelCased functions Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Thu, 25 Feb 2010 23:29:39 +0100
parents 740effa74c18
children fbe40b397f67
comparison
equal deleted inserted replaced
202:2a1ee46f86af 203:2a81c480439a
37 self.irc_connection = None 37 self.irc_connection = None
38 self.xmpp_c = None 38 self.xmpp_c = None
39 self.muc = None 39 self.muc = None
40 self.left = False 40 self.left = False
41 if protocol == 'xmpp' and self.bridge.mode in ['normal', 'bypass']: 41 if protocol == 'xmpp' and self.bridge.mode in ['normal', 'bypass']:
42 self.createDuplicateOnIRC() 42 self.create_duplicate_on_irc()
43 elif protocol == 'irc' and self.bridge.mode != 'minimal': 43 elif protocol == 'irc' and self.bridge.mode != 'minimal':
44 self.createDuplicateOnXMPP() 44 self.create_duplicate_on_xmpp()
45 45
46 46
47 def _get_new_duplicate_nickname(self): 47 def _get_new_duplicate_nickname(self):
48 new_duplicate_nickname = self.duplicate_nickname 48 new_duplicate_nickname = self.duplicate_nickname
49 for i in xrange(5): 49 for i in xrange(5):
50 new_duplicate_nickname = new_duplicate_nickname+'_' 50 new_duplicate_nickname = new_duplicate_nickname+'_'
51 if not self.bridge.hasParticipant(new_duplicate_nickname): 51 if not self.bridge.has_participant(new_duplicate_nickname):
52 return new_duplicate_nickname 52 return new_duplicate_nickname
53 return None 53 return None
54 54
55 55
56 def createDuplicateOnXMPP(self): 56 def create_duplicate_on_xmpp(self):
57 if isinstance(self.xmpp_c, xmpp.client.Client) or isinstance(self.irc_connection, ServerConnection): 57 if isinstance(self.xmpp_c, xmpp.client.Client) or isinstance(self.irc_connection, ServerConnection):
58 return 58 return
59 self.xmpp_c = self.bridge.bot.get_xmpp_connection(self.duplicate_nickname) 59 self.xmpp_c = self.bridge.bot.get_xmpp_connection(self.duplicate_nickname)
60 self.muc = xmpp.muc(self.bridge.xmpp_room_jid) 60 self.muc = xmpp.muc(self.bridge.xmpp_room_jid)
61 self.join_muc() 61 self.join_muc()
88 self.bridge.say(say_levels.info, 'The nickname "'+self.duplicate_nickname+'" is used on both rooms or reserved on the XMPP server') 88 self.bridge.say(say_levels.info, 'The nickname "'+self.duplicate_nickname+'" is used on both rooms or reserved on the XMPP server')
89 self.duplicate_nickname = new_duplicate_nickname 89 self.duplicate_nickname = new_duplicate_nickname
90 if isinstance(self.xmpp_c, xmpp.client.Client): 90 if isinstance(self.xmpp_c, xmpp.client.Client):
91 self.bridge.bot.close_xmpp_connection(self.nickname) 91 self.bridge.bot.close_xmpp_connection(self.nickname)
92 self.xmpp_c = None 92 self.xmpp_c = None
93 self.createDuplicateOnXMPP() 93 self.create_duplicate_on_xmpp()
94 return 94 return
95 95
96 else: 96 else:
97 self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" is used on both rooms or reserved on the XMPP server', log=True) 97 self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" is used on both rooms or reserved on the XMPP server', log=True)
98 if self.muc.connected == True: 98 if self.muc.connected == True:
105 if isinstance(self.xmpp_c, xmpp.client.Client): 105 if isinstance(self.xmpp_c, xmpp.client.Client):
106 self.bridge.bot.close_xmpp_connection(self.nickname) 106 self.bridge.bot.close_xmpp_connection(self.nickname)
107 self.xmpp_c = None 107 self.xmpp_c = None
108 108
109 109
110 def createDuplicateOnIRC(self): 110 def create_duplicate_on_irc(self):
111 if isinstance(self.xmpp_c, xmpp.client.Client) or isinstance(self.irc_connection, ServerConnection): 111 if isinstance(self.xmpp_c, xmpp.client.Client) or isinstance(self.irc_connection, ServerConnection):
112 return 112 return
113 self.irc_connection = self.bridge.bot.irc.open_connection(self.bridge.irc_server, self.bridge.irc_port, self.duplicate_nickname) 113 self.irc_connection = self.bridge.bot.irc.open_connection(self.bridge.irc_server, self.bridge.irc_port, self.duplicate_nickname)
114 self.irc_connection.connect(nick_callback=self._irc_nick_callback) 114 self.irc_connection.connect(nick_callback=self._irc_nick_callback)
115 115
137 self.bridge.say(say_levels.info, 'The nickname "'+self.duplicate_nickname+'" is used or reserved on the IRC server') 137 self.bridge.say(say_levels.info, 'The nickname "'+self.duplicate_nickname+'" is used or reserved on the IRC server')
138 self.duplicate_nickname = new_duplicate_nickname 138 self.duplicate_nickname = new_duplicate_nickname
139 if isinstance(self.irc_connection, ServerConnection): 139 if isinstance(self.irc_connection, ServerConnection):
140 self.irc_connection.close('') 140 self.irc_connection.close('')
141 self.irc_connection = error 141 self.irc_connection = error
142 self.createDuplicateOnIRC() 142 self.create_duplicate_on_irc()
143 return 143 return
144 144
145 else: 145 else:
146 self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" is used or reserved on the IRC server', log=True) 146 self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" is used or reserved on the IRC server', log=True)
147 147
149 if self.bridge.mode == 'bypass': 149 if self.bridge.mode == 'bypass':
150 self.duplicate_nickname = re.sub('[^a-zA-Z]', '', self.nickname) 150 self.duplicate_nickname = re.sub('[^a-zA-Z]', '', self.nickname)
151 if isinstance(self.irc_connection, ServerConnection): 151 if isinstance(self.irc_connection, ServerConnection):
152 self.irc_connection.close('') 152 self.irc_connection.close('')
153 self.irc_connection = error 153 self.irc_connection = error
154 self.createDuplicateOnIRC() 154 self.create_duplicate_on_irc()
155 return 155 return
156 else: 156 else:
157 self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" contains unauthorized characters and cannot be used in the IRC channel', log=True) 157 self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" contains unauthorized characters and cannot be used in the IRC channel', log=True)
158 158
159 elif error == 'nicknametoolong': 159 elif error == 'nicknametoolong':
178 self.bridge.bot.close_xmpp_connection(self.nickname) 178 self.bridge.bot.close_xmpp_connection(self.nickname)
179 if self.xmpp_c != 'both': 179 if self.xmpp_c != 'both':
180 self.xmpp_c = 'both' 180 self.xmpp_c = 'both'
181 181
182 182
183 def changeNickname(self, newnick, on_protocol): 183 def change_nickname(self, newnick, on_protocol):
184 """Change participant's nickname.""" 184 """Change participant's nickname."""
185 185
186 p = None 186 p = None
187 oldnick = self.nickname 187 oldnick = self.nickname
188 188
191 self._close_irc_connection('unwanted nick change') 191 self._close_irc_connection('unwanted nick change')
192 self.irc_connection = 'unwanted nick change' 192 self.irc_connection = 'unwanted nick change'
193 193
194 else: 194 else:
195 try: 195 try:
196 p = self.bridge.getParticipant(newnick) 196 p = self.bridge.get_participant(newnick)
197 except self.bridge.NoSuchParticipantException: 197 except self.bridge.NoSuchParticipantException:
198 self.nickname = newnick 198 self.nickname = newnick
199 self.duplicate_nickname = newnick 199 self.duplicate_nickname = newnick
200 has_connection = self.bridge.bot.irc.has_connection(self.bridge.irc_server, self.bridge.irc_port, self.duplicate_nickname) 200 has_connection = self.bridge.bot.irc.has_connection(self.bridge.irc_server, self.bridge.irc_port, self.duplicate_nickname)
201 if isinstance(self.irc_connection, ServerConnection): 201 if isinstance(self.irc_connection, ServerConnection):
202 if not has_connection and self.irc_connection.used_by == 1: 202 if not has_connection and self.irc_connection.used_by == 1:
203 self.irc_connection.nick(newnick, callback=self._irc_nick_callback) 203 self.irc_connection.nick(newnick, callback=self._irc_nick_callback)
204 else: 204 else:
205 self._close_irc_connection('Changed nickname') 205 self._close_irc_connection('Changed nickname')
206 self.createDuplicateOnIRC() 206 self.create_duplicate_on_irc()
207 else: 207 else:
208 if self.irc_connection == 'both': 208 if self.irc_connection == 'both':
209 self.bridge.addParticipant('irc', oldnick) 209 self.bridge.add_participant('irc', oldnick)
210 self.createDuplicateOnIRC() 210 self.create_duplicate_on_irc()
211 return 211 return
212 212
213 elif self.protocol == 'irc': 213 elif self.protocol == 'irc':
214 if on_protocol == 'irc': 214 if on_protocol == 'irc':
215 self._close_xmpp_connection('unwanted nick change') 215 self._close_xmpp_connection('unwanted nick change')
216 self.xmpp_c = 'unwanted nick change' 216 self.xmpp_c = 'unwanted nick change'
217 217
218 else: 218 else:
219 try: 219 try:
220 p = self.bridge.getParticipant(newnick) 220 p = self.bridge.get_participant(newnick)
221 except self.bridge.NoSuchParticipantException: 221 except self.bridge.NoSuchParticipantException:
222 self.nickname = newnick 222 self.nickname = newnick
223 self.duplicate_nickname = newnick 223 self.duplicate_nickname = newnick
224 if isinstance(self.xmpp_c, xmpp.client.Client): 224 if isinstance(self.xmpp_c, xmpp.client.Client):
225 for b in self.bridge.bot.bridges: 225 for b in self.bridge.bot.bridges:
226 if b.hasParticipant(oldnick) and b.irc_server != self.bridge.irc_server: 226 if b.has_participant(oldnick) and b.irc_server != self.bridge.irc_server:
227 self.muc.leave(message='Changed nickname to "'+self.nickname+'"') 227 self.muc.leave(message='Changed nickname to "'+self.nickname+'"')
228 self.xmpp_c = None 228 self.xmpp_c = None
229 self.bridge.bot.close_xmpp_connection(oldnick) 229 self.bridge.bot.close_xmpp_connection(oldnick)
230 self.createDuplicateOnXMPP() 230 self.create_duplicate_on_xmpp()
231 return 231 return
232 232
233 if not self.bridge.bot.xmpp_connections.has_key(newnick): 233 if not self.bridge.bot.xmpp_connections.has_key(newnick):
234 if self.bridge.bot.xmpp_connections.has_key(oldnick): 234 if self.bridge.bot.xmpp_connections.has_key(oldnick):
235 self.bridge.bot.xmpp_connections.pop(oldnick) 235 self.bridge.bot.xmpp_connections.pop(oldnick)
236 self.bridge.bot.xmpp_connections[newnick] = self.xmpp_c 236 self.bridge.bot.xmpp_connections[newnick] = self.xmpp_c
237 237
238 self.muc.change_nick(newnick, status='From IRC', callback=self._xmpp_join_callback) 238 self.muc.change_nick(newnick, status='From IRC', callback=self._xmpp_join_callback)
239 else: 239 else:
240 if self.xmpp_c == 'both': 240 if self.xmpp_c == 'both':
241 self.bridge.addParticipant('xmpp', oldnick) 241 self.bridge.add_participant('xmpp', oldnick)
242 self.createDuplicateOnXMPP() 242 self.create_duplicate_on_xmpp()
243 return 243 return
244 244
245 self.nickname = newnick 245 self.nickname = newnick
246 self.duplicate_nickname = newnick 246 self.duplicate_nickname = newnick
247 247
266 self.xmpp_c = p.xmpp_c 266 self.xmpp_c = p.xmpp_c
267 self.muc = p.muc 267 self.muc = p.muc
268 p.xmpp_c = None 268 p.xmpp_c = None
269 p.muc = None 269 p.muc = None
270 p.duplicate_nickname = p._get_new_duplicate_nickname() 270 p.duplicate_nickname = p._get_new_duplicate_nickname()
271 p.createDuplicateOnXMPP() 271 p.create_duplicate_on_xmpp()
272 else: 272 else:
273 # should never happen 273 # should never happen
274 raise Exception('WTF ?') 274 raise Exception('WTF ?')
275 275
276 276
277 def sayOnIRC(self, message): 277 def say_on_irc(self, message):
278 bot_say = False 278 bot_say = False
279 if message[:4] == '/me ': 279 if message[:4] == '/me ':
280 action = True 280 action = True
281 message = message[4:] 281 message = message[4:]
282 else: 282 else:
297 self.bridge.say(-1, '* '+self.nickname+' '+message, on_xmpp=False) 297 self.bridge.say(-1, '* '+self.nickname+' '+message, on_xmpp=False)
298 else: 298 else:
299 self.bridge.say(-1, '<'+self.nickname+'> '+message, on_xmpp=False) 299 self.bridge.say(-1, '<'+self.nickname+'> '+message, on_xmpp=False)
300 300
301 301
302 def sayOnIRCTo(self, to, message): 302 def say_on_irc_to(self, to, message):
303 if isinstance(self.irc_connection, ServerConnection): 303 if isinstance(self.irc_connection, ServerConnection):
304 self.irc_connection.privmsg(to, message) 304 self.irc_connection.privmsg(to, message)
305 elif not isinstance(self.xmpp_c, xmpp.client.Client): 305 elif not isinstance(self.xmpp_c, xmpp.client.Client):
306 if self.bridge.mode != 'normal': 306 if self.bridge.mode != 'normal':
307 self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') 307 self.bridge.get_participant(to).say_on_xmpp_to(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.')
308 else: 308 else:
309 self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but you cannot send cross-protocol private messages because I don\'t have an IRC duplicate with your nickname.') 309 self.bridge.get_participant(to).say_on_xmpp_to(self.nickname, 'Sorry but you cannot send cross-protocol private messages because I don\'t have an IRC duplicate with your nickname.')
310 310
311 311
312 def sayOnXMPP(self, message): 312 def say_on_xmpp(self, message):
313 if isinstance(self.xmpp_c, xmpp.client.Client): 313 if isinstance(self.xmpp_c, xmpp.client.Client):
314 self.muc.say(message) 314 self.muc.say(message)
315 elif not isinstance(self.irc_connection, ServerConnection): 315 elif not isinstance(self.irc_connection, ServerConnection):
316 self.say_on_XMPP_through_bridge(message) 316 self.say_on_XMPP_through_bridge(message)
317 317
321 self.bridge.say(-1, '* '+self.nickname+' '+message[4:], on_irc=False) 321 self.bridge.say(-1, '* '+self.nickname+' '+message[4:], on_irc=False)
322 else: 322 else:
323 self.bridge.say(-1, '<'+self.nickname+'> '+message, on_irc=False) 323 self.bridge.say(-1, '<'+self.nickname+'> '+message, on_irc=False)
324 324
325 325
326 def sayOnXMPPTo(self, to, message): 326 def say_on_xmpp_to(self, to, message):
327 if isinstance(self.xmpp_c, xmpp.client.Client): 327 if isinstance(self.xmpp_c, xmpp.client.Client):
328 self.muc.sayTo(to, message) 328 self.muc.say_to(to, message)
329 elif not isinstance(self.irc_connection, ServerConnection): 329 elif not isinstance(self.irc_connection, ServerConnection):
330 if self.bridge.mode != 'normal': 330 if self.bridge.mode != 'normal':
331 self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') 331 self.bridge.get_participant(to).say_on_xmpp_to(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.')
332 else: 332 else:
333 self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but you cannot send cross-protocol private messages because I don\'t have an XMPP duplicate with your nickname.') 333 self.bridge.get_participant(to).say_on_xmpp_to(self.nickname, 'Sorry but you cannot send cross-protocol private messages because I don\'t have an XMPP duplicate with your nickname.')
334 334
335 335
336 def leave(self, message): 336 def leave(self, message):
337 if message == None: 337 if message == None:
338 message = '' 338 message = ''