Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0045.py @ 505:2402668b5d05
plugin xep-0045: nick change management
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 27 Sep 2012 00:51:43 +0200 |
parents | 6edb4219fcf7 |
children | f98bef71a918 |
comparison
equal
deleted
inserted
replaced
504:65ecbb473cbb | 505:2402668b5d05 |
---|---|
23 from twisted.words.xish import domish | 23 from twisted.words.xish import domish |
24 from twisted.internet import protocol, defer, threads, reactor | 24 from twisted.internet import protocol, defer, threads, reactor |
25 from twisted.words.protocols.jabber import client, jid, xmlstream | 25 from twisted.words.protocols.jabber import client, jid, xmlstream |
26 from twisted.words.protocols.jabber import error as jab_error | 26 from twisted.words.protocols.jabber import error as jab_error |
27 from twisted.words.protocols.jabber.xmlstream import IQ | 27 from twisted.words.protocols.jabber.xmlstream import IQ |
28 | |
29 from sat.core import exceptions | |
30 | |
28 import os.path | 31 import os.path |
29 import uuid | 32 import uuid |
30 | 33 |
31 from zope.interface import implements | 34 from zope.interface import implements |
32 | 35 |
50 "main": "XEP_0045", | 53 "main": "XEP_0045", |
51 "handler": "yes", | 54 "handler": "yes", |
52 "description": _("""Implementation of Multi-User Chat""") | 55 "description": _("""Implementation of Multi-User Chat""") |
53 } | 56 } |
54 | 57 |
58 class UnknownRoom(Exception): | |
59 pass | |
60 | |
55 class XEP_0045(): | 61 class XEP_0045(): |
56 | 62 |
57 def __init__(self, host): | 63 def __init__(self, host): |
58 info(_("Plugin XEP_0045 initialization")) | 64 info(_("Plugin XEP_0045 initialization")) |
59 self.host = host | 65 self.host = host |
60 self.clients={} | 66 self.clients={} |
61 host.bridge.addMethod("joinMUC", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._join) | 67 host.bridge.addMethod("joinMUC", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._join) |
68 host.bridge.addMethod("changeNick", ".plugin", in_sign='sss', out_sign='', method=self.changeNick) | |
62 host.bridge.addMethod("getRoomsJoined", ".plugin", in_sign='s', out_sign='a(sass)', method=self.getRoomsJoined) | 69 host.bridge.addMethod("getRoomsJoined", ".plugin", in_sign='s', out_sign='a(sass)', method=self.getRoomsJoined) |
63 host.bridge.addMethod("getRoomsSubjects", ".plugin", in_sign='s', out_sign='a(ss)', method=self.getRoomsSubjects) | 70 host.bridge.addMethod("getRoomsSubjects", ".plugin", in_sign='s', out_sign='a(ss)', method=self.getRoomsSubjects) |
64 host.bridge.addMethod("getUniqueRoomName", ".plugin", in_sign='s', out_sign='s', method=self.getUniqueName) | 71 host.bridge.addMethod("getUniqueRoomName", ".plugin", in_sign='s', out_sign='s', method=self.getUniqueName) |
65 host.bridge.addSignal("roomJoined", ".plugin", signature='sasss') #args: room_jid, room_nicks, user_nick, profile | 72 host.bridge.addSignal("roomJoined", ".plugin", signature='sasss') #args: room_jid, room_nicks, user_nick, profile |
66 host.bridge.addSignal("roomUserJoined", ".plugin", signature='ssa{ss}s') #args: room_jid, user_nick, user_data, profile | 73 host.bridge.addSignal("roomUserJoined", ".plugin", signature='ssa{ss}s') #args: room_jid, user_nick, user_data, profile |
169 warning(mess) | 176 warning(mess) |
170 self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile) | 177 self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile) |
171 return | 178 return |
172 d = self.join(room_jid, nick, options, profile) | 179 d = self.join(room_jid, nick, options, profile) |
173 d.addErrback(lambda x: warning(_('Error while joining room'))) #TODO: error management + signal in bridge | 180 d.addErrback(lambda x: warning(_('Error while joining room'))) #TODO: error management + signal in bridge |
174 | 181 |
182 def nick(self, room_jid, nick, profile_key='@DEFAULT@'): | |
183 profile = self.host.memory.getProfileName(profile_key) | |
184 if not self.__check_profile(profile): | |
185 raise exceptions.UnknownProfileError("Unknown or disconnected profile") | |
186 if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()): | |
187 raise UnknownRoom("This room has not been joined") | |
188 return self.clients[profile].nick(room_jid, nick) | |
189 | |
190 def changeNick(self, room_jid_s, nick, profile_key='@DEFAULT@'): | |
191 """Change nickname in a room""" | |
192 return self.nick(jid.JID(room_jid_s), nick, profile_key) | |
193 | |
175 def getHandler(self, profile): | 194 def getHandler(self, profile): |
176 self.clients[profile] = SatMUCClient(self) | 195 self.clients[profile] = SatMUCClient(self) |
177 return self.clients[profile] | 196 return self.clients[profile] |
178 | 197 |
179 | 198 |