comparison bridge.py @ 174:c158ad24ef3c

moved irc connection interval handling to irclib Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Thu, 04 Feb 2010 21:02:36 +0100
parents 64a0e9636ae6
children 8378da7844f2
comparison
equal deleted inserted replaced
173:6c4aaf8f3733 174:c158ad24ef3c
40 40
41 41
42 class NoSuchParticipantException(Exception): pass 42 class NoSuchParticipantException(Exception): pass
43 43
44 44
45 def __init__(self, owner_bot, xmpp_room_jid, irc_room, irc_server, mode, say_level, irc_port=6667, irc_connection_interval=1, irc_charsets=None): 45 def __init__(self, owner_bot, xmpp_room_jid, irc_room, irc_server, mode, say_level, irc_port=6667, irc_connection_interval=None, irc_charsets=None):
46 """Create a new bridge.""" 46 """Create a new bridge."""
47 self.bot = owner_bot 47 self.bot = owner_bot
48 self.irc_server = irc_server 48 self.irc_server = irc_server
49 self.irc_port = irc_port 49 self.irc_port = irc_port
50 self.irc_room = irc_room.lower() 50 self.irc_room = irc_room.lower()
65 self.init2() 65 self.init2()
66 66
67 67
68 def init2(self): 68 def init2(self):
69 # Join XMPP room 69 # Join XMPP room
70 try: 70 self.xmpp_room = xmpp.muc(self.xmpp_room_jid)
71 self.xmpp_room = xmpp.muc(self.xmpp_room_jid) 71 self.xmpp_room.join(self.bot.xmpp_c, self.bot.nickname, callback=self._xmpp_join_callback)
72 self.xmpp_room.join(self.bot.xmpp_c, self.bot.nickname, callback=self._xmpp_join_callback)
73 except:
74 self.bot.error('[Error] joining XMPP room failed')
75 raise
76 72
77 # Join IRC room 73 # Join IRC room
78 try: 74 self.irc_connection = self.bot.irc.open_connection(self.irc_server, self.irc_port, self.bot.nickname, delay=self.irc_connection_interval)
79 self.irc_connections_limit = -1 75 self.irc_connection.connect(nick_callback=self._irc_nick_callback, charsets=self.irc_charsets)
80 self.irc_connection = self.bot.irc.open_connection(self.irc_server, self.irc_port, self.bot.nickname)
81 self.irc_connection.connect(nick_callback=self._irc_nick_callback, charsets=self.irc_charsets)
82 except:
83 self.bot.error('[Error] joining IRC room failed')
84 raise
85 76
86 self.bot.error('[Notice] bridge "'+str(self)+'" is running in '+self.mode+' mode and a say_level of "'+self.__class__._say_levels[self.say_level]+'"') 77 self.bot.error('[Notice] bridge "'+str(self)+'" is running in '+self.mode+' mode and a say_level of "'+self.__class__._say_levels[self.say_level]+'"')
87 78
88 79
89 def _irc_nick_callback(self, error, arguments=[]): 80 def _irc_nick_callback(self, error, arguments=[]):
91 if self.mode == None: 82 if self.mode == None:
92 return 83 return
93 self.irc_connection.join(self.irc_room) 84 self.irc_connection.join(self.irc_room)
94 self.bot.error('===> Debug: successfully connected on IRC side of bridge "'+str(self)+'"', debug=True) 85 self.bot.error('===> Debug: successfully connected on IRC side of bridge "'+str(self)+'"', debug=True)
95 self.say('[Notice] bridge "'+str(self)+'" is running in '+self.mode+' mode', on_xmpp=False) 86 self.say('[Notice] bridge "'+str(self)+'" is running in '+self.mode+' mode', on_xmpp=False)
87 if self.mode not in ['normal', 'bypass']:
88 self.show_participants_list_on(protocols=['irc'])
96 else: 89 else:
97 self.mode = None 90 self.mode = None
98 if self.xmpp_room.connected == True: 91 if self.xmpp_room.connected == True:
99 self.say('[Error] failed to connect to the IRC chan, leaving ...', on_irc=False) 92 self.say('[Error] failed to connect to the IRC chan, leaving ...', on_irc=False)
100 try: 93 try:
383 if on_irc == True: 376 if on_irc == True:
384 self.irc_connection.privmsg(self.irc_room, message) 377 self.irc_connection.privmsg(self.irc_room, message)
385 378
386 379
387 def show_participants_list_on(self, protocols=[]): 380 def show_participants_list_on(self, protocols=[]):
388 if 'irc' in protocols: 381 if 'irc' in protocols and self.irc_connection.really_connected:
389 xmpp_participants_nicknames = self.get_participants_nicknames_list(protocols=['xmpp']) 382 xmpp_participants_nicknames = self.get_participants_nicknames_list(protocols=['xmpp'])
390 self.say('[Info] Participants on XMPP: '+' '.join(xmpp_participants_nicknames), on_xmpp=False) 383 self.say('[Info] Participants on XMPP: '+' '.join(xmpp_participants_nicknames), on_xmpp=False)
391 if 'xmpp' in protocols: 384 if 'xmpp' in protocols:
392 irc_participants_nicknames = self.get_participants_nicknames_list(protocols=['irc']) 385 irc_participants_nicknames = self.get_participants_nicknames_list(protocols=['irc'])
393 self.say('[Info] Participants on IRC: '+' '.join(irc_participants_nicknames), on_irc=False) 386 self.say('[Info] Participants on IRC: '+' '.join(irc_participants_nicknames), on_irc=False)