comparison participant.py @ 137:9f39cead20cb

reduced duplication of error messages Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sat, 16 Jan 2010 17:01:17 +0100
parents 7dc6a1764c4f
children ddc87b605019
comparison
equal deleted inserted replaced
136:7dc6a1764c4f 137:9f39cead20cb
81 if self.bridge.mode == 'bypass': 81 if self.bridge.mode == 'bypass':
82 new_duplicate_nickname = self._get_new_duplicate_nickname() 82 new_duplicate_nickname = self._get_new_duplicate_nickname()
83 if new_duplicate_nickname != None: 83 if new_duplicate_nickname != None:
84 self.bridge.bot.error('===> Debug: "'+self.duplicate_nickname+'" is already used in the XMPP MUC or reserved on the XMPP server of bridge "'+str(self.bridge)+'", trying "'+new_duplicate_nickname+'"', debug=True) 84 self.bridge.bot.error('===> Debug: "'+self.duplicate_nickname+'" is already used in the XMPP MUC or reserved on the XMPP server of bridge "'+str(self.bridge)+'", trying "'+new_duplicate_nickname+'"', debug=True)
85 if self.duplicate_nickname == self.nickname: 85 if self.duplicate_nickname == self.nickname:
86 self.bridge.say('[Info] The nickname "'+self.duplicate_nickname+'" is used on both rooms or reserved on the XMPP server, please avoid that if possible') 86 self.bridge.say('[Info] The nickname "'+self.duplicate_nickname+'" is used on both rooms or reserved on the XMPP server')
87 self.duplicate_nickname = new_duplicate_nickname 87 self.duplicate_nickname = new_duplicate_nickname
88 if isinstance(self.xmpp_c, xmpp.client.Client): 88 if isinstance(self.xmpp_c, xmpp.client.Client):
89 self.bridge.bot.close_xmpp_connection(self.nickname) 89 self.bridge.bot.close_xmpp_connection(self.nickname)
90 self.xmpp_c = None 90 self.xmpp_c = None
91 self.createDuplicateOnXMPP() 91 self.createDuplicateOnXMPP()
92 return 92 return
93 93
94 else: 94 else:
95 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is already used in the XMPP MUC or reserved on the XMPP server of bridge "'+str(self.bridge)+'"', debug=True) 95 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both rooms or reserved on the XMPP server', log=True)
96 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both rooms or reserved on the XMPP server, please avoid that if possible')
97 if self.muc.connected == True: 96 if self.muc.connected == True:
98 self.muc.leave('Changed nickname to "'+self.nickname+'"') 97 self.muc.leave('Changed nickname to "'+self.nickname+'"')
99 except xmpp.muc.RoomIsFull: 98 except xmpp.muc.RoomIsFull:
100 self.bridge.bot.error('[Warning] XMPP MUC of bridge "'+str(self.bridge)+'" is full', send_to_admins=True) 99 self.bridge.say('[Warning] XMPP room is full', log=True)
101 self.bridge.say('[Warning] XMPP room is full')
102 except xmpp.muc.RemoteServerNotFound: 100 except xmpp.muc.RemoteServerNotFound:
103 self.bridge._RemoteServerNotFound_handler() 101 self.bridge._RemoteServerNotFound_handler()
104 102
105 if isinstance(self.xmpp_c, xmpp.client.Client): 103 if isinstance(self.xmpp_c, xmpp.client.Client):
106 self.bridge.bot.close_xmpp_connection(self.nickname) 104 self.bridge.bot.close_xmpp_connection(self.nickname)
133 if self.bridge.mode == 'bypass': 131 if self.bridge.mode == 'bypass':
134 new_duplicate_nickname = self._get_new_duplicate_nickname() 132 new_duplicate_nickname = self._get_new_duplicate_nickname()
135 if new_duplicate_nickname != None: 133 if new_duplicate_nickname != None:
136 self.bridge.bot.error('===> Debug: "'+self.duplicate_nickname+'" is already used or reserved on the IRC server of bridge "'+str(self.bridge)+'", trying "'+new_duplicate_nickname+'"', debug=True) 134 self.bridge.bot.error('===> Debug: "'+self.duplicate_nickname+'" is already used or reserved on the IRC server of bridge "'+str(self.bridge)+'", trying "'+new_duplicate_nickname+'"', debug=True)
137 if self.duplicate_nickname == self.nickname: 135 if self.duplicate_nickname == self.nickname:
138 self.bridge.say('[Info] The nickname "'+self.duplicate_nickname+'" is used or reserved on the IRC server, please avoid that if possible') 136 self.bridge.say('[Info] The nickname "'+self.duplicate_nickname+'" is used or reserved on the IRC server')
139 self.duplicate_nickname = new_duplicate_nickname 137 self.duplicate_nickname = new_duplicate_nickname
140 if isinstance(self.irc_connection, ServerConnection): 138 if isinstance(self.irc_connection, ServerConnection):
141 self.irc_connection.close('') 139 self.irc_connection.close('')
142 self.irc_connection = error 140 self.irc_connection = error
143 self.createDuplicateOnIRC() 141 self.createDuplicateOnIRC()
144 return 142 return
145 143
146 else: 144 else:
147 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is used or reserved on the IRC server of bridge "'+str(self.bridge)+'"', debug=True) 145 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used or reserved on the IRC server', log=True)
148 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used or reserved on the IRC server, please avoid that if possible')
149 146
150 elif error == 'erroneusnickname': 147 elif error == 'erroneusnickname':
151 if self.bridge.mode == 'bypass': 148 if self.bridge.mode == 'bypass':
152 self.duplicate_nickname = re.sub('[^a-zA-Z]', '', self.nickname) 149 self.duplicate_nickname = re.sub('[^a-zA-Z]', '', self.nickname)
153 if isinstance(self.irc_connection, ServerConnection): 150 if isinstance(self.irc_connection, ServerConnection):
154 self.irc_connection.close('') 151 self.irc_connection.close('')
155 self.irc_connection = error 152 self.irc_connection = error
156 self.createDuplicateOnIRC() 153 self.createDuplicateOnIRC()
157 return 154 return
158 else: 155 else:
159 self.bridge.bot.error('===> Debug: "'+self.nickname+'" got "erroneusnickname" on bridge "'+str(self.bridge)+'"', debug=True) 156 self.bridge.say('[Warning] The nickname "'+self.nickname+'" contains unauthorized characters and cannot be used in the IRC channel', log=True)
160 self.bridge.say('[Warning] The nickname "'+self.nickname+'" contains unauthorized characters and cannot be used in the IRC channel, please avoid that if possible')
161 157
162 elif error == 'nicknametoolong': 158 elif error == 'nicknametoolong':
163 self.bridge.bot.error('===> Debug: "'+self.nickname+'" got "nicknametoolong" on bridge "'+str(self.bridge)+'"', debug=True) 159 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is too long (limit seems to be '+str(arguments[0])+') and cannot be used in the IRC channel', log=True)
164 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is too long (limit seems to be '+str(arguments[0])+') and cannot be used in the IRC channel, please avoid that if possible') 160
165 161 else:
166 else: 162 self.bridge.say('[Warning] unknown error while adding "'+self.nickname+'" to IRC side of bridge', log=True)
167 self.bridge.bot.error('===> Debug: unknown error while adding "'+self.nickname+'" to IRC side of bridge "'+str(self.bridge)+'"', debug=True)
168 self.bridge.say('[Warning] unknown error while adding "'+self.nickname+'" to IRC side of bridge')
169 163
170 if isinstance(self.irc_connection, ServerConnection): 164 if isinstance(self.irc_connection, ServerConnection):
171 self.irc_connection.close('') 165 self.irc_connection.close('')
172 self.irc_connection = error 166 self.irc_connection = error
173 167
174 168
175 def set_both_sides(self): 169 def set_both_sides(self):
176 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is on both sides of bridge "'+str(self.bridge)+'"', debug=True) 170 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both sides of the bridge', log=True)
177 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both sides of the bridge, please avoid that if possible')
178 if isinstance(self.irc_connection, ServerConnection): 171 if isinstance(self.irc_connection, ServerConnection):
179 self.irc_connection.close('') 172 self.irc_connection.close('')
180 if self.irc_connection != 'both': 173 if self.irc_connection != 'both':
181 self.irc_connection = 'both' 174 self.irc_connection = 'both'
182 if isinstance(self.muc, xmpp.muc): 175 if isinstance(self.muc, xmpp.muc):
298 if action: 291 if action:
299 self.bridge.irc_connection.privmsg(self.bridge.irc_room, '* '+self.nickname+' '+message) 292 self.bridge.irc_connection.privmsg(self.bridge.irc_room, '* '+self.nickname+' '+message)
300 else: 293 else:
301 self.bridge.irc_connection.privmsg(self.bridge.irc_room, '<'+self.nickname+'> '+message) 294 self.bridge.irc_connection.privmsg(self.bridge.irc_room, '<'+self.nickname+'> '+message)
302 except EncodingException: 295 except EncodingException:
303 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding') 296 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding', log=True)
304 297
305 298
306 def sayOnIRCTo(self, to, message): 299 def sayOnIRCTo(self, to, message):
307 if isinstance(self.irc_connection, ServerConnection): 300 if isinstance(self.irc_connection, ServerConnection):
308 try: 301 try:
309 self.irc_connection.privmsg(to, message) 302 self.irc_connection.privmsg(to, message)
310 except EncodingException: 303 except EncodingException:
311 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding') 304 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding', log=True)
312 elif not isinstance(self.xmpp_c, xmpp.client.Client): 305 elif not isinstance(self.xmpp_c, xmpp.client.Client):
313 if self.bridge.mode != 'normal': 306 if self.bridge.mode != 'normal':
314 self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') 307 self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.')
315 else: 308 else:
316 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.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.')
324 if message[:4] == '/me ': 317 if message[:4] == '/me ':
325 self.bridge.xmpp_room.say('* '+self.nickname+' '+auto_decode(message[4:])) 318 self.bridge.xmpp_room.say('* '+self.nickname+' '+auto_decode(message[4:]))
326 else: 319 else:
327 self.bridge.xmpp_room.say('<'+self.nickname+'> '+auto_decode(message)) 320 self.bridge.xmpp_room.say('<'+self.nickname+'> '+auto_decode(message))
328 except EncodingException: 321 except EncodingException:
329 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding') 322 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding', log=True)
330 323
331 324
332 def sayOnXMPPTo(self, to, message): 325 def sayOnXMPPTo(self, to, message):
333 try: 326 try:
334 if isinstance(self.xmpp_c, xmpp.client.Client): 327 if isinstance(self.xmpp_c, xmpp.client.Client):
337 if self.bridge.mode != 'normal': 330 if self.bridge.mode != 'normal':
338 self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') 331 self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.')
339 else: 332 else:
340 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.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.')
341 except EncodingException: 334 except EncodingException:
342 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding') 335 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding', log=True)
343 336
344 337
345 def leave(self, message): 338 def leave(self, message):
346 if message == None: 339 if message == None:
347 message = '' 340 message = ''