Mercurial > xib
comparison participant.py @ 180:102f895347ff
added a required "importance" argument to Bot.error()
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sat, 13 Feb 2010 16:32:28 +0100 |
parents | c158ad24ef3c |
children | 6173873c6b0d |
comparison
equal
deleted
inserted
replaced
179:f6c6708c6c0e | 180:102f895347ff |
---|---|
20 | 20 |
21 from irclib import ServerNotConnectedError, ServerConnection | 21 from irclib import ServerNotConnectedError, ServerConnection |
22 import muc | 22 import muc |
23 xmpp = muc.xmpp | 23 xmpp = muc.xmpp |
24 del muc | 24 del muc |
25 | |
26 import say_levels | |
25 | 27 |
26 | 28 |
27 class Participant: | 29 class Participant: |
28 def __init__(self, owner_bridge, protocol, nickname, real_jid=None): | 30 def __init__(self, owner_bridge, protocol, nickname, real_jid=None): |
29 self.bot_admin = False | 31 self.bot_admin = False |
62 self.muc.join(self.xmpp_c, self.duplicate_nickname, status='From IRC', callback=self._xmpp_join_callback) | 64 self.muc.join(self.xmpp_c, self.duplicate_nickname, status='From IRC', callback=self._xmpp_join_callback) |
63 | 65 |
64 | 66 |
65 def _xmpp_join_callback(self, errors): | 67 def _xmpp_join_callback(self, errors): |
66 if len(errors) == 0: | 68 if len(errors) == 0: |
67 m = '===> Debug: "'+self.nickname+'" duplicate succesfully created on XMPP side of bridge "'+str(self.bridge)+'"' | 69 m = '"'+self.nickname+'" duplicate succesfully created on XMPP side of bridge "'+str(self.bridge)+'"' |
68 if self.nickname != self.duplicate_nickname: | 70 if self.nickname != self.duplicate_nickname: |
69 m += ' using nickname "'+self.duplicate_nickname+'"' | 71 m += ' using nickname "'+self.duplicate_nickname+'"' |
70 self.bridge.say('[Info] "'+self.nickname+'" will appear as "'+self.duplicate_nickname+'" on XMPP because its real nickname is reserved or contains unauthorized characters') | 72 self.bridge.say(say_levels.info, '"'+self.nickname+'" will appear as "'+self.duplicate_nickname+'" on XMPP because its real nickname is reserved or contains unauthorized characters') |
71 self.bridge.bot.error(m, debug=True) | 73 self.bridge.bot.error(3, m, debug=True) |
72 elif self.xmpp_c != 'both': | 74 elif self.xmpp_c != 'both': |
73 for error in errors: | 75 for error in errors: |
74 try: | 76 try: |
75 raise error | 77 raise error |
76 except xmpp.muc.NicknameConflict as e: | 78 except xmpp.muc.NicknameConflict as e: |
78 return | 80 return |
79 | 81 |
80 if self.bridge.mode == 'bypass': | 82 if self.bridge.mode == 'bypass': |
81 new_duplicate_nickname = self._get_new_duplicate_nickname() | 83 new_duplicate_nickname = self._get_new_duplicate_nickname() |
82 if new_duplicate_nickname != None: | 84 if new_duplicate_nickname != None: |
83 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 self.bridge.bot.error(3, '"'+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 if self.duplicate_nickname == self.nickname: | 86 if self.duplicate_nickname == self.nickname: |
85 self.bridge.say('[Info] The nickname "'+self.duplicate_nickname+'" is used on both rooms or reserved on the XMPP server') | 87 self.bridge.say(say_levels.info, 'The nickname "'+self.duplicate_nickname+'" is used on both rooms or reserved on the XMPP server') |
86 self.duplicate_nickname = new_duplicate_nickname | 88 self.duplicate_nickname = new_duplicate_nickname |
87 if isinstance(self.xmpp_c, xmpp.client.Client): | 89 if isinstance(self.xmpp_c, xmpp.client.Client): |
88 self.bridge.bot.close_xmpp_connection(self.nickname) | 90 self.bridge.bot.close_xmpp_connection(self.nickname) |
89 self.xmpp_c = None | 91 self.xmpp_c = None |
90 self.createDuplicateOnXMPP() | 92 self.createDuplicateOnXMPP() |
91 return | 93 return |
92 | 94 |
93 else: | 95 else: |
94 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(say_levels.warning, 'The nickname "'+self.nickname+'" is used on both rooms or reserved on the XMPP server', log=True) |
95 if self.muc.connected == True: | 97 if self.muc.connected == True: |
96 self.muc.leave('Changed nickname to "'+self.nickname+'"') | 98 self.muc.leave('Changed nickname to "'+self.nickname+'"') |
97 except xmpp.muc.RoomIsFull: | 99 except xmpp.muc.RoomIsFull: |
98 self.bridge.say('[Warning] XMPP room is full', log=True) | 100 self.bridge.say(say_levels.warning, 'XMPP room is full', log=True) |
99 except xmpp.muc.RemoteServerNotFound: | 101 except xmpp.muc.RemoteServerNotFound: |
100 self.bridge._RemoteServerNotFound_handler() | 102 self.bridge._RemoteServerNotFound_handler() |
101 | 103 |
102 if isinstance(self.xmpp_c, xmpp.client.Client): | 104 if isinstance(self.xmpp_c, xmpp.client.Client): |
103 self.bridge.bot.close_xmpp_connection(self.nickname) | 105 self.bridge.bot.close_xmpp_connection(self.nickname) |
112 | 114 |
113 | 115 |
114 def _irc_nick_callback(self, error, arguments=[]): | 116 def _irc_nick_callback(self, error, arguments=[]): |
115 if error == None: | 117 if error == None: |
116 self.irc_connection.join(self.bridge.irc_room) | 118 self.irc_connection.join(self.bridge.irc_room) |
117 m = '===> Debug: "'+self.nickname+'" duplicate succesfully created on IRC side of bridge "'+str(self.bridge)+'"' | 119 m = '"'+self.nickname+'" duplicate succesfully created on IRC side of bridge "'+str(self.bridge)+'"' |
118 if self.nickname != self.duplicate_nickname: | 120 if self.nickname != self.duplicate_nickname: |
119 m += ' using nickname "'+self.duplicate_nickname+'"' | 121 m += ' using nickname "'+self.duplicate_nickname+'"' |
120 self.bridge.say('[Info] "'+self.nickname+'" will appear as "'+self.duplicate_nickname+'" on IRC because its real nickname is reserved or contains unauthorized characters') | 122 self.bridge.say(say_levels.info, '"'+self.nickname+'" will appear as "'+self.duplicate_nickname+'" on IRC because its real nickname is reserved or contains unauthorized characters') |
121 self.bridge.bot.error(m, debug=True) | 123 self.bridge.bot.error(3, m, debug=True) |
122 | 124 |
123 elif self.irc_connection != 'both': | 125 elif self.irc_connection != 'both': |
124 | 126 |
125 if error in ['nicknameinuse', 'nickcollision']: | 127 if error in ['nicknameinuse', 'nickcollision']: |
126 if arguments[0].arguments()[0] != self.duplicate_nickname: | 128 if arguments[0].arguments()[0] != self.duplicate_nickname: |
127 return | 129 return |
128 | 130 |
129 if self.bridge.mode == 'bypass': | 131 if self.bridge.mode == 'bypass': |
130 new_duplicate_nickname = self._get_new_duplicate_nickname() | 132 new_duplicate_nickname = self._get_new_duplicate_nickname() |
131 if new_duplicate_nickname != None: | 133 if new_duplicate_nickname != None: |
132 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(3, '"'+self.duplicate_nickname+'" is already used or reserved on the IRC server of bridge "'+str(self.bridge)+'", trying "'+new_duplicate_nickname+'"', debug=True) |
133 if self.duplicate_nickname == self.nickname: | 135 if self.duplicate_nickname == self.nickname: |
134 self.bridge.say('[Info] The nickname "'+self.duplicate_nickname+'" is used or reserved on the IRC server') | 136 self.bridge.say(say_levels.info, 'The nickname "'+self.duplicate_nickname+'" is used or reserved on the IRC server') |
135 self.duplicate_nickname = new_duplicate_nickname | 137 self.duplicate_nickname = new_duplicate_nickname |
136 if isinstance(self.irc_connection, ServerConnection): | 138 if isinstance(self.irc_connection, ServerConnection): |
137 self.irc_connection.close('') | 139 self.irc_connection.close('') |
138 self.irc_connection = error | 140 self.irc_connection = error |
139 self.createDuplicateOnIRC() | 141 self.createDuplicateOnIRC() |
140 return | 142 return |
141 | 143 |
142 else: | 144 else: |
143 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used or reserved on the IRC server', log=True) | 145 self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" is used or reserved on the IRC server', log=True) |
144 | 146 |
145 elif error == 'erroneusnickname': | 147 elif error == 'erroneusnickname': |
146 if self.bridge.mode == 'bypass': | 148 if self.bridge.mode == 'bypass': |
147 self.duplicate_nickname = re.sub('[^a-zA-Z]', '', self.nickname) | 149 self.duplicate_nickname = re.sub('[^a-zA-Z]', '', self.nickname) |
148 if isinstance(self.irc_connection, ServerConnection): | 150 if isinstance(self.irc_connection, ServerConnection): |
149 self.irc_connection.close('') | 151 self.irc_connection.close('') |
150 self.irc_connection = error | 152 self.irc_connection = error |
151 self.createDuplicateOnIRC() | 153 self.createDuplicateOnIRC() |
152 return | 154 return |
153 else: | 155 else: |
154 self.bridge.say('[Warning] The nickname "'+self.nickname+'" contains unauthorized characters and cannot be used in the IRC channel', log=True) | 156 self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" contains unauthorized characters and cannot be used in the IRC channel', log=True) |
155 | 157 |
156 elif error == 'nicknametoolong': | 158 elif error == 'nicknametoolong': |
157 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) | 159 self.bridge.say(say_levels.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) |
158 | 160 |
159 else: | 161 else: |
160 self.bridge.say('[Warning] unknown error while adding "'+self.nickname+'" to IRC side of bridge', log=True) | 162 self.bridge.say(say_levels.warning, 'unknown error while adding "'+self.nickname+'" to IRC side of bridge', log=True) |
161 | 163 |
162 if isinstance(self.irc_connection, ServerConnection): | 164 if isinstance(self.irc_connection, ServerConnection): |
163 self.irc_connection.close('') | 165 self.irc_connection.close('') |
164 self.irc_connection = error | 166 self.irc_connection = error |
165 | 167 |
166 | 168 |
167 def set_both_sides(self): | 169 def set_both_sides(self): |
168 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both sides of the bridge', log=True) | 170 self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" is used on both sides of the bridge', log=True) |
169 if isinstance(self.irc_connection, ServerConnection): | 171 if isinstance(self.irc_connection, ServerConnection): |
170 self.irc_connection.close('') | 172 self.irc_connection.close('') |
171 if self.irc_connection != 'both': | 173 if self.irc_connection != 'both': |
172 self.irc_connection = 'both' | 174 self.irc_connection = 'both' |
173 if isinstance(self.muc, xmpp.muc): | 175 if isinstance(self.muc, xmpp.muc): |
294 if action: | 296 if action: |
295 self.bridge.irc_connection.privmsg(self.bridge.irc_room, '* '+self.nickname+' '+message) | 297 self.bridge.irc_connection.privmsg(self.bridge.irc_room, '* '+self.nickname+' '+message) |
296 else: | 298 else: |
297 self.bridge.irc_connection.privmsg(self.bridge.irc_room, '<'+self.nickname+'> '+message) | 299 self.bridge.irc_connection.privmsg(self.bridge.irc_room, '<'+self.nickname+'> '+message) |
298 except EncodingException: | 300 except EncodingException: |
299 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding', log=True) | 301 self.bridge.say(say_levels.warning, '"'+self.nickname+'" is sending messages using an unknown encoding', log=True) |
300 | 302 |
301 | 303 |
302 def sayOnIRCTo(self, to, message): | 304 def sayOnIRCTo(self, to, message): |
303 if isinstance(self.irc_connection, ServerConnection): | 305 if isinstance(self.irc_connection, ServerConnection): |
304 try: | 306 try: |
305 self.irc_connection.privmsg(to, message) | 307 self.irc_connection.privmsg(to, message) |
306 except EncodingException: | 308 except EncodingException: |
307 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding', log=True) | 309 self.bridge.say(say_levels.warning, '"'+self.nickname+'" is sending messages using an unknown encoding', log=True) |
308 elif not isinstance(self.xmpp_c, xmpp.client.Client): | 310 elif not isinstance(self.xmpp_c, xmpp.client.Client): |
309 if self.bridge.mode != 'normal': | 311 if self.bridge.mode != 'normal': |
310 self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') | 312 self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') |
311 else: | 313 else: |
312 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.') | 314 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.') |
320 if message[:4] == '/me ': | 322 if message[:4] == '/me ': |
321 self.bridge.xmpp_room.say('* '+self.nickname+' '+message[4:]) | 323 self.bridge.xmpp_room.say('* '+self.nickname+' '+message[4:]) |
322 else: | 324 else: |
323 self.bridge.xmpp_room.say('<'+self.nickname+'> '+message) | 325 self.bridge.xmpp_room.say('<'+self.nickname+'> '+message) |
324 except EncodingException: | 326 except EncodingException: |
325 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding', log=True) | 327 self.bridge.say(say_levels.warning, '"'+self.nickname+'" is sending messages using an unknown encoding', log=True) |
326 | 328 |
327 | 329 |
328 def sayOnXMPPTo(self, to, message): | 330 def sayOnXMPPTo(self, to, message): |
329 try: | 331 try: |
330 if isinstance(self.xmpp_c, xmpp.client.Client): | 332 if isinstance(self.xmpp_c, xmpp.client.Client): |
333 if self.bridge.mode != 'normal': | 335 if self.bridge.mode != 'normal': |
334 self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') | 336 self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') |
335 else: | 337 else: |
336 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.') | 338 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.') |
337 except EncodingException: | 339 except EncodingException: |
338 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding', log=True) | 340 self.bridge.say(say_levels.warning, '"'+self.nickname+'" is sending messages using an unknown encoding', log=True) |
339 | 341 |
340 | 342 |
341 def leave(self, message): | 343 def leave(self, message): |
342 if message == None: | 344 if message == None: |
343 message = '' | 345 message = '' |