comparison bridge.py @ 11:79b0a7f48a3e

Introduced the command mechanism and fixed a bug Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Mon, 17 Aug 2009 00:30:37 +0200
parents 7cb790f5f243
children fd695e2b5283
comparison
equal deleted inserted replaced
10:7cb790f5f243 11:79b0a7f48a3e
84 except NoSuchParticipantException: 84 except NoSuchParticipantException:
85 pass 85 pass
86 self.bot.error('===> Debug: adding participant "'+nickname+'" from "'+protocol+'" to bridge "'+str(self)+'"', debug=True) 86 self.bot.error('===> Debug: adding participant "'+nickname+'" from "'+protocol+'" to bridge "'+str(self)+'"', debug=True)
87 p = participant(self, protocol, nickname) 87 p = participant(self, protocol, nickname)
88 self.participants.append(p) 88 self.participants.append(p)
89 if self.mode != 'normal' and protocol == 'xmpp':
90 xmpp_participants_nicknames = self.get_xmpp_participants_nicknames_list()
91 self.say('[Info] Participants on XMPP: '+' '.join(xmpp_participants_nicknames), on_xmpp=False)
89 return p 92 return p
90 93
91 94
92 def getParticipant(self, nickname): 95 def getParticipant(self, nickname):
93 """Returns a participant object if there is a participant using nickname in the bridge. Raises a NoSuchParticipantException otherwise.""" 96 """Returns a participant object if there is a participant using nickname in the bridge. Raises a NoSuchParticipantException otherwise."""
94 for participant_ in self.participants: 97 for participant_ in self.participants:
95 if participant_.nickname == nickname: 98 if participant_.nickname == nickname:
96 return participant_ 99 return participant_
97 raise NoSuchParticipantException('there is no participant using the nickname "'+nickname+'" in this bridge') 100 raise NoSuchParticipantException('there is no participant using the nickname "'+nickname+'" in this bridge')
101
102
103 def get_xmpp_participants_nicknames_list(self):
104 xmpp_participants_nicknames = []
105 for p in self.participants:
106 if p.protocol == 'xmpp':
107 xmpp_participants_nicknames.append(p.nickname)
108 return xmpp_participants_nicknames
98 109
99 110
100 def removeParticipant(self, protocol, nickname, leave_message): 111 def removeParticipant(self, protocol, nickname, leave_message):
101 """Remove the participant using nickname from the bridge. Raises a NoSuchParticipantException if nickname is not used in the bridge.""" 112 """Remove the participant using nickname from the bridge. Raises a NoSuchParticipantException if nickname is not used in the bridge."""
102 p = self.getParticipant(nickname) 113 p = self.getParticipant(nickname)
121 if protocol == 'xmpp' and self.irc_connections_limit >= i: 132 if protocol == 'xmpp' and self.irc_connections_limit >= i:
122 self.switchToNormalMode() 133 self.switchToNormalMode()
123 del p 134 del p
124 135
125 136
126 def say(self, message): 137 def say(self, message, on_irc=True, on_xmpp=True):
127 self.xmpp_room.say(message) 138 if on_xmpp == True:
128 self.irc_connection.privmsg(self.irc_room, auto_encode(message)) 139 self.xmpp_room.say(message)
140 if on_irc == True:
141 self.irc_connection.privmsg(self.irc_room, auto_encode(message))
129 142
130 143
131 def switchToNormalMode(self): 144 def switchToNormalMode(self):
132 if self.mode == 'normal': 145 if self.mode == 'normal':
133 return 146 return
155 p.irc_connection.disconnect('Bridge is switching to limited mode') 168 p.irc_connection.disconnect('Bridge is switching to limited mode')
156 p.irc_connection = None 169 p.irc_connection = None
157 self.irc_connections_limit = i 170 self.irc_connections_limit = i
158 self.bot.error('===> Bridge is switching to limited mode.') 171 self.bot.error('===> Bridge is switching to limited mode.')
159 self.say('[Warning] Bridge is switching to limited mode, it means that it will be transparent for XMPP users but not for IRC users, this is due to the IRC servers\' per-IP-address connections\' limit number.') 172 self.say('[Warning] Bridge is switching to limited mode, it means that it will be transparent for XMPP users but not for IRC users, this is due to the IRC servers\' per-IP-address connections\' limit number.')
173 xmpp_participants_nicknames = self.get_xmpp_participants_nicknames_list()
174 self.say('[Info] Participants on XMPP: '+' '.join(xmpp_participants_nicknames), on_xmpp=False)
160 175
161 176
162 def __str__(self): 177 def __str__(self):
163 return self.irc_room+'@'+self.irc_server+' <-> '+self.xmpp_room.room_jid 178 return self.irc_room+'@'+self.irc_server+' <-> '+self.xmpp_room.room_jid
164 179