annotate participant.py @ 56:b048c4c03b00

Fixed encoding issues Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Thu, 27 Aug 2009 22:31:47 +0200
parents 5afa22125334
children 0c00cf22492d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
21 import irclib
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:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
28 def __init__(self, owner_bridge, protocol, nickname):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
29 self.bridge = owner_bridge
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
30 self.protocol = protocol
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
31 self.nickname = nickname
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
32 self.irc_connection = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
33 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
34 self.muc = None
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
35 if protocol == 'xmpp':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
36 self.createDuplicateOnIRC()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
37 elif protocol == 'irc':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
38 self.createDuplicateOnXMPP()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
39 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
40 raise Exception('[Internal Error] bad protocol')
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
41
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
42
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
43 def createDuplicateOnXMPP(self):
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
44 if self.xmpp_c != None or self.irc_connection != None or self.bridge.mode == 'minimal':
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
45 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
46 self.xmpp_c = self.bridge.bot.get_xmpp_connection(self.nickname)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
47 self.muc = xmpp.muc(self.bridge.xmpp_room.room_jid)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
48 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
49
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
50
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
51 def _xmpp_join_callback(self, errors):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
52 if len(errors) == 0:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
53 self.bridge.bot.error('===> Debug: "'+self.nickname+'" duplicate succesfully created on XMPP side of bridge "'+str(self.bridge)+'"', debug=True)
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
54 else:
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
55 for error in errors:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
56 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
57 raise error
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
58 except xmpp.muc.NicknameConflict:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
59 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is already used in the XMPP MUC or reserved on the XMPP server of bridge "'+str(self.bridge)+'"', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
60 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both rooms or reserved on the XMPP server, please avoid that if possible')
29
a694ffe6a973 Fixed nickname change.
Charly COSTE <changaco@changaco.net>
parents: 26
diff changeset
61 self.muc.leave('Nickname 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
62 self.bridge.bot.close_xmpp_connection(self.nickname)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
63 self.xmpp_c = None
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
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
66 def createDuplicateOnIRC(self):
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
67 if self.irc_connection != None or self.xmpp_c != None or self.bridge.mode != 'normal':
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
68 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
69 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
70 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
71 self.irc_connection.connect(nick_callback=self._irc_nick_callback)
56
b048c4c03b00 Fixed encoding issues
Charly COSTE <changaco@changaco.net>
parents: 31
diff changeset
72 if self.irc_connection != None:
b048c4c03b00 Fixed encoding issues
Charly COSTE <changaco@changaco.net>
parents: 31
diff changeset
73 self.irc_connection.join(self.bridge.irc_room)
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
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
75
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 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
77 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
78 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
79 self.bridge.bot.error('===> Debug: "'+self.nickname+'" duplicate succesfully created on IRC side of 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
80 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
81 if error == 'nicknameinuse':
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 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is already used in the IRC chan of 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
83 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both rooms or reserved on the IRC server, please avoid that if possible')
31
5afa22125334 Changed participant's IRC nickname callback function.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
84 if self.irc_connection != None:
5afa22125334 Changed participant's IRC nickname callback function.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
85 self.irc_connection.close('')
5afa22125334 Changed participant's IRC nickname callback function.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
86 self.irc_connection = None
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 11
diff changeset
87 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
88 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
89 self.bridge.say('[Warning] The nickname "'+self.nickname+'" contains unauthorized characters and cannot be used in the IRC channel, please avoid that if possible')
31
5afa22125334 Changed participant's IRC nickname callback function.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
90 if self.irc_connection != None:
5afa22125334 Changed participant's IRC nickname callback function.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
91 self.irc_connection.close('')
5afa22125334 Changed participant's IRC nickname callback function.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
92 self.irc_connection = None
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 11
diff changeset
93 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
94 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
95 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')
31
5afa22125334 Changed participant's IRC nickname callback function.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
96 if self.irc_connection != None:
5afa22125334 Changed participant's IRC nickname callback function.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
97 self.irc_connection.close('')
5afa22125334 Changed participant's IRC nickname callback function.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
98 self.irc_connection = None
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
99
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
100
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
101 def changeNickname(self, newnick, on_protocol):
29
a694ffe6a973 Fixed nickname change.
Charly COSTE <changaco@changaco.net>
parents: 26
diff changeset
102 """Change participant's nickname."""
a694ffe6a973 Fixed nickname change.
Charly COSTE <changaco@changaco.net>
parents: 26
diff changeset
103
a694ffe6a973 Fixed nickname change.
Charly COSTE <changaco@changaco.net>
parents: 26
diff changeset
104 oldnick = self.nickname
a694ffe6a973 Fixed nickname change.
Charly COSTE <changaco@changaco.net>
parents: 26
diff changeset
105
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
106 if self.protocol == 'xmpp':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
107 if on_protocol == 'xmpp':
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 self.bridge.removeParticipant('irc', 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
109 self.bridge.addParticipant('irc', newnick)
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
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 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
112 self.nickname = newnick
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
113 if self.irc_connection != None:
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 11
diff changeset
114 self.irc_connection.nick(newnick, 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
115 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
116 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
117
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
118 elif self.protocol == 'irc':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
119 if on_protocol == 'irc':
10
7cb790f5f243 No comment.
Charly COSTE <changaco@changaco.net>
parents: 5
diff changeset
120 self.bridge.removeParticipant('xmpp', self.nickname, '')
7cb790f5f243 No comment.
Charly COSTE <changaco@changaco.net>
parents: 5
diff changeset
121 self.bridge.addParticipant('xmpp', newnick)
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
122
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
123 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
124 self.nickname = newnick
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
125 if self.muc != None:
29
a694ffe6a973 Fixed nickname change.
Charly COSTE <changaco@changaco.net>
parents: 26
diff changeset
126 self.bridge.bot.xmpp_connections[newnick] = self.xmpp_c
a694ffe6a973 Fixed nickname change.
Charly COSTE <changaco@changaco.net>
parents: 26
diff changeset
127 self.bridge.bot.close_xmpp_connection(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
128 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
129 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
130 self.createDuplicateOnXMPP()
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
131
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
132
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
133 def sayOnIRC(self, message):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
134 try:
26
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
135 if self.irc_connection != None:
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
136 self.irc_connection.privmsg(self.bridge.irc_room, message)
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
137 elif self.xmpp_c == None:
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
138 self.bridge.irc_connection.privmsg(self.bridge.irc_room, '<'+self.nickname+'> '+message)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
139 except EncodingException:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
140 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
141
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
142
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
143 def sayOnIRCTo(self, to, message):
26
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
144 if self.irc_connection != None:
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
145 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
146 self.irc_connection.privmsg(to, message)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
147 except EncodingException:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
148 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding')
26
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
149 elif self.xmpp_c == None:
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
150 if self.bridge.mode != 'normal':
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
151 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
152 else:
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
153 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
154
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
155
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
156 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
157 try:
26
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
158 if self.xmpp_c != None:
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
159 self.muc.say(auto_decode(message))
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
160 elif self.irc_connection == None:
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 11
diff changeset
161 self.bridge.xmpp_room.say('<'+self.nickname+'> '+auto_decode(message))
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 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
163 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
164
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
165
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
166 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
167 try:
26
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
168 if self.xmpp_c != None:
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
169 self.muc.sayTo(to, auto_decode(message))
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
170 elif self.irc_connection == None:
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
171 if self.bridge.mode != 'normal':
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
172 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
173 else:
1691ab4d131f Fixed participant's "say" functions.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
174 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
175 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
176 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
177
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
178
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
179 def leave(self, message):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
180 if message == None:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
181 message = ''
11
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
182 if self.xmpp_c != None:
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
183 self.muc.leave(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
184 self.bridge.bot.close_xmpp_connection(self.nickname)
11
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
185 if self.irc_connection != None:
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 11
diff changeset
186 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
187 if 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
188 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
189 self.irc_connection = None
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
190 self.nickname = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
191
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
192
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
193 def __del__(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
194 if self.nickname != None:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
195 self.leave('')