Mercurial > xib
comparison participant.py @ 98:35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sun, 04 Oct 2009 13:43:45 +0200 |
parents | f27de569f5db |
children | 23416c27b592 |
comparison
equal
deleted
inserted
replaced
97:c71861491968 | 98:35e0ddf3b13c |
---|---|
58 except xmpp.muc.NicknameConflict: | 58 except xmpp.muc.NicknameConflict: |
59 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) | 59 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) |
60 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both rooms or reserved on the XMPP server, please avoid that if possible') | 60 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both rooms or reserved on the XMPP server, please avoid that if possible') |
61 if self.muc.connected == True: | 61 if self.muc.connected == True: |
62 self.muc.leave('Changed nickname to "'+self.nickname+'"') | 62 self.muc.leave('Changed nickname to "'+self.nickname+'"') |
63 self.bridge.bot.close_xmpp_connection(self.nickname) | |
64 self.xmpp_c = None | |
65 except xmpp.muc.RoomIsFull: | 63 except xmpp.muc.RoomIsFull: |
66 self.bridge.bot.error('[Warning] XMPP MUC of bridge "'+str(self.bridge)+'" is full', send_to_admins=True) | 64 self.bridge.bot.error('[Warning] XMPP MUC of bridge "'+str(self.bridge)+'" is full', send_to_admins=True) |
67 self.bridge.say('[Warning] XMPP room is full') | 65 self.bridge.say('[Warning] XMPP room is full') |
66 | |
67 if isinstance(self.xmpp_c, xmpp.client.Client): | |
68 self.bridge.bot.close_xmpp_connection(self.nickname) | 68 self.bridge.bot.close_xmpp_connection(self.nickname) |
69 self.xmpp_c = None | 69 self.xmpp_c = None |
70 | 70 |
71 | 71 |
72 def createDuplicateOnIRC(self): | 72 def createDuplicateOnIRC(self): |
83 self.bridge.bot.error('===> Debug: "'+self.nickname+'" duplicate succesfully created on IRC side of bridge "'+str(self.bridge)+'"', debug=True) | 83 self.bridge.bot.error('===> Debug: "'+self.nickname+'" duplicate succesfully created on IRC side of bridge "'+str(self.bridge)+'"', debug=True) |
84 elif self.irc_connection != 'both': | 84 elif self.irc_connection != 'both': |
85 if error == 'nicknameinuse': | 85 if error == 'nicknameinuse': |
86 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is used or reserved on the IRC server of bridge "'+str(self.bridge)+'"', debug=True) | 86 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is used or reserved on the IRC server of bridge "'+str(self.bridge)+'"', debug=True) |
87 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used or reserved on the IRC server, please avoid that if possible') | 87 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used or reserved on the IRC server, please avoid that if possible') |
88 if isinstance(self.irc_connection, ServerConnection): | |
89 self.irc_connection.close('') | |
90 self.irc_connection = error | |
91 elif error == 'nickcollision': | 88 elif error == 'nickcollision': |
92 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is used or reserved on the IRC server of bridge "'+str(self.bridge)+'"', debug=True) | 89 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is used or reserved on the IRC server of bridge "'+str(self.bridge)+'"', debug=True) |
93 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used or reserved on the IRC server, please avoid that if possible') | 90 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used or reserved on the IRC server, please avoid that if possible') |
94 if isinstance(self.irc_connection, ServerConnection): | |
95 self.irc_connection.close('') | |
96 self.irc_connection = error | |
97 elif error == 'erroneusnickname': | 91 elif error == 'erroneusnickname': |
98 self.bridge.bot.error('===> Debug: "'+self.nickname+'" got "erroneusnickname" on bridge "'+str(self.bridge)+'"', debug=True) | 92 self.bridge.bot.error('===> Debug: "'+self.nickname+'" got "erroneusnickname" on bridge "'+str(self.bridge)+'"', debug=True) |
99 self.bridge.say('[Warning] The nickname "'+self.nickname+'" contains unauthorized characters and cannot be used in the IRC channel, please avoid that if possible') | 93 self.bridge.say('[Warning] The nickname "'+self.nickname+'" contains unauthorized characters and cannot be used in the IRC channel, please avoid that if possible') |
100 if isinstance(self.irc_connection, ServerConnection): | |
101 self.irc_connection.close('') | |
102 self.irc_connection = error | |
103 elif error == 'nicknametoolong': | 94 elif error == 'nicknametoolong': |
104 self.bridge.bot.error('===> Debug: "'+self.nickname+'" got "nicknametoolong" on bridge "'+str(self.bridge)+'"', debug=True) | 95 self.bridge.bot.error('===> Debug: "'+self.nickname+'" got "nicknametoolong" on bridge "'+str(self.bridge)+'"', debug=True) |
105 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') | 96 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') |
106 if isinstance(self.irc_connection, ServerConnection): | |
107 self.irc_connection.close('') | |
108 self.irc_connection = error | |
109 else: | 97 else: |
110 self.bridge.bot.error('===> Debug: unknown error while adding "'+self.nickname+'" to IRC side of bridge "'+str(self.bridge)+'"', debug=True) | 98 self.bridge.bot.error('===> Debug: unknown error while adding "'+self.nickname+'" to IRC side of bridge "'+str(self.bridge)+'"', debug=True) |
111 self.bridge.say('[Warning] unknown error while adding "'+self.nickname+'" to IRC side of bridge') | 99 self.bridge.say('[Warning] unknown error while adding "'+self.nickname+'" to IRC side of bridge') |
112 if isinstance(self.irc_connection, ServerConnection): | 100 |
113 self.irc_connection.close('') | 101 if isinstance(self.irc_connection, ServerConnection): |
114 self.irc_connection = error | 102 self.irc_connection.close('') |
103 self.irc_connection = error | |
115 | 104 |
116 | 105 |
117 def changeNickname(self, newnick, on_protocol): | 106 def changeNickname(self, newnick, on_protocol): |
118 """Change participant's nickname.""" | 107 """Change participant's nickname.""" |
119 | 108 |
125 self.irc_connection = 'unwanted nick change' | 114 self.irc_connection = 'unwanted nick change' |
126 | 115 |
127 else: | 116 else: |
128 self.nickname = newnick | 117 self.nickname = newnick |
129 if isinstance(self.irc_connection, ServerConnection): | 118 if isinstance(self.irc_connection, ServerConnection): |
130 self.irc_connection.nick(newnick, callback=self._irc_nick_callback) | 119 if self.irc_connection.used_by == 1: |
131 else: | 120 self.irc_connection.nick(newnick, callback=self._irc_nick_callback) |
121 else: | |
122 self._close_irc_connection(self, 'Changed nickname') | |
123 self.createDuplicateOnIRC() | |
124 else: | |
125 if self.irc_connection == 'both': | |
126 self.bridge.addParticipant('irc', oldnick) | |
132 self.createDuplicateOnIRC() | 127 self.createDuplicateOnIRC() |
133 | 128 |
134 elif self.protocol == 'irc': | 129 elif self.protocol == 'irc': |
135 if on_protocol == 'irc': | 130 if on_protocol == 'irc': |
136 self._close_xmpp_connection('unwanted nick change') | 131 self._close_xmpp_connection('unwanted nick change') |
137 self.xmpp_c = 'unwanted nick change' | 132 self.xmpp_c = 'unwanted nick change' |
138 | 133 |
139 else: | 134 else: |
140 self.nickname = newnick | 135 self.nickname = newnick |
141 if self.muc != None: | 136 if isinstance(self.xmpp_c, xmpp.client.Client): |
142 for b in self.bridge.bot.bridges: | 137 for b in self.bridge.bot.bridges: |
143 if b.hasParticipant(oldnick) and b.irc_server != self.bridge.irc_server: | 138 if b.hasParticipant(oldnick) and b.irc_server != self.bridge.irc_server: |
144 self.muc.leave(message='Changed nickname to "'+self.nickname+'"') | 139 self.muc.leave(message='Changed nickname to "'+self.nickname+'"') |
145 self.xmpp_c = None | 140 self.xmpp_c = None |
146 self.bridge.bot.close_xmpp_connection(oldnick) | 141 self.bridge.bot.close_xmpp_connection(oldnick) |
152 self.bridge.bot.xmpp_connections.pop(oldnick) | 147 self.bridge.bot.xmpp_connections.pop(oldnick) |
153 self.bridge.bot.xmpp_connections[newnick] = self.xmpp_c | 148 self.bridge.bot.xmpp_connections[newnick] = self.xmpp_c |
154 | 149 |
155 self.muc.change_nick(newnick, status='From IRC', callback=self._xmpp_join_callback) | 150 self.muc.change_nick(newnick, status='From IRC', callback=self._xmpp_join_callback) |
156 else: | 151 else: |
152 if self.xmpp_c == 'both': | |
153 self.bridge.addParticipant('xmpp', oldnick) | |
157 self.createDuplicateOnXMPP() | 154 self.createDuplicateOnXMPP() |
158 | 155 |
159 | 156 |
160 def sayOnIRC(self, message): | 157 def sayOnIRC(self, message): |
161 try: | 158 try: |
245 if self.irc_connection.used_by < 1: | 242 if self.irc_connection.used_by < 1: |
246 self.irc_connection.close(message) | 243 self.irc_connection.close(message) |
247 self.irc_connection = None | 244 self.irc_connection = None |
248 | 245 |
249 | 246 |
247 def __str__(self): | |
248 r = 'self.protocol='+str(self.protocol)+'\n'+'self.nickname='+str(self.nickname) | |
249 if isinstance(self.irc_connection, ServerConnection): | |
250 r += '\nself.irc_connection='+str(self.irc_connection)+'\n'+'self.irc_connection.really_connected='+str(self.irc_connection.really_connected) | |
251 if isinstance(self.xmpp_c, xmpp.client.Client): | |
252 r += '\nself.muc.connected='+str(self.muc.connected) | |
253 return r | |
254 | |
255 | |
250 def __del__(self): | 256 def __del__(self): |
251 if self.nickname != None: | 257 if self.nickname != None: |
252 self.leave('') | 258 self.leave('') |