comparison participant.py @ 5:cb0daec4b778

Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sun, 16 Aug 2009 17:59:00 +0200
parents 012593ed4e12
children 7cb790f5f243
comparison
equal deleted inserted replaced
4:012593ed4e12 5:cb0daec4b778
60 if self.irc_connection != None or self.xmpp_c != None or self.protocol == 'both' or self.bridge.mode != 'normal': 60 if self.irc_connection != None or self.xmpp_c != None or self.protocol == 'both' or self.bridge.mode != 'normal':
61 return 61 return
62 if ' ' in self.nickname: 62 if ' ' in self.nickname:
63 self.bridge.bot.error('===> Debug: "'+self.nickname+'" contains a white space character, duplicate cannot be created on the IRC chan of bridge "'+str(self.bridge)+'"', debug=True) 63 self.bridge.bot.error('===> Debug: "'+self.nickname+'" contains a white space character, duplicate cannot be created on the IRC chan of bridge "'+str(self.bridge)+'"', debug=True)
64 self.bridge.say('[Warning] The nickname "'+self.nickname+'" contains a white space character, duplicate cannot be created on IRC, please avoid that if possible') 64 self.bridge.say('[Warning] The nickname "'+self.nickname+'" contains a white space character, duplicate cannot be created on IRC, please avoid that if possible')
65 if self.irc_connection:
66 self.irc_connection.close()
67 self.irc_connection = None
68 return 65 return
69 sleep(1) # try to prevent "reconnecting too fast" shit 66 sleep(1) # try to prevent "reconnecting too fast" shit
70 self.irc_connection = self.bridge.bot.irc.server() 67 self.irc_connection = self.bridge.bot.irc.server()
71 self.irc_connection.bridge = self.bridge 68 self.irc_connection.bridge = self.bridge
72 self.irc_connection.nick_callback = self._irc_nick_callback 69 self.irc_connection.nick_callback = self._irc_nick_callback
81 elif self.protocol != 'both': 78 elif self.protocol != 'both':
82 if error == 'nicknameinuse': 79 if error == 'nicknameinuse':
83 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is already used in the IRC chan of bridge "'+str(self.bridge)+'"', debug=True) 80 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is already used in the IRC chan of bridge "'+str(self.bridge)+'"', debug=True)
84 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both rooms or reserved on the IRC server, please avoid that if possible') 81 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both rooms or reserved on the IRC server, please avoid that if possible')
85 self.protocol = 'both' 82 self.protocol = 'both'
86 self.irc_connection.close() 83 self.irc_connection.closing = True
84 self.irc_connection.disconnect()
87 self.irc_connection = None 85 self.irc_connection = None
88 elif error == 'erroneusnickname': 86 elif error == 'erroneusnickname':
89 self.bridge.bot.error('===> Debug: "'+self.nickname+'" got "erroneusnickname" on bridge "'+str(self.bridge)+'"', debug=True) 87 self.bridge.bot.error('===> Debug: "'+self.nickname+'" got "erroneusnickname" on bridge "'+str(self.bridge)+'"', debug=True)
90 self.bridge.say('[Warning] The nickname "'+self.nickname+'" contains non-ASCII characters and cannot be used in the IRC channel, please avoid that if possible') 88 self.bridge.say('[Warning] The nickname "'+self.nickname+'" contains non-ASCII characters and cannot be used in the IRC channel, please avoid that if possible')
91 self.irc_connection.close() 89 self.irc_connection.closing = True
90 self.irc_connection.disconnect()
92 self.irc_connection = None 91 self.irc_connection = None
93 92
94 93
95 def _xmpp_join_callback(self, errors): 94 def _xmpp_join_callback(self, errors):
96 if len(errors) == 0: 95 if len(errors) == 0:
116 115
117 def changeNickname(self, newnick, on_protocol): 116 def changeNickname(self, newnick, on_protocol):
118 if self.protocol == 'xmpp': 117 if self.protocol == 'xmpp':
119 if on_protocol == 'xmpp': 118 if on_protocol == 'xmpp':
120 raise Exception('Internal Error: wanted to change nickname on bad protocol') 119 raise Exception('Internal Error: wanted to change nickname on bad protocol')
121 if self.irc_connection: 120 self.nickname = newnick
121 if ' ' in self.nickname:
122 self.bridge.bot.error('===> Debug: "'+self.nickname+'" contains a white space character, duplicate cannot be created on the IRC chan of bridge "'+str(self.bridge)+'"', debug=True)
123 self.bridge.say('[Warning] The nickname "'+self.nickname+'" contains a white space character, duplicate cannot be created on IRC, please avoid that if possible')
124 if self.irc_connection != None:
125 self.irc_connection.closing = True
126 self.irc_connection.disconnect()
127 self.irc_connection = None
128 return
129 if self.irc_connection != None:
122 self.irc_connection.nick(newnick) 130 self.irc_connection.nick(newnick)
123 self.nickname = newnick 131 else:
132 self.createDuplicateOnIRC()
124 elif self.protocol == 'irc': 133 elif self.protocol == 'irc':
125 if on_protocol == 'irc': 134 if on_protocol == 'irc':
126 raise Exception('Internal Error: wanted to change nickname on bad protocol') 135 raise Exception('Internal Error: wanted to change nickname on bad protocol')
136 self.nickname = newnick
127 if self.muc: 137 if self.muc:
128 self.muc.change_nick(newnick, callback=self._xmpp_join_callback) 138 self.muc.change_nick(newnick, callback=self._xmpp_join_callback)
129 self.nickname = newnick 139 else:
140 self.createDuplicateOnXMPP()
130 elif self.protocol == 'both': 141 elif self.protocol == 'both':
131 if on_protocol == 'irc': 142 if on_protocol == 'irc':
132 self.protocol = 'xmpp' 143 self.protocol = 'xmpp'
133 self.createDuplicateOnIRC() 144 self.createDuplicateOnIRC()
134 elif on_protocol == 'xmpp': 145 elif on_protocol == 'xmpp':
186 197
187 198
188 def leave(self, message): 199 def leave(self, message):
189 if message == None: 200 if message == None:
190 message = '' 201 message = ''
191 try: 202 if self.muc:
192 self.muc.leave(message) 203 self.muc.leave(message)
193 except AttributeError: 204 if self.irc_connection:
194 pass 205 self.irc_connection.closing = True
195 try:
196 self.irc_connection.disconnect(message) 206 self.irc_connection.disconnect(message)
197 except AttributeError: 207 self.irc_connection = None
198 pass
199 self.nickname = None 208 self.nickname = None
200 209
201 210
202 def __del__(self): 211 def __del__(self):
203 if self.nickname != None: 212 if self.nickname != None: