Mercurial > xib
annotate participant.py @ 275:09a5bde70919 default tip master
minor fix in Participant
Signed-off-by: Changaco <changaco ατ changaco δοτ net>
author | Changaco <changaco ατ changaco δοτ net> |
---|---|
date | Wed, 05 May 2010 23:36:13 +0200 |
parents | d04e40b7be2e |
children |
rev | line source |
---|---|
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
3 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
4 # This program is free software: you can redistribute it and/or modify |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
5 # it under the terms of the GNU General Public License as published by |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
6 # the Free Software Foundation, either version 3 of the License, or |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
7 # (at your option) any later version. |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
8 # |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
9 # This program is distributed in the hope that it will be useful, |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
12 # GNU General Public License for more details. |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
13 # |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
14 # You should have received a copy of the GNU General Public License |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
15 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
16 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
17 |
124 | 18 import re |
19 from time import sleep | |
20 | |
272
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
21 import irclib |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
22 import muc |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
23 xmpp = muc.xmpp |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
24 del muc |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
25 |
180
102f895347ff
added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents:
174
diff
changeset
|
26 import say_levels |
102f895347ff
added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents:
174
diff
changeset
|
27 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
28 |
124 | 29 class Participant: |
103 | 30 def __init__(self, owner_bridge, protocol, nickname, real_jid=None): |
31 self.bot_admin = False | |
32 self.real_jid = real_jid | |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
33 self.bridge = owner_bridge |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
34 self.protocol = protocol |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
35 self.nickname = nickname |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
36 self.duplicate_nickname = self.nickname |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
37 self.irc_connection = None |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
38 self.xmpp_c = None |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
11
diff
changeset
|
39 self.muc = None |
189
e04410e7e527
split the leaving process in two, first call to Bridge.removeParticipant() calls Participant.leave(), second call (when the bot receives the part or quit event) removes it from Bridge.participants
Charly COSTE <changaco@changaco.net>
parents:
185
diff
changeset
|
40 self.left = False |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
41 if protocol == 'xmpp' and self.bridge.mode in ['normal', 'bypass']: |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
42 self.create_duplicate_on_irc() |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
43 elif protocol == 'irc' and self.bridge.mode != 'minimal': |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
44 self.create_duplicate_on_xmpp() |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
45 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
46 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
47 def _get_new_duplicate_nickname(self): |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
48 new_duplicate_nickname = self.duplicate_nickname |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
49 for i in xrange(5): |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
50 new_duplicate_nickname = new_duplicate_nickname+'_' |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
51 if not self.bridge.has_participant(new_duplicate_nickname): |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
52 return new_duplicate_nickname |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
53 return None |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
54 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
55 |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
56 def create_duplicate_on_xmpp(self): |
272
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
57 if isinstance(self.xmpp_c, xmpp.client.Client) or isinstance(self.irc_connection, irclib.ServerConnection): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
58 return |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
59 self.xmpp_c = self.bridge.bot.get_xmpp_connection(self.duplicate_nickname) |
103 | 60 self.muc = xmpp.muc(self.bridge.xmpp_room_jid) |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
61 self.join_muc() |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
62 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
63 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
64 def join_muc(self): |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
65 self.muc.join(self.xmpp_c, self.duplicate_nickname, status='From IRC', callback=self._xmpp_join_callback) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
66 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
67 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
68 def _xmpp_join_callback(self, errors): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
69 if len(errors) == 0: |
180
102f895347ff
added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents:
174
diff
changeset
|
70 m = '"'+self.nickname+'" duplicate succesfully created on XMPP side of bridge "'+str(self.bridge)+'"' |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
71 if self.nickname != self.duplicate_nickname: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
72 m += ' using nickname "'+self.duplicate_nickname+'"' |
180
102f895347ff
added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents:
174
diff
changeset
|
73 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') |
102f895347ff
added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents:
174
diff
changeset
|
74 self.bridge.bot.error(3, m, debug=True) |
82
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
75 elif self.xmpp_c != 'both': |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
76 for error in errors: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
77 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
78 raise error |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
79 except xmpp.muc.NicknameConflict as e: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
80 if xmpp.protocol.JID(e.args[0]).getResource() != self.duplicate_nickname: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
81 return |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
82 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
83 if self.bridge.mode == 'bypass': |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
84 new_duplicate_nickname = self._get_new_duplicate_nickname() |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
85 if new_duplicate_nickname != None: |
180
102f895347ff
added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents:
174
diff
changeset
|
86 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) |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
87 if self.duplicate_nickname == self.nickname: |
180
102f895347ff
added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents:
174
diff
changeset
|
88 self.bridge.say(say_levels.info, 'The nickname "'+self.duplicate_nickname+'" is used on both rooms or reserved on the XMPP server') |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
89 self.duplicate_nickname = new_duplicate_nickname |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
90 if isinstance(self.xmpp_c, xmpp.client.Client): |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
91 self.bridge.bot.close_xmpp_connection(self.nickname) |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
92 self.xmpp_c = None |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
93 self.create_duplicate_on_xmpp() |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
94 return |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
95 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
96 else: |
180
102f895347ff
added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents:
174
diff
changeset
|
97 self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" is used on both rooms or reserved on the XMPP server', log=True) |
254
3b930e2fad43
minor fix in Participant
Charly COSTE <changaco@changaco.net>
parents:
252
diff
changeset
|
98 if isinstance(self.muc, xmpp.muc): |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
99 self.muc.leave('Changed nickname to "'+self.nickname+'"') |
82
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
100 except xmpp.muc.RoomIsFull: |
180
102f895347ff
added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents:
174
diff
changeset
|
101 self.bridge.say(say_levels.warning, 'XMPP room is full', log=True) |
135
922858915907
handle xmpp.muc.RemoteServerNotFound
Charly COSTE <changaco@changaco.net>
parents:
132
diff
changeset
|
102 except xmpp.muc.RemoteServerNotFound: |
922858915907
handle xmpp.muc.RemoteServerNotFound
Charly COSTE <changaco@changaco.net>
parents:
132
diff
changeset
|
103 self.bridge._RemoteServerNotFound_handler() |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
104 |
275
09a5bde70919
minor fix in Participant
Changaco <changaco ατ changaco δοτ net>
parents:
272
diff
changeset
|
105 self._close_xmpp_connection('') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
106 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
107 |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
108 def create_duplicate_on_irc(self): |
272
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
109 if isinstance(self.xmpp_c, xmpp.client.Client) or isinstance(self.irc_connection, irclib.ServerConnection): |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
11
diff
changeset
|
110 return |
125
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
111 self.irc_connection = self.bridge.bot.irc.open_connection(self.bridge.irc_server, self.bridge.irc_port, self.duplicate_nickname) |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
11
diff
changeset
|
112 self.irc_connection.connect(nick_callback=self._irc_nick_callback) |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
11
diff
changeset
|
113 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
11
diff
changeset
|
114 |
231
5f1e9211af03
fix for 48ad162772b79740e8ff580bde2c250b9957c126, we do need arguments in nick callbacks
Charly COSTE <changaco@changaco.net>
parents:
229
diff
changeset
|
115 def _irc_nick_callback(self, error, arguments=None): |
226
0d85049ac68d
switch to IRC join callbacks in bridge.py and participant.py
Charly COSTE <changaco@changaco.net>
parents:
219
diff
changeset
|
116 if not error: |
0d85049ac68d
switch to IRC join callbacks in bridge.py and participant.py
Charly COSTE <changaco@changaco.net>
parents:
219
diff
changeset
|
117 self.irc_connection.join(self.bridge.irc_room, callback=self._irc_join_callback) |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
118 |
82
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
119 elif self.irc_connection != 'both': |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
120 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
121 if error in ['nicknameinuse', 'nickcollision']: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
122 if arguments[0].arguments()[0] != self.duplicate_nickname: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
123 return |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
124 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
125 if self.bridge.mode == 'bypass': |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
126 new_duplicate_nickname = self._get_new_duplicate_nickname() |
231
5f1e9211af03
fix for 48ad162772b79740e8ff580bde2c250b9957c126, we do need arguments in nick callbacks
Charly COSTE <changaco@changaco.net>
parents:
229
diff
changeset
|
127 if new_duplicate_nickname: |
180
102f895347ff
added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents:
174
diff
changeset
|
128 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) |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
129 if self.duplicate_nickname == self.nickname: |
180
102f895347ff
added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents:
174
diff
changeset
|
130 self.bridge.say(say_levels.info, 'The nickname "'+self.duplicate_nickname+'" is used or reserved on the IRC server') |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
131 self.duplicate_nickname = new_duplicate_nickname |
272
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
132 if isinstance(self.irc_connection, irclib.ServerConnection): |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
133 self.irc_connection.close('') |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
134 self.irc_connection = error |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
135 self.create_duplicate_on_irc() |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
136 return |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
137 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
138 else: |
180
102f895347ff
added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents:
174
diff
changeset
|
139 self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" is used or reserved on the IRC server', log=True) |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
140 |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
11
diff
changeset
|
141 elif error == 'erroneusnickname': |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
142 if self.bridge.mode == 'bypass': |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
143 self.duplicate_nickname = re.sub('[^a-zA-Z]', '', self.nickname) |
272
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
144 if isinstance(self.irc_connection, irclib.ServerConnection): |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
145 self.irc_connection.close('') |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
146 self.irc_connection = error |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
147 self.create_duplicate_on_irc() |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
148 return |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
149 else: |
180
102f895347ff
added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents:
174
diff
changeset
|
150 self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" contains unauthorized characters and cannot be used in the IRC channel', log=True) |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
151 |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
11
diff
changeset
|
152 elif error == 'nicknametoolong': |
219
63289aa1dea7
moved "nicknametoolong" and ServerConnection.really_connected handling to irclib, renamed ServerConnection.really_connected to .logged_in
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
153 self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" is too long (limit seems to be '+str(len(self.irc_connection.real_nickname))+') and cannot be used in the IRC channel', log=True) |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
154 |
82
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
155 else: |
180
102f895347ff
added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents:
174
diff
changeset
|
156 self.bridge.say(say_levels.warning, 'unknown error while adding "'+self.nickname+'" to IRC side of bridge', log=True) |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
157 |
272
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
158 if isinstance(self.irc_connection, irclib.ServerConnection): |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
159 self.irc_connection.close('') |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
160 self.irc_connection = error |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
161 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
162 |
226
0d85049ac68d
switch to IRC join callbacks in bridge.py and participant.py
Charly COSTE <changaco@changaco.net>
parents:
219
diff
changeset
|
163 def _irc_join_callback(self, channel, error): |
0d85049ac68d
switch to IRC join callbacks in bridge.py and participant.py
Charly COSTE <changaco@changaco.net>
parents:
219
diff
changeset
|
164 if not error: |
0d85049ac68d
switch to IRC join callbacks in bridge.py and participant.py
Charly COSTE <changaco@changaco.net>
parents:
219
diff
changeset
|
165 m = '"'+self.nickname+'" duplicate succesfully joined IRC side of bridge "'+str(self.bridge)+'"' |
0d85049ac68d
switch to IRC join callbacks in bridge.py and participant.py
Charly COSTE <changaco@changaco.net>
parents:
219
diff
changeset
|
166 if self.nickname != self.duplicate_nickname: |
0d85049ac68d
switch to IRC join callbacks in bridge.py and participant.py
Charly COSTE <changaco@changaco.net>
parents:
219
diff
changeset
|
167 m += ' using nickname "'+self.duplicate_nickname+'"' |
0d85049ac68d
switch to IRC join callbacks in bridge.py and participant.py
Charly COSTE <changaco@changaco.net>
parents:
219
diff
changeset
|
168 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') |
0d85049ac68d
switch to IRC join callbacks in bridge.py and participant.py
Charly COSTE <changaco@changaco.net>
parents:
219
diff
changeset
|
169 self.bridge.bot.error(3, m, debug=True) |
0d85049ac68d
switch to IRC join callbacks in bridge.py and participant.py
Charly COSTE <changaco@changaco.net>
parents:
219
diff
changeset
|
170 |
0d85049ac68d
switch to IRC join callbacks in bridge.py and participant.py
Charly COSTE <changaco@changaco.net>
parents:
219
diff
changeset
|
171 elif self.irc_connection != 'both': |
0d85049ac68d
switch to IRC join callbacks in bridge.py and participant.py
Charly COSTE <changaco@changaco.net>
parents:
219
diff
changeset
|
172 self._close_irc_connection('') |
0d85049ac68d
switch to IRC join callbacks in bridge.py and participant.py
Charly COSTE <changaco@changaco.net>
parents:
219
diff
changeset
|
173 self.irc_connection = error |
0d85049ac68d
switch to IRC join callbacks in bridge.py and participant.py
Charly COSTE <changaco@changaco.net>
parents:
219
diff
changeset
|
174 |
0d85049ac68d
switch to IRC join callbacks in bridge.py and participant.py
Charly COSTE <changaco@changaco.net>
parents:
219
diff
changeset
|
175 |
123
75a03f10a863
Code refactoring (new method participant.set_both_sides())
Charly COSTE <changaco@changaco.net>
parents:
118
diff
changeset
|
176 def set_both_sides(self): |
180
102f895347ff
added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents:
174
diff
changeset
|
177 self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" is used on both sides of the bridge', log=True) |
272
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
178 if isinstance(self.irc_connection, irclib.ServerConnection): |
123
75a03f10a863
Code refactoring (new method participant.set_both_sides())
Charly COSTE <changaco@changaco.net>
parents:
118
diff
changeset
|
179 self.irc_connection.close('') |
75a03f10a863
Code refactoring (new method participant.set_both_sides())
Charly COSTE <changaco@changaco.net>
parents:
118
diff
changeset
|
180 if self.irc_connection != 'both': |
75a03f10a863
Code refactoring (new method participant.set_both_sides())
Charly COSTE <changaco@changaco.net>
parents:
118
diff
changeset
|
181 self.irc_connection = 'both' |
75a03f10a863
Code refactoring (new method participant.set_both_sides())
Charly COSTE <changaco@changaco.net>
parents:
118
diff
changeset
|
182 if isinstance(self.muc, xmpp.muc): |
75a03f10a863
Code refactoring (new method participant.set_both_sides())
Charly COSTE <changaco@changaco.net>
parents:
118
diff
changeset
|
183 self.muc.leave('') |
75a03f10a863
Code refactoring (new method participant.set_both_sides())
Charly COSTE <changaco@changaco.net>
parents:
118
diff
changeset
|
184 self.bridge.bot.close_xmpp_connection(self.nickname) |
75a03f10a863
Code refactoring (new method participant.set_both_sides())
Charly COSTE <changaco@changaco.net>
parents:
118
diff
changeset
|
185 if self.xmpp_c != 'both': |
75a03f10a863
Code refactoring (new method participant.set_both_sides())
Charly COSTE <changaco@changaco.net>
parents:
118
diff
changeset
|
186 self.xmpp_c = 'both' |
75a03f10a863
Code refactoring (new method participant.set_both_sides())
Charly COSTE <changaco@changaco.net>
parents:
118
diff
changeset
|
187 |
75a03f10a863
Code refactoring (new method participant.set_both_sides())
Charly COSTE <changaco@changaco.net>
parents:
118
diff
changeset
|
188 |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
189 def change_nickname(self, newnick, on_protocol): |
29 | 190 """Change participant's nickname.""" |
191 | |
145
ddc87b605019
minor fix in Participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
137
diff
changeset
|
192 p = None |
29 | 193 oldnick = self.nickname |
194 | |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
195 if self.protocol == 'xmpp': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
196 if on_protocol == 'xmpp': |
94
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
197 self._close_irc_connection('unwanted nick change') |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
198 self.irc_connection = 'unwanted nick change' |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
11
diff
changeset
|
199 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
11
diff
changeset
|
200 else: |
125
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
201 try: |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
202 p = self.bridge.get_participant(newnick) |
125
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
203 except self.bridge.NoSuchParticipantException: |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
204 self.nickname = newnick |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
205 self.duplicate_nickname = newnick |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
206 has_connection = self.bridge.bot.irc.has_connection(self.bridge.irc_server, self.bridge.irc_port, self.duplicate_nickname) |
272
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
207 if isinstance(self.irc_connection, irclib.ServerConnection): |
125
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
208 if not has_connection and self.irc_connection.used_by == 1: |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
209 self.irc_connection.nick(newnick, callback=self._irc_nick_callback) |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
210 else: |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
211 self._close_irc_connection('Changed nickname') |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
212 self.create_duplicate_on_irc() |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
213 else: |
125
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
214 if self.irc_connection == 'both': |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
215 self.bridge.add_participant('irc', oldnick) |
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
216 self.create_duplicate_on_irc() |
125
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
217 return |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
11
diff
changeset
|
218 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
219 elif self.protocol == 'irc': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
220 if on_protocol == 'irc': |
94
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
221 self._close_xmpp_connection('unwanted nick change') |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
222 self.xmpp_c = 'unwanted nick change' |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
11
diff
changeset
|
223 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
11
diff
changeset
|
224 else: |
125
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
225 try: |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
226 p = self.bridge.get_participant(newnick) |
125
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
227 except self.bridge.NoSuchParticipantException: |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
228 self.nickname = newnick |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
229 self.duplicate_nickname = newnick |
248
234e8ca6a10c
in Participant, test isinstance(self.muc, xmpp.muc) before using self.muc
Charly COSTE <changaco@changaco.net>
parents:
247
diff
changeset
|
230 if isinstance(self.muc, xmpp.muc): |
125
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
231 for b in self.bridge.bot.bridges: |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
232 if b.has_participant(oldnick) and b.irc_server != self.bridge.irc_server: |
125
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
233 self.muc.leave(message='Changed nickname to "'+self.nickname+'"') |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
234 self.xmpp_c = None |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
235 self.bridge.bot.close_xmpp_connection(oldnick) |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
236 self.create_duplicate_on_xmpp() |
125
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
237 return |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
238 |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
239 if not self.bridge.bot.xmpp_connections.has_key(newnick): |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
240 if self.bridge.bot.xmpp_connections.has_key(oldnick): |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
241 self.bridge.bot.xmpp_connections.pop(oldnick) |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
242 self.bridge.bot.xmpp_connections[newnick] = self.xmpp_c |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
243 |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
244 self.muc.change_nick(newnick, status='From IRC', callback=self._xmpp_join_callback) |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
245 else: |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
246 if self.xmpp_c == 'both': |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
247 self.bridge.add_participant('xmpp', oldnick) |
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
248 self.create_duplicate_on_xmpp() |
125
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
249 return |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
250 |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
251 self.nickname = newnick |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
252 self.duplicate_nickname = newnick |
145
ddc87b605019
minor fix in Participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
137
diff
changeset
|
253 |
ddc87b605019
minor fix in Participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
137
diff
changeset
|
254 if not isinstance(p, Participant): |
ddc87b605019
minor fix in Participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
137
diff
changeset
|
255 return |
ddc87b605019
minor fix in Participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
137
diff
changeset
|
256 |
125
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
257 if p.nickname == newnick: |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
258 if p.protocol == self.protocol: |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
259 # should never happen |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
260 raise Exception('WTF ?') |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
261 else: |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
262 self.set_both_sides() |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
263 elif p.duplicate_nickname == newnick: |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
264 if p.protocol != self.protocol: |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
265 # should never happen |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
266 raise Exception('WTF ?') |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
267 else: |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
268 if self.protocol == 'xmpp': |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
269 self.irc_connection = p.irc_connection |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
270 p.irc_connection = None |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
11
diff
changeset
|
271 else: |
125
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
272 self.xmpp_c = p.xmpp_c |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
273 self.muc = p.muc |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
274 p.xmpp_c = None |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
275 p.muc = None |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
276 p.duplicate_nickname = p._get_new_duplicate_nickname() |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
277 p.create_duplicate_on_xmpp() |
125
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
278 else: |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
279 # should never happen |
efdc038e757a
fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents:
124
diff
changeset
|
280 raise Exception('WTF ?') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
281 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
282 |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
283 def say_on_irc(self, message): |
185
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
284 bot_say = False |
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
285 if message[:4] == '/me ': |
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
286 action = True |
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
287 message = message[4:] |
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
288 else: |
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
289 action = False |
272
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
290 if isinstance(self.irc_connection, irclib.ServerConnection): |
185
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
291 try: |
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
292 if action: |
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
293 self.irc_connection.action(self.bridge.irc_room, message) |
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
294 else: |
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
295 self.irc_connection.privmsg(self.bridge.irc_room, message) |
272
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
296 except irclib.ServerNotConnectedError: |
185
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
297 self.irc_connection.connect() |
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
298 bot_say = True |
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
299 elif not isinstance(self.xmpp_c, xmpp.client.Client): |
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
300 bot_say = True |
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
301 if bot_say: |
213
fbe40b397f67
created Bridge.say_on_behalf in order to avoid code repetition in participant.py
Charly COSTE <changaco@changaco.net>
parents:
203
diff
changeset
|
302 self.bridge.say_on_behalf(self.nickname, message, 'irc', action=action) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
303 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
304 |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
200
diff
changeset
|
305 def say_on_irc_to(self, to, message): |
247
303e571bc104
catch ServerNotConnectedError in Participant.say_on_irc_to
Charly COSTE <changaco@changaco.net>
parents:
245
diff
changeset
|
306 error = False |
272
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
307 if isinstance(self.irc_connection, irclib.ServerConnection): |
247
303e571bc104
catch ServerNotConnectedError in Participant.say_on_irc_to
Charly COSTE <changaco@changaco.net>
parents:
245
diff
changeset
|
308 try: |
303e571bc104
catch ServerNotConnectedError in Participant.say_on_irc_to
Charly COSTE <changaco@changaco.net>
parents:
245
diff
changeset
|
309 self.irc_connection.privmsg(to, message) |
272
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
310 except irclib.ServerNotConnectedError: |
247
303e571bc104
catch ServerNotConnectedError in Participant.say_on_irc_to
Charly COSTE <changaco@changaco.net>
parents:
245
diff
changeset
|
311 self.irc_connection.connect() |
303e571bc104
catch ServerNotConnectedError in Participant.say_on_irc_to
Charly COSTE <changaco@changaco.net>
parents:
245
diff
changeset
|
312 error = True |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
313 elif not isinstance(self.xmpp_c, xmpp.client.Client): |
247
303e571bc104
catch ServerNotConnectedError in Participant.say_on_irc_to
Charly COSTE <changaco@changaco.net>
parents:
245
diff
changeset
|
314 error = True |
303e571bc104
catch ServerNotConnectedError in Participant.say_on_irc_to
Charly COSTE <changaco@changaco.net>
parents:
245
diff
changeset
|
315 |
303e571bc104
catch ServerNotConnectedError in Participant.say_on_irc_to
Charly COSTE <changaco@changaco.net>
parents:
245
diff
changeset
|
316 if error: |
229
a434b73bde51
added optional "action" argument to Participant.say_on_xmpp_to and muc.say_to
Charly COSTE <changaco@changaco.net>
parents:
226
diff
changeset
|
317 if self.bridge.mode not in ['normal', 'bypass']: |
a434b73bde51
added optional "action" argument to Participant.say_on_xmpp_to and muc.say_to
Charly COSTE <changaco@changaco.net>
parents:
226
diff
changeset
|
318 self.bridge.get_participant(to).say_on_xmpp_to(self.nickname, 'XIB error: Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') |
26
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
319 else: |
229
a434b73bde51
added optional "action" argument to Participant.say_on_xmpp_to and muc.say_to
Charly COSTE <changaco@changaco.net>
parents:
226
diff
changeset
|
320 self.bridge.get_participant(to).say_on_xmpp_to(self.nickname, 'XIB error: Sorry but you cannot send cross-protocol private messages because I don\'t have an IRC duplicate with your nickname.') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
321 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
322 |
213
fbe40b397f67
created Bridge.say_on_behalf in order to avoid code repetition in participant.py
Charly COSTE <changaco@changaco.net>
parents:
203
diff
changeset
|
323 def say_on_xmpp(self, message, action=False): |
259
3b318108e9e0
(muc) created "state" attribute to replace the "connected" one
Charly COSTE <changaco@changaco.net>
parents:
254
diff
changeset
|
324 if isinstance(self.muc, xmpp.muc) and self.muc.state == self.muc.JOINED: |
213
fbe40b397f67
created Bridge.say_on_behalf in order to avoid code repetition in participant.py
Charly COSTE <changaco@changaco.net>
parents:
203
diff
changeset
|
325 self.muc.say(message, action=action) |
272
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
326 elif not isinstance(self.irc_connection, irclib.ServerConnection): |
213
fbe40b397f67
created Bridge.say_on_behalf in order to avoid code repetition in participant.py
Charly COSTE <changaco@changaco.net>
parents:
203
diff
changeset
|
327 self.bridge.say_on_behalf(self.nickname, message, 'xmpp', action=action) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
328 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
329 |
229
a434b73bde51
added optional "action" argument to Participant.say_on_xmpp_to and muc.say_to
Charly COSTE <changaco@changaco.net>
parents:
226
diff
changeset
|
330 def say_on_xmpp_to(self, to, message, action=False): |
259
3b318108e9e0
(muc) created "state" attribute to replace the "connected" one
Charly COSTE <changaco@changaco.net>
parents:
254
diff
changeset
|
331 if isinstance(self.muc, xmpp.muc) and self.muc.state == self.muc.JOINED: |
229
a434b73bde51
added optional "action" argument to Participant.say_on_xmpp_to and muc.say_to
Charly COSTE <changaco@changaco.net>
parents:
226
diff
changeset
|
332 self.muc.say_to(to, message, action=action) |
272
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
333 elif not isinstance(self.irc_connection, irclib.ServerConnection): |
229
a434b73bde51
added optional "action" argument to Participant.say_on_xmpp_to and muc.say_to
Charly COSTE <changaco@changaco.net>
parents:
226
diff
changeset
|
334 if self.bridge.mode not in ['normal', 'bypass']: |
a434b73bde51
added optional "action" argument to Participant.say_on_xmpp_to and muc.say_to
Charly COSTE <changaco@changaco.net>
parents:
226
diff
changeset
|
335 self.bridge.get_participant(to).say_on_xmpp_to(self.nickname, 'XIB error: Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') |
185
6173873c6b0d
minor fix in participant.py, encoding is handled in irclib since cbaab9cc23f8097dbe647d5ea6d982b1c9e49b19
Charly COSTE <changaco@changaco.net>
parents:
180
diff
changeset
|
336 else: |
229
a434b73bde51
added optional "action" argument to Participant.say_on_xmpp_to and muc.say_to
Charly COSTE <changaco@changaco.net>
parents:
226
diff
changeset
|
337 self.bridge.get_participant(to).say_on_xmpp_to(self.nickname, 'XIB error: Sorry but you cannot send cross-protocol private messages because I don\'t have an XMPP duplicate with your nickname.') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
338 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
339 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
340 def leave(self, message): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
341 if message == None: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
342 message = '' |
189
e04410e7e527
split the leaving process in two, first call to Bridge.removeParticipant() calls Participant.leave(), second call (when the bot receives the part or quit event) removes it from Bridge.participants
Charly COSTE <changaco@changaco.net>
parents:
185
diff
changeset
|
343 self.left = True |
94
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
344 self._close_xmpp_connection(message) |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
345 self._close_irc_connection(message) |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
346 |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
347 |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
348 def _close_xmpp_connection(self, message): |
248
234e8ca6a10c
in Participant, test isinstance(self.muc, xmpp.muc) before using self.muc
Charly COSTE <changaco@changaco.net>
parents:
247
diff
changeset
|
349 if isinstance(self.muc, xmpp.muc): |
172
64a0e9636ae6
removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
350 self.muc.leave(message) |
132
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
125
diff
changeset
|
351 self.xmpp_c = None |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
11
diff
changeset
|
352 self.bridge.bot.close_xmpp_connection(self.nickname) |
94
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
353 |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
354 |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
355 def _close_irc_connection(self, message): |
272
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
356 if isinstance(self.irc_connection, irclib.ServerConnection): |
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
357 try: |
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
358 self.irc_connection.part(self.bridge.irc_room, message=message) |
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
359 except irclib.UnknownChannel: |
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
360 pass |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
11
diff
changeset
|
361 self.irc_connection.used_by -= 1 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
11
diff
changeset
|
362 if self.irc_connection.used_by < 1: |
64
8fc496eaa17b
Handle IRC "nickcollision" event
Charly COSTE <changaco@changaco.net>
parents:
63
diff
changeset
|
363 self.irc_connection.close(message) |
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
Charly COSTE <changaco@changaco.net>
parents:
4
diff
changeset
|
364 self.irc_connection = None |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
365 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
366 |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
367 def __str__(self): |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
368 r = 'self.protocol='+str(self.protocol)+'\n'+'self.nickname='+str(self.nickname) |
272
d04e40b7be2e
catch irclib.UnknownChannel in Participant._close_irc_connection
Charly COSTE <changaco@changaco.net>
parents:
260
diff
changeset
|
369 if isinstance(self.irc_connection, irclib.ServerConnection): |
219
63289aa1dea7
moved "nicknametoolong" and ServerConnection.really_connected handling to irclib, renamed ServerConnection.really_connected to .logged_in
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
370 r += '\nself.irc_connection='+str(self.irc_connection)+'\n'+'self.irc_connection.logged_in='+str(self.irc_connection.logged_in) |
248
234e8ca6a10c
in Participant, test isinstance(self.muc, xmpp.muc) before using self.muc
Charly COSTE <changaco@changaco.net>
parents:
247
diff
changeset
|
371 if isinstance(self.muc, xmpp.muc): |
259
3b318108e9e0
(muc) created "state" attribute to replace the "connected" one
Charly COSTE <changaco@changaco.net>
parents:
254
diff
changeset
|
372 r += '\nself.muc.state='+str(self.muc.state) |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
373 return r |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
374 |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
375 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
376 def __del__(self): |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
377 self.leave('') |