comparison participant.py @ 125:efdc038e757a

fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it) Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Wed, 13 Jan 2010 22:28:09 +0100
parents 99f3dee1fad7
children 6a6885dbed25
comparison
equal deleted inserted replaced
124:99f3dee1fad7 125:efdc038e757a
107 107
108 def createDuplicateOnIRC(self): 108 def createDuplicateOnIRC(self):
109 if isinstance(self.xmpp_c, xmpp.client.Client) or isinstance(self.irc_connection, ServerConnection): 109 if isinstance(self.xmpp_c, xmpp.client.Client) or isinstance(self.irc_connection, ServerConnection):
110 return 110 return
111 sleep(1) # try to prevent "reconnecting too fast" shit 111 sleep(1) # try to prevent "reconnecting too fast" shit
112 self.irc_connection = self.bridge.bot.irc.server(self.bridge.irc_server, self.bridge.irc_port, self.duplicate_nickname) 112 self.irc_connection = self.bridge.bot.irc.open_connection(self.bridge.irc_server, self.bridge.irc_port, self.duplicate_nickname)
113 self.irc_connection.connect(nick_callback=self._irc_nick_callback) 113 self.irc_connection.connect(nick_callback=self._irc_nick_callback)
114 114
115 115
116 def _irc_nick_callback(self, error, arguments=[]): 116 def _irc_nick_callback(self, error, arguments=[]):
117 if error == None: 117 if error == None:
193 if on_protocol == 'xmpp': 193 if on_protocol == 'xmpp':
194 self._close_irc_connection('unwanted nick change') 194 self._close_irc_connection('unwanted nick change')
195 self.irc_connection = 'unwanted nick change' 195 self.irc_connection = 'unwanted nick change'
196 196
197 else: 197 else:
198 self.nickname = newnick 198 try:
199 self.duplicate_nickname = newnick 199 p = self.bridge.getParticipant(newnick)
200 if isinstance(self.irc_connection, ServerConnection): 200 except self.bridge.NoSuchParticipantException:
201 if self.irc_connection.used_by == 1: 201 self.nickname = newnick
202 self.irc_connection.nick(newnick, callback=self._irc_nick_callback) 202 self.duplicate_nickname = newnick
203 has_connection = self.bridge.bot.irc.has_connection(self.bridge.irc_server, self.bridge.irc_port, self.duplicate_nickname)
204 if isinstance(self.irc_connection, ServerConnection):
205 if not has_connection and self.irc_connection.used_by == 1:
206 self.irc_connection.nick(newnick, callback=self._irc_nick_callback)
207 else:
208 self._close_irc_connection('Changed nickname')
209 self.createDuplicateOnIRC()
203 else: 210 else:
204 self._close_irc_connection('Changed nickname') 211 if self.irc_connection == 'both':
212 self.bridge.addParticipant('irc', oldnick)
205 self.createDuplicateOnIRC() 213 self.createDuplicateOnIRC()
206 else: 214 return
207 if self.irc_connection == 'both':
208 self.bridge.addParticipant('irc', oldnick)
209 self.createDuplicateOnIRC()
210 215
211 elif self.protocol == 'irc': 216 elif self.protocol == 'irc':
212 if on_protocol == 'irc': 217 if on_protocol == 'irc':
213 self._close_xmpp_connection('unwanted nick change') 218 self._close_xmpp_connection('unwanted nick change')
214 self.xmpp_c = 'unwanted nick change' 219 self.xmpp_c = 'unwanted nick change'
215 220
216 else: 221 else:
217 self.nickname = newnick 222 try:
218 self.duplicate_nickname = newnick 223 p = self.bridge.getParticipant(newnick)
219 if isinstance(self.xmpp_c, xmpp.client.Client): 224 except self.bridge.NoSuchParticipantException:
220 for b in self.bridge.bot.bridges: 225 self.nickname = newnick
221 if b.hasParticipant(oldnick) and b.irc_server != self.bridge.irc_server: 226 self.duplicate_nickname = newnick
222 self.muc.leave(message='Changed nickname to "'+self.nickname+'"') 227 if isinstance(self.xmpp_c, xmpp.client.Client):
223 self.xmpp_c = None 228 for b in self.bridge.bot.bridges:
224 self.bridge.bot.close_xmpp_connection(oldnick) 229 if b.hasParticipant(oldnick) and b.irc_server != self.bridge.irc_server:
225 self.createDuplicateOnXMPP() 230 self.muc.leave(message='Changed nickname to "'+self.nickname+'"')
226 return 231 self.xmpp_c = None
227 232 self.bridge.bot.close_xmpp_connection(oldnick)
228 if not self.bridge.bot.xmpp_connections.has_key(newnick): 233 self.createDuplicateOnXMPP()
229 if self.bridge.bot.xmpp_connections.has_key(oldnick): 234 return
230 self.bridge.bot.xmpp_connections.pop(oldnick) 235
231 self.bridge.bot.xmpp_connections[newnick] = self.xmpp_c 236 if not self.bridge.bot.xmpp_connections.has_key(newnick):
232 237 if self.bridge.bot.xmpp_connections.has_key(oldnick):
233 self.muc.change_nick(newnick, status='From IRC', callback=self._xmpp_join_callback) 238 self.bridge.bot.xmpp_connections.pop(oldnick)
234 else: 239 self.bridge.bot.xmpp_connections[newnick] = self.xmpp_c
235 if self.xmpp_c == 'both': 240
236 self.bridge.addParticipant('xmpp', oldnick) 241 self.muc.change_nick(newnick, status='From IRC', callback=self._xmpp_join_callback)
237 self.createDuplicateOnXMPP() 242 else:
243 if self.xmpp_c == 'both':
244 self.bridge.addParticipant('xmpp', oldnick)
245 self.createDuplicateOnXMPP()
246 return
247
248 self.nickname = newnick
249 self.duplicate_nickname = newnick
250 if p.nickname == newnick:
251 if p.protocol == self.protocol:
252 # should never happen
253 raise Exception('WTF ?')
254 else:
255 self.set_both_sides()
256 elif p.duplicate_nickname == newnick:
257 if p.protocol != self.protocol:
258 # should never happen
259 raise Exception('WTF ?')
260 else:
261 if self.protocol == 'xmpp':
262 self.irc_connection = p.irc_connection
263 p.irc_connection = None
264 else:
265 self.xmpp_c = p.xmpp_c
266 self.muc = p.muc
267 p.xmpp_c = None
268 p.muc = None
269 p.duplicate_nickname = p._get_new_duplicate_nickname()
270 p.createDuplicateOnXMPP()
271 else:
272 # should never happen
273 raise Exception('WTF ?')
238 274
239 275
240 def sayOnIRC(self, message): 276 def sayOnIRC(self, message):
241 try: 277 try:
242 bot_say = False 278 bot_say = False