comparison bridge.py @ 260:9a2302e8382b

(irclib) created a "Channel" class Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sat, 13 Mar 2010 17:38:47 +0100
parents 3b318108e9e0
children db77ef37ff2c
comparison
equal deleted inserted replaced
259:3b318108e9e0 260:9a2302e8382b
17 17
18 import re 18 import re
19 import threading 19 import threading
20 import traceback 20 import traceback
21 21
22 from irclib import ServerConnection 22 import irclib
23 import muc 23 import muc
24 xmpp = muc.xmpp 24 xmpp = muc.xmpp
25 del muc 25 del muc
26 26
27 from participant import Participant 27 from participant import Participant
140 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):
141 return 141 return
142 try: 142 try:
143 p = self.get_participant(nickname) 143 p = self.get_participant(nickname)
144 if p.protocol != from_protocol: 144 if p.protocol != from_protocol:
145 if from_protocol == 'irc' and isinstance(p.irc_connection, ServerConnection) and p.irc_connection.logged_in or from_protocol == 'xmpp' and isinstance(p.muc, xmpp.muc) and p.muc.state >= p.muc.JOINING: 145 if from_protocol == 'irc' and isinstance(p.irc_connection, irclib.ServerConnection) and p.irc_connection.channels.has_key(self.irc_room) and p.irc_connection.channels[self.irc_room].state >= irclib.JOINING or from_protocol == 'xmpp' and isinstance(p.muc, xmpp.muc) and p.muc.state >= p.muc.JOINING:
146 return p 146 return p
147 p.set_both_sides() 147 p.set_both_sides()
148 return p 148 return p
149 except self.NoSuchParticipantException: 149 except self.NoSuchParticipantException:
150 pass 150 pass
292 else: 292 else:
293 if left_protocol == 'xmpp': 293 if left_protocol == 'xmpp':
294 was_on_both = False 294 was_on_both = False
295 elif left_protocol == 'irc': 295 elif left_protocol == 'irc':
296 # got disconnected somehow 296 # got disconnected somehow
297 if isinstance(p.irc_connection, ServerConnection): 297 if isinstance(p.irc_connection, irclib.ServerConnection):
298 if p.irc_connection.socket == 'closed': 298 if p.irc_connection.socket == 'closed':
299 return 299 return
300 p.irc_connection.join(self.irc_room) 300 p.irc_connection.join(self.irc_room)
301 else: 301 else:
302 c = self.bot.irc.get_connection(self.irc_server, self.irc_port, p.duplicate_nickname) 302 c = self.bot.irc.get_connection(self.irc_server, self.irc_port, p.duplicate_nickname)
303 if not (c and self.irc_room in c.left_channels): 303 if not (c and c.channels.has_key(self.irc_room) and c.channels[self.irc_room].state <= irclib.LEAVING):
304 p.create_duplicate_on_irc() 304 p.create_duplicate_on_irc()
305 return 305 return
306 306
307 elif p.protocol == 'irc': 307 elif p.protocol == 'irc':
308 if p.xmpp_c == 'both': 308 if p.xmpp_c == 'both':
401 401
402 if log: 402 if log:
403 self.bot.error(-1, message+' '+str(self), send_to_admins=True) 403 self.bot.error(-1, message+' '+str(self), send_to_admins=True)
404 404
405 # Leave 405 # Leave
406 if isinstance(self.irc_connection, ServerConnection) and isinstance(self.xmpp_room, xmpp.muc): 406 if isinstance(self.irc_connection, irclib.ServerConnection) and isinstance(self.xmpp_room, xmpp.muc):
407 self.irc_connection.part(self.irc_room, message=message) 407 self.irc_connection.part(self.irc_room, message=message)
408 self.xmpp_room.leave(message=message) 408 self.xmpp_room.leave(message=message)
409 else: 409 else:
410 self.stop() 410 self.stop()
411 self.init2() 411 self.init2()
421 421
422 if log: 422 if log:
423 self.bot.error(-1, message+' '+str(self), send_to_admins=True) 423 self.bot.error(-1, message+' '+str(self), send_to_admins=True)
424 424
425 # Close IRC connection if not used by an other bridge, just leave the room otherwise 425 # Close IRC connection if not used by an other bridge, just leave the room otherwise
426 if isinstance(self.irc_connection, ServerConnection): 426 if isinstance(self.irc_connection, irclib.ServerConnection):
427 self.irc_connection.used_by -= 1 427 self.irc_connection.used_by -= 1
428 if self.irc_connection.used_by < 1: 428 if self.irc_connection.used_by < 1:
429 self.irc_connection.close(message) 429 self.irc_connection.close(message)
430 else: 430 else:
431 self.irc_connection.part(self.irc_room, message=message) 431 self.irc_connection.part(self.irc_room, message=message)