Mercurial > xib
annotate participant.py @ 117:d062efcfbe9d 0.2
minor fix
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sat, 28 Nov 2009 23:55:47 +0100 |
parents | 23416c27b592 |
children | b29fd5696a78 |
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 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
25 |
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 class participant: |
103 | 28 def __init__(self, owner_bridge, protocol, nickname, real_jid=None): |
29 self.bot_admin = False | |
30 self.real_jid = real_jid | |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
31 self.bridge = owner_bridge |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
32 self.protocol = protocol |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
33 self.nickname = nickname |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
34 self.irc_connection = None |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
35 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
|
36 self.muc = None |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
37 if protocol == 'xmpp': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
38 self.createDuplicateOnIRC() |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
39 elif protocol == 'irc': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
40 self.createDuplicateOnXMPP() |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
41 else: |
19
c1b84196c100
Changed format of non-debug error messages, fixed IRC namreply handling, prevented crash when receiving bad XMPP stanza.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
42 raise Exception('[Internal Error] bad protocol') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
43 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
44 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
45 def createDuplicateOnXMPP(self): |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
46 if isinstance(self.xmpp_c, xmpp.client.Client) or isinstance(self.irc_connection, ServerConnection) or self.bridge.mode == 'minimal' or self.nickname == 'ChanServ': |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
47 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
|
48 self.xmpp_c = self.bridge.bot.get_xmpp_connection(self.nickname) |
103 | 49 self.muc = xmpp.muc(self.bridge.xmpp_room_jid) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
50 self.muc.join(self.xmpp_c, self.nickname, status='From IRC', callback=self._xmpp_join_callback) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
51 |
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 def _xmpp_join_callback(self, errors): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
54 if len(errors) == 0: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
55 self.bridge.bot.error('===> Debug: "'+self.nickname+'" duplicate succesfully created on XMPP side of bridge "'+str(self.bridge)+'"', debug=True) |
82
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
56 elif self.xmpp_c != 'both': |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
57 for error in errors: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
58 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
59 raise error |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
60 except xmpp.muc.NicknameConflict: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
61 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) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
62 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both rooms or reserved on the XMPP server, please avoid that if possible') |
82
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
63 if self.muc.connected == True: |
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
64 self.muc.leave('Changed nickname to "'+self.nickname+'"') |
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
65 except xmpp.muc.RoomIsFull: |
86
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
83
diff
changeset
|
66 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
|
67 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
|
68 |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
69 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
|
70 self.bridge.bot.close_xmpp_connection(self.nickname) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
71 self.xmpp_c = None |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
72 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
73 |
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
|
74 def createDuplicateOnIRC(self): |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
75 if isinstance(self.xmpp_c, xmpp.client.Client) or isinstance(self.irc_connection, ServerConnection) or self.bridge.mode != 'normal': |
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
|
76 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
|
77 sleep(1) # try to prevent "reconnecting too fast" shit |
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
|
78 self.irc_connection = self.bridge.bot.irc.server(self.bridge.irc_server, self.bridge.irc_port, self.nickname) |
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
|
79 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
|
80 |
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
|
81 |
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
|
82 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
|
83 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
|
84 self.irc_connection.join(self.bridge.irc_room) |
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
|
85 self.bridge.bot.error('===> Debug: "'+self.nickname+'" duplicate succesfully created on IRC side of bridge "'+str(self.bridge)+'"', debug=True) |
82
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
86 elif self.irc_connection != 'both': |
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
|
87 if error == 'nicknameinuse': |
82
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
88 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is used or reserved on the IRC server of bridge "'+str(self.bridge)+'"', debug=True) |
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
89 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used or reserved on the IRC server, please avoid that if possible') |
64
8fc496eaa17b
Handle IRC "nickcollision" event
Charly COSTE <changaco@changaco.net>
parents:
63
diff
changeset
|
90 elif error == 'nickcollision': |
82
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
91 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is used or reserved on the IRC server of bridge "'+str(self.bridge)+'"', debug=True) |
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
92 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used or reserved on the IRC server, please avoid that if possible') |
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
|
93 elif error == 'erroneusnickname': |
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
|
94 self.bridge.bot.error('===> Debug: "'+self.nickname+'" got "erroneusnickname" 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
|
95 self.bridge.say('[Warning] The nickname "'+self.nickname+'" contains unauthorized characters and cannot be used in the IRC channel, please avoid that if possible') |
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
|
96 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
|
97 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
|
98 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') |
82
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
99 else: |
90baff5dedb2
Fixed callbacks in participant.py
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
100 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
|
101 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
|
102 |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
103 if isinstance(self.irc_connection, ServerConnection): |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
104 self.irc_connection.close('') |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
105 self.irc_connection = error |
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 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
108 def changeNickname(self, newnick, on_protocol): |
29 | 109 """Change participant's nickname.""" |
110 | |
111 oldnick = self.nickname | |
112 | |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
113 if self.protocol == 'xmpp': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
114 if on_protocol == 'xmpp': |
94
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
115 self._close_irc_connection('unwanted nick change') |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
116 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
|
117 |
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 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
|
119 self.nickname = newnick |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 else: |
117 | 124 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
|
125 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
|
126 else: |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
127 if self.irc_connection == 'both': |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
128 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
|
129 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
|
130 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
131 elif self.protocol == 'irc': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
132 if on_protocol == 'irc': |
94
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
133 self._close_xmpp_connection('unwanted nick change') |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
134 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
|
135 |
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
|
136 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
|
137 self.nickname = newnick |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
138 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
|
139 for b in self.bridge.bot.bridges: |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
61
diff
changeset
|
140 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
|
141 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
|
142 self.xmpp_c = None |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
61
diff
changeset
|
143 self.bridge.bot.close_xmpp_connection(oldnick) |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
61
diff
changeset
|
144 self.createDuplicateOnXMPP() |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
61
diff
changeset
|
145 return |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
61
diff
changeset
|
146 |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
61
diff
changeset
|
147 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
|
148 if self.bridge.bot.xmpp_connections.has_key(oldnick): |
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
149 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
|
150 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
|
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 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
|
153 else: |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
154 if self.xmpp_c == 'both': |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
155 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
|
156 self.createDuplicateOnXMPP() |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
157 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
158 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
159 def sayOnIRC(self, message): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
160 try: |
95 | 161 bot_say = False |
162 if message[:4] == '/me ': | |
163 action = True | |
164 message = message[4:] | |
165 else: | |
166 action = False | |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
167 if isinstance(self.irc_connection, ServerConnection): |
65 | 168 try: |
95 | 169 if action: |
170 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
|
171 else: |
fa291fd20480
Handle /me the XMPP to IRC way
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
172 self.irc_connection.privmsg(self.bridge.irc_room, message) |
65 | 173 except ServerNotConnectedError: |
95 | 174 bot_say = True |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
175 elif not isinstance(self.xmpp_c, xmpp.client.Client): |
95 | 176 bot_say = True |
177 if bot_say: | |
178 if action: | |
179 self.bridge.irc_connection.privmsg(self.bridge.irc_room, '* '+self.nickname+' '+message) | |
180 else: | |
181 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
|
182 except EncodingException: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
183 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
|
184 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
185 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
186 def sayOnIRCTo(self, to, message): |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
187 if isinstance(self.irc_connection, ServerConnection): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
188 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
189 self.irc_connection.privmsg(to, message) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
190 except EncodingException: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
191 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
|
192 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
|
193 if self.bridge.mode != 'normal': |
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
194 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
|
195 else: |
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
196 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
|
197 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
198 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
199 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
|
200 try: |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
201 if isinstance(self.xmpp_c, xmpp.client.Client): |
26
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
202 self.muc.say(auto_decode(message)) |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
203 elif not isinstance(self.irc_connection, ServerConnection): |
95 | 204 if message[:4] == '/me ': |
205 self.bridge.xmpp_room.say('* '+self.nickname+' '+auto_decode(message[4:])) | |
206 else: | |
207 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
|
208 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
|
209 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
|
210 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
211 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
212 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
|
213 try: |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
214 if isinstance(self.xmpp_c, xmpp.client.Client): |
26
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
215 self.muc.sayTo(to, auto_decode(message)) |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
216 elif not isinstance(self.irc_connection, ServerConnection): |
26
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
217 if self.bridge.mode != 'normal': |
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
218 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
|
219 else: |
1691ab4d131f
Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
220 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
|
221 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
|
222 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
|
223 |
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 def leave(self, message): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
226 if message == None: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
227 message = '' |
94
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
228 self._close_xmpp_connection(message) |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
229 self._close_irc_connection(message) |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
230 self.nickname = None |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
231 |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
232 |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
233 def _close_xmpp_connection(self, message): |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
234 if isinstance(self.xmpp_c, xmpp.client.Client): |
66 | 235 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
|
236 self.bridge.bot.close_xmpp_connection(self.nickname) |
94
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
237 |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
238 |
810a6bed6c9c
Tried to fix participant.changeNickname
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
239 def _close_irc_connection(self, message): |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
68
diff
changeset
|
240 if isinstance(self.irc_connection, ServerConnection): |
83
5115ba7d5983
Leave chan only if (really) connected
Charly COSTE <changaco@changaco.net>
parents:
82
diff
changeset
|
241 if self.irc_connection.really_connected == True: |
5115ba7d5983
Leave chan only if (really) connected
Charly COSTE <changaco@changaco.net>
parents:
82
diff
changeset
|
242 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
|
243 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
|
244 if self.irc_connection.used_by < 1: |
64
8fc496eaa17b
Handle IRC "nickcollision" event
Charly COSTE <changaco@changaco.net>
parents:
63
diff
changeset
|
245 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
|
246 self.irc_connection = None |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
247 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
248 |
98
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
249 def __str__(self): |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
250 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
|
251 if isinstance(self.irc_connection, ServerConnection): |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
252 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
|
253 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
|
254 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
|
255 return r |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
256 |
35e0ddf3b13c
Code cleaning, participant.changeNickname improvement, added participant.__str__
Charly COSTE <changaco@changaco.net>
parents:
95
diff
changeset
|
257 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
258 def __del__(self): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
259 if self.nickname != None: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
260 self.leave('') |