Mercurial > xib
annotate muc.py @ 216:d527d7b75f56
merged Bot.find_bridges and Bot.get_bridges into Bot.iter_bridges, btw we don't need to lock Bot.bridges because lists don't raise RuntimeError
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sat, 06 Mar 2010 22:55:47 +0100 |
parents | 0c99d38b84b8 |
children | 45065f6f674c |
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 xmppony as xmpp |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
19 from time import sleep |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
20 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
21 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
22 class muc: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
23 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
24 class PasswordNeeded(Exception): pass |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
25 class MembersOnlyRoom(Exception): pass |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
26 class BannedFromRoom(Exception): pass |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
27 class NicknameConflict(Exception): pass |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
28 class RoomIsFull(Exception): pass |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
29 class RoomIsLocked(Exception): pass |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
30 class ForgotNickname(Exception): pass |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
31 class UnknownError(Exception): pass |
111
59401ac0f47a
handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents:
90
diff
changeset
|
32 class RemoteServerNotFound(Exception): pass |
214
0c99d38b84b8
(muc) added "auto_reconnect" attribute (defaults to True, turns to False when "leave" is called), created NotConnected exception
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
33 class NotConnected(Exception): pass |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
34 |
214
0c99d38b84b8
(muc) added "auto_reconnect" attribute (defaults to True, turns to False when "leave" is called), created NotConnected exception
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
35 def __init__(self, room_jid, auto_reconnect=True): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
36 self.room_jid = room_jid |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
37 self.connected = False |
214
0c99d38b84b8
(muc) added "auto_reconnect" attribute (defaults to True, turns to False when "leave" is called), created NotConnected exception
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
38 self.auto_reconnect = auto_reconnect |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
39 self.participants = {} |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
40 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
41 |
90
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
42 def _join(self, callback=None): |
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
43 self.callback = callback |
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
44 self.xmpp_c.RegisterHandler('presence', self._xmpp_presence_handler) |
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
45 s = xmpp.protocol.Presence(to=self.jid, status=self.status, payload=[xmpp.simplexml.Node(tag='x', attrs={'xmlns': 'http://jabber.org/protocol/muc'}, payload=[xmpp.simplexml.Node(tag='history', attrs={'maxchars': '0'})])]) |
214
0c99d38b84b8
(muc) added "auto_reconnect" attribute (defaults to True, turns to False when "leave" is called), created NotConnected exception
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
46 self._send(s, force=True) |
170
11717d14e22f
created muc._send(), should have been done ages ago
Charly COSTE <changaco@changaco.net>
parents:
111
diff
changeset
|
47 |
11717d14e22f
created muc._send(), should have been done ages ago
Charly COSTE <changaco@changaco.net>
parents:
111
diff
changeset
|
48 |
214
0c99d38b84b8
(muc) added "auto_reconnect" attribute (defaults to True, turns to False when "leave" is called), created NotConnected exception
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
49 def _send(self, stanza, force=False): |
0c99d38b84b8
(muc) added "auto_reconnect" attribute (defaults to True, turns to False when "leave" is called), created NotConnected exception
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
50 """Send a stanza. |
0c99d38b84b8
(muc) added "auto_reconnect" attribute (defaults to True, turns to False when "leave" is called), created NotConnected exception
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
51 |
0c99d38b84b8
(muc) added "auto_reconnect" attribute (defaults to True, turns to False when "leave" is called), created NotConnected exception
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
52 The "force" optional argument bypasses the fact that we are not in the room yet, necessary to send initial presence""" |
0c99d38b84b8
(muc) added "auto_reconnect" attribute (defaults to True, turns to False when "leave" is called), created NotConnected exception
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
53 |
0c99d38b84b8
(muc) added "auto_reconnect" attribute (defaults to True, turns to False when "leave" is called), created NotConnected exception
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
54 if not self.connected and not force: |
0c99d38b84b8
(muc) added "auto_reconnect" attribute (defaults to True, turns to False when "leave" is called), created NotConnected exception
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
55 raise self.NotConnected, stanza.__str__(fancy=1).encode('utf-8') |
90
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
56 try: |
170
11717d14e22f
created muc._send(), should have been done ages ago
Charly COSTE <changaco@changaco.net>
parents:
111
diff
changeset
|
57 self.xmpp_c.send(stanza) |
90
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
58 except IOError, xmpp.Conflict: |
214
0c99d38b84b8
(muc) added "auto_reconnect" attribute (defaults to True, turns to False when "leave" is called), created NotConnected exception
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
59 if not self.auto_reconnect: |
0c99d38b84b8
(muc) added "auto_reconnect" attribute (defaults to True, turns to False when "leave" is called), created NotConnected exception
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
60 raise self.NotConnected, stanza.__str__(fancy=1).encode('utf-8') |
0c99d38b84b8
(muc) added "auto_reconnect" attribute (defaults to True, turns to False when "leave" is called), created NotConnected exception
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
61 |
90
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
62 self.xmpp_c.reconnectAndReauth() |
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
63 for m in self.xmpp_c.mucs: |
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
64 m.rejoin() |
170
11717d14e22f
created muc._send(), should have been done ages ago
Charly COSTE <changaco@changaco.net>
parents:
111
diff
changeset
|
65 self.xmpp_c.send(stanza) |
90
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
66 |
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
67 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
68 def join(self, xmpp_c, nickname, status=None, callback=None): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
69 """Join room on xmpp_c connection using nickname""" |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
70 self.jid = self.room_jid+'/'+nickname |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
71 self.nickname = nickname |
90
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
72 self.status = status |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
73 self.xmpp_c = xmpp_c |
90
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
74 self.xmpp_c.mucs.append(self) |
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
75 self._join(callback=callback) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
76 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
77 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
78 def _xmpp_presence_handler(self, xmpp_c, presence): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
79 if presence.getFrom() == self.jid: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
80 errors = [] |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
81 if presence.getAttr('type') == 'error': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
82 for c in presence.getChildren(): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
83 if c.getName() == 'error': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
84 for cc in c.getChildren(): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
85 if cc.getNamespace() == 'urn:ietf:params:xml:ns:xmpp-stanzas' and cc.getName() != 'text': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
86 err = c.getAttr('type')+' '+cc.getName() |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
87 if err == 'auth not-authorized': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
88 # password-protected room |
81 | 89 errors.append(self.__class__.PasswordNeeded(self.jid)) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
90 elif err == 'auth registration-required': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
91 # members-only room |
81 | 92 errors.append(self.__class__.MembersOnlyRoom(self.jid)) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
93 elif err == 'auth forbidden': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
94 # banned from room |
81 | 95 errors.append(self.__class__.BannedFromRoom(self.jid)) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
96 elif err == 'cancel conflict': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
97 # nickname conflict |
81 | 98 errors.append(self.__class__.NicknameConflict(self.jid)) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
99 elif err == 'wait service-unavailable': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
100 # room is full |
81 | 101 errors.append(self.__class__.RoomIsFull(self.jid)) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
102 elif err == 'cancel item-not-found': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
103 # room is locked |
81 | 104 errors.append(self.__class__.RoomIsLocked(self.jid)) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
105 elif err == 'modify jid-malformed': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
106 # forgot to give a nickname |
81 | 107 errors.append(self.__class__.ForgotNickname(self.jid)) |
111
59401ac0f47a
handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents:
90
diff
changeset
|
108 elif err == 'cancel remote-server-not-found': |
59401ac0f47a
handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents:
90
diff
changeset
|
109 # MUC server is down or doesn't exist |
59401ac0f47a
handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents:
90
diff
changeset
|
110 errors.append(self.__class__.RemoteServerNotFound(self.jid)) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
111 else: |
81 | 112 errors.append(self.__class__.UnknownError(presence.__str__(fancy=1).encode('utf-8'))) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
113 break |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
114 if len(errors) == 0: |
81 | 115 errors.append(self.__class__.UnknownError(presence.__str__(fancy=1).encode('utf-8'))) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
116 else: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
117 self.connected = True |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
118 xmpp_c.UnregisterHandler('presence', self._xmpp_presence_handler) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
119 if self.callback != None: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
120 self.callback(errors) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
121 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
122 |
213
fbe40b397f67
created Bridge.say_on_behalf in order to avoid code repetition in participant.py
Charly COSTE <changaco@changaco.net>
parents:
203
diff
changeset
|
123 def say(self, message, action=False): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
124 """Say message in the room""" |
40
faa468731d8a
Tried to get thread safety and handle disconnections in muc.py
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
125 self.xmpp_c.lock.acquire() |
213
fbe40b397f67
created Bridge.say_on_behalf in order to avoid code repetition in participant.py
Charly COSTE <changaco@changaco.net>
parents:
203
diff
changeset
|
126 if action: |
fbe40b397f67
created Bridge.say_on_behalf in order to avoid code repetition in participant.py
Charly COSTE <changaco@changaco.net>
parents:
203
diff
changeset
|
127 message = '/me '+message |
90
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
128 s = xmpp.protocol.Message(to=self.room_jid, typ='groupchat', body=message) |
170
11717d14e22f
created muc._send(), should have been done ages ago
Charly COSTE <changaco@changaco.net>
parents:
111
diff
changeset
|
129 self._send(s) |
40
faa468731d8a
Tried to get thread safety and handle disconnections in muc.py
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
130 self.xmpp_c.lock.release() |
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 |
203
2a81c480439a
renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents:
170
diff
changeset
|
133 def say_to(self, to, message): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
134 """Send a private message""" |
40
faa468731d8a
Tried to get thread safety and handle disconnections in muc.py
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
135 self.xmpp_c.lock.acquire() |
90
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
136 s = xmpp.protocol.Message(to=self.room_jid+'/'+to, typ='chat', body=message) |
170
11717d14e22f
created muc._send(), should have been done ages ago
Charly COSTE <changaco@changaco.net>
parents:
111
diff
changeset
|
137 self._send(s) |
40
faa468731d8a
Tried to get thread safety and handle disconnections in muc.py
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
138 self.xmpp_c.lock.release() |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
139 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
140 |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
7
diff
changeset
|
141 def change_nick(self, nickname, status=None, callback=None): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
142 """Change nickname""" |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
143 self.jid = self.room_jid+'/'+nickname |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
144 self.callback = callback |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
145 self.xmpp_c.RegisterHandler('presence', self._xmpp_presence_handler) |
40
faa468731d8a
Tried to get thread safety and handle disconnections in muc.py
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
146 self.xmpp_c.lock.acquire() |
90
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
147 s = xmpp.protocol.Presence(to=self.jid, status=status) |
170
11717d14e22f
created muc._send(), should have been done ages ago
Charly COSTE <changaco@changaco.net>
parents:
111
diff
changeset
|
148 self._send(s) |
40
faa468731d8a
Tried to get thread safety and handle disconnections in muc.py
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
149 self.xmpp_c.lock.release() |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
150 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
151 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
152 def leave(self, message=''): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
153 """Leave the room""" |
40
faa468731d8a
Tried to get thread safety and handle disconnections in muc.py
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
154 self.xmpp_c.lock.acquire() |
214
0c99d38b84b8
(muc) added "auto_reconnect" attribute (defaults to True, turns to False when "leave" is called), created NotConnected exception
Charly COSTE <changaco@changaco.net>
parents:
213
diff
changeset
|
155 self.auto_reconnect = False |
90
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
156 s = xmpp.protocol.Presence(to=self.jid, typ='unavailable', status=message) |
170
11717d14e22f
created muc._send(), should have been done ages ago
Charly COSTE <changaco@changaco.net>
parents:
111
diff
changeset
|
157 self._send(s) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
158 self.connected = False |
40
faa468731d8a
Tried to get thread safety and handle disconnections in muc.py
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
159 self.xmpp_c.lock.release() |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
160 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
161 |
90
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
162 def rejoin(self, callback=None): |
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
163 """Rejoin room""" |
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
164 self.connected = False |
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
165 self._join(callback=callback) |
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
166 |
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
167 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
168 def __del__(self): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
169 if self.connected: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
170 self.leave() |
90
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
171 if self in self.xmpp_c.mucs: |
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
81
diff
changeset
|
172 self.xmpp_c.mucs.remove(self) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
173 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
174 xmpp.muc = muc |