Mercurial > xib
annotate participant.py @ 118:b29fd5696a78
new mode bypass and new method bridge.changeMode
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sat, 28 Nov 2009 23:47:11 +0100 |
parents | d062efcfbe9d |
children | 75a03f10a863 |
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 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
18 import muc |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
19 xmpp = muc.xmpp |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
20 del muc |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
21 from irclib import ServerNotConnectedError, ServerConnection |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
22 from encoding import * |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
23 from threading import Thread |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
24 from time import sleep |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
25 import re |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
26 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
27 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
28 class participant: |
103 | 29 def __init__(self, owner_bridge, protocol, nickname, real_jid=None): |
30 self.bot_admin = False | |
31 self.real_jid = real_jid | |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
32 self.bridge = owner_bridge |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
33 self.protocol = protocol |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
34 self.nickname = nickname |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
35 self.duplicate_nickname = self.nickname |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
36 self.irc_connection = None |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
37 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
|
38 self.muc = None |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
39 if protocol == 'xmpp' and self.bridge.mode in ['normal', 'bypass']: |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
40 self.createDuplicateOnIRC() |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
41 elif protocol == 'irc' and self.bridge.mode != 'minimal': |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
42 self.createDuplicateOnXMPP() |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
43 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
44 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
45 def _get_new_duplicate_nickname(self): |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
46 new_duplicate_nickname = self.duplicate_nickname |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
47 for i in xrange(5): |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
48 new_duplicate_nickname = new_duplicate_nickname+'_' |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
49 if not self.bridge.hasParticipant(new_duplicate_nickname): |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
50 return new_duplicate_nickname |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
51 return None |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
52 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
53 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
54 def createDuplicateOnXMPP(self): |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
55 if isinstance(self.xmpp_c, xmpp.client.Client) or isinstance(self.irc_connection, ServerConnection): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
56 return |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
57 self.xmpp_c = self.bridge.bot.get_xmpp_connection(self.duplicate_nickname) |
103 | 58 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
|
59 self.join_muc() |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
60 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
61 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
62 def join_muc(self): |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
63 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
|
64 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
65 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
66 def _xmpp_join_callback(self, errors): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
67 if len(errors) == 0: |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
68 m = '===> Debug: "'+self.nickname+'" duplicate succesfully created on XMPP side of bridge "'+str(self.bridge)+'"' |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
69 if self.nickname != self.duplicate_nickname: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
70 m += ' using nickname "'+self.duplicate_nickname+'"' |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
71 self.bridge.say('[Info] "'+self.nickname+'" will appear as "'+self.duplicate_nickname+'" on XMPP because its real nickname is reserved or contains unauthorized characters') |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
72 self.bridge.bot.error(m, debug=True) |
82
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
73 elif self.xmpp_c != 'both': |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
74 for error in errors: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
75 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
76 raise error |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
77 except xmpp.muc.NicknameConflict as e: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
78 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
|
79 return |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
80 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
81 if self.bridge.mode == 'bypass': |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
82 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
|
83 if new_duplicate_nickname != None: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
84 self.bridge.bot.error('===> Debug: "'+self.duplicate_nickname+'" is already used in the XMPP MUC or reserved on the XMPP server of bridge "'+str(self.bridge)+'", trying "'+new_duplicate_nickname+'"', debug=True) |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
85 if self.duplicate_nickname == self.nickname: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
86 self.bridge.say('[Info] The nickname "'+self.duplicate_nickname+'" is used on both rooms or reserved on the XMPP server, please avoid that if possible') |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
87 self.duplicate_nickname = new_duplicate_nickname |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
88 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
|
89 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
|
90 self.xmpp_c = None |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
91 self.createDuplicateOnXMPP() |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
92 return |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
93 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
94 else: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
95 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is already used in the XMPP MUC or reserved on the XMPP server of bridge "'+str(self.bridge)+'"', debug=True) |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
96 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both rooms or reserved on the XMPP server, please avoid that if possible') |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
97 if self.muc.connected == True: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
98 self.muc.leave('Changed nickname to "'+self.nickname+'"') |
82
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
99 except xmpp.muc.RoomIsFull: |
86
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
83
diff
changeset
|
100 self.bridge.bot.error('[Warning] XMPP MUC of bridge "'+str(self.bridge)+'" is full', send_to_admins=True) |
82
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
101 self.bridge.say('[Warning] XMPP room is full') |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
102 |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
103 if isinstance(self.xmpp_c, xmpp.client.Client): |
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
|
104 self.bridge.bot.close_xmpp_connection(self.nickname) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
105 self.xmpp_c = None |
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 |
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
|
108 def createDuplicateOnIRC(self): |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
109 if isinstance(self.xmpp_c, xmpp.client.Client) or isinstance(self.irc_connection, 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 |
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
|
111 sleep(1) # try to prevent "reconnecting too fast" shit |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
112 self.irc_connection = self.bridge.bot.irc.server(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
|
113 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
|
114 |
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
|
115 |
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
|
116 def _irc_nick_callback(self, error, arguments=[]): |
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
|
117 if error == None: |
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
|
118 self.irc_connection.join(self.bridge.irc_room) |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
119 m = '===> Debug: "'+self.nickname+'" duplicate succesfully created on IRC side of bridge "'+str(self.bridge)+'"' |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
120 if self.nickname != self.duplicate_nickname: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
121 m += ' using nickname "'+self.duplicate_nickname+'"' |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
122 self.bridge.say('[Info] "'+self.nickname+'" will appear as "'+self.duplicate_nickname+'" on IRC because its real nickname is reserved or contains unauthorized characters') |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
123 self.bridge.bot.error(m, debug=True) |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
124 |
82
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
125 elif self.irc_connection != 'both': |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
126 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
127 if error in ['nicknameinuse', 'nickcollision']: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
128 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
|
129 return |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
130 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
131 if self.bridge.mode == 'bypass': |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
132 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
|
133 if new_duplicate_nickname != None: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
134 self.bridge.bot.error('===> Debug: "'+self.duplicate_nickname+'" is already used or reserved on the IRC server of bridge "'+str(self.bridge)+'", trying "'+new_duplicate_nickname+'"', debug=True) |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
135 if self.duplicate_nickname == self.nickname: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
136 self.bridge.say('[Info] The nickname "'+self.duplicate_nickname+'" is used or reserved on the IRC server, please avoid that if possible') |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
137 self.duplicate_nickname = new_duplicate_nickname |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
138 if isinstance(self.irc_connection, ServerConnection): |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
139 self.irc_connection.close('') |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
140 self.irc_connection = error |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
141 self.createDuplicateOnIRC() |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
142 return |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
143 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
144 else: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
145 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is used or reserved on the IRC server of bridge "'+str(self.bridge)+'"', debug=True) |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
146 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used or reserved on the IRC server, please avoid that if possible') |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
147 |
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
|
148 elif error == 'erroneusnickname': |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
149 if self.bridge.mode == 'bypass': |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
150 self.duplicate_nickname = re.sub('[^a-zA-Z]', '', self.nickname) |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
151 if isinstance(self.irc_connection, ServerConnection): |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
152 self.irc_connection.close('') |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
153 self.irc_connection = error |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
154 self.createDuplicateOnIRC() |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
155 return |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
156 else: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
157 self.bridge.bot.error('===> Debug: "'+self.nickname+'" got "erroneusnickname" on bridge "'+str(self.bridge)+'"', debug=True) |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
158 self.bridge.say('[Warning] The nickname "'+self.nickname+'" contains unauthorized characters and cannot be used in the IRC channel, please avoid that if possible') |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
159 |
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
|
160 elif error == 'nicknametoolong': |
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
|
161 self.bridge.bot.error('===> Debug: "'+self.nickname+'" got "nicknametoolong" on bridge "'+str(self.bridge)+'"', debug=True) |
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
|
162 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') |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
163 |
82
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
164 else: |
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
165 self.bridge.bot.error('===> Debug: unknown error while adding "'+self.nickname+'" to IRC side of bridge "'+str(self.bridge)+'"', debug=True) |
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
166 self.bridge.say('[Warning] unknown error while adding "'+self.nickname+'" to IRC side of bridge') |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
167 |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
168 if isinstance(self.irc_connection, ServerConnection): |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
169 self.irc_connection.close('') |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
170 self.irc_connection = error |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
171 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
172 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
173 def changeNickname(self, newnick, on_protocol): |
29 | 174 """Change participant's nickname.""" |
175 | |
176 oldnick = self.nickname | |
177 | |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
178 if self.protocol == 'xmpp': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
179 if on_protocol == 'xmpp': |
94
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
180 self._close_irc_connection('unwanted nick change') |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
181 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
|
182 |
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
|
183 else: |
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
|
184 self.nickname = newnick |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
185 self.duplicate_nickname = newnick |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
186 if isinstance(self.irc_connection, ServerConnection): |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
187 if self.irc_connection.used_by == 1: |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
188 self.irc_connection.nick(newnick, callback=self._irc_nick_callback) |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
189 else: |
117 | 190 self._close_irc_connection('Changed nickname') |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
191 self.createDuplicateOnIRC() |
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
|
192 else: |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
193 if self.irc_connection == 'both': |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
194 self.bridge.addParticipant('irc', oldnick) |
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
|
195 self.createDuplicateOnIRC() |
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
|
196 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
197 elif self.protocol == 'irc': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
198 if on_protocol == 'irc': |
94
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
199 self._close_xmpp_connection('unwanted nick change') |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
200 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
|
201 |
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
|
202 else: |
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
|
203 self.nickname = newnick |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
204 self.duplicate_nickname = newnick |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
205 if isinstance(self.xmpp_c, xmpp.client.Client): |
62
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
61
diff
changeset
|
206 for b in self.bridge.bot.bridges: |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
61
diff
changeset
|
207 if b.hasParticipant(oldnick) and b.irc_server != self.bridge.irc_server: |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
208 self.muc.leave(message='Changed nickname to "'+self.nickname+'"') |
62
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
61
diff
changeset
|
209 self.xmpp_c = None |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
61
diff
changeset
|
210 self.bridge.bot.close_xmpp_connection(oldnick) |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
61
diff
changeset
|
211 self.createDuplicateOnXMPP() |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
61
diff
changeset
|
212 return |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
61
diff
changeset
|
213 |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
61
diff
changeset
|
214 if not self.bridge.bot.xmpp_connections.has_key(newnick): |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
215 if self.bridge.bot.xmpp_connections.has_key(oldnick): |
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
216 self.bridge.bot.xmpp_connections.pop(oldnick) |
62
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
61
diff
changeset
|
217 self.bridge.bot.xmpp_connections[newnick] = self.xmpp_c |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
61
diff
changeset
|
218 |
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
|
219 self.muc.change_nick(newnick, status='From IRC', callback=self._xmpp_join_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
|
220 else: |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
221 if self.xmpp_c == 'both': |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
222 self.bridge.addParticipant('xmpp', oldnick) |
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 self.createDuplicateOnXMPP() |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
224 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
225 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
226 def sayOnIRC(self, message): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
227 try: |
95 | 228 bot_say = False |
229 if message[:4] == '/me ': | |
230 action = True | |
231 message = message[4:] | |
232 else: | |
233 action = False | |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
234 if isinstance(self.irc_connection, ServerConnection): |
65 | 235 try: |
95 | 236 if action: |
237 self.irc_connection.action(self.bridge.irc_room, message) | |
73
fa291fd20480
Handle /me the XMPP to IRC way
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
238 else: |
fa291fd20480
Handle /me the XMPP to IRC way
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
239 self.irc_connection.privmsg(self.bridge.irc_room, message) |
65 | 240 except ServerNotConnectedError: |
95 | 241 bot_say = True |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
242 elif not isinstance(self.xmpp_c, xmpp.client.Client): |
95 | 243 bot_say = True |
244 if bot_say: | |
245 if action: | |
246 self.bridge.irc_connection.privmsg(self.bridge.irc_room, '* '+self.nickname+' '+message) | |
247 else: | |
248 self.bridge.irc_connection.privmsg(self.bridge.irc_room, '<'+self.nickname+'> '+message) | |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
249 except EncodingException: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
250 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding') |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
251 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
252 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
253 def sayOnIRCTo(self, to, message): |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
254 if isinstance(self.irc_connection, ServerConnection): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
255 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
256 self.irc_connection.privmsg(to, message) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
257 except EncodingException: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
258 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding') |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
259 elif not isinstance(self.xmpp_c, xmpp.client.Client): |
26
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
260 if self.bridge.mode != 'normal': |
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
261 self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') |
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
262 else: |
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
263 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.') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
264 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
265 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
266 def sayOnXMPP(self, message): |
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
|
267 try: |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
268 if isinstance(self.xmpp_c, xmpp.client.Client): |
26
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
269 self.muc.say(auto_decode(message)) |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
270 elif not isinstance(self.irc_connection, ServerConnection): |
95 | 271 if message[:4] == '/me ': |
272 self.bridge.xmpp_room.say('* '+self.nickname+' '+auto_decode(message[4:])) | |
273 else: | |
274 self.bridge.xmpp_room.say('<'+self.nickname+'> '+auto_decode(message)) | |
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
|
275 except EncodingException: |
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
|
276 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
277 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
278 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
279 def sayOnXMPPTo(self, to, message): |
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
|
280 try: |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
281 if isinstance(self.xmpp_c, xmpp.client.Client): |
26
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
282 self.muc.sayTo(to, auto_decode(message)) |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
283 elif not isinstance(self.irc_connection, ServerConnection): |
26
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
284 if self.bridge.mode != 'normal': |
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
285 self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') |
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
286 else: |
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
287 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.') |
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
|
288 except EncodingException: |
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
|
289 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
290 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
291 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
292 def leave(self, message): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
293 if message == None: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
294 message = '' |
94
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
295 self._close_xmpp_connection(message) |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
296 self._close_irc_connection(message) |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
297 |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
298 |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
299 def _close_xmpp_connection(self, message): |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
300 if isinstance(self.xmpp_c, xmpp.client.Client): |
66 | 301 self.muc.leave(auto_decode(message)) |
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
|
302 self.bridge.bot.close_xmpp_connection(self.nickname) |
94
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
303 |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
304 |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
305 def _close_irc_connection(self, message): |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
306 if isinstance(self.irc_connection, ServerConnection): |
83
5115ba7d5983
Leave chan only if (really) connected
Charly COSTE <changaco@changaco.net>
parents:
82
diff
changeset
|
307 if self.irc_connection.really_connected == True: |
5115ba7d5983
Leave chan only if (really) connected
Charly COSTE <changaco@changaco.net>
parents:
82
diff
changeset
|
308 self.irc_connection.part(self.bridge.irc_room, message=message) |
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
|
309 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
|
310 if self.irc_connection.used_by < 1: |
64
8fc496eaa17b
Handle IRC "nickcollision" event
Charly COSTE <changaco@changaco.net>
parents:
63
diff
changeset
|
311 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
|
312 self.irc_connection = None |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
313 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
314 |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
315 def __str__(self): |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
316 r = 'self.protocol='+str(self.protocol)+'\n'+'self.nickname='+str(self.nickname) |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
317 if isinstance(self.irc_connection, ServerConnection): |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
318 r += '\nself.irc_connection='+str(self.irc_connection)+'\n'+'self.irc_connection.really_connected='+str(self.irc_connection.really_connected) |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
319 if isinstance(self.xmpp_c, xmpp.client.Client): |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
320 r += '\nself.muc.connected='+str(self.muc.connected) |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
321 return r |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
322 |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
323 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
324 def __del__(self): |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
117
diff
changeset
|
325 self.leave('') |