diff options
Diffstat (limited to 'slixmpp/plugins/xep_0045/stanza.py')
-rw-r--r-- | slixmpp/plugins/xep_0045/stanza.py | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/slixmpp/plugins/xep_0045/stanza.py b/slixmpp/plugins/xep_0045/stanza.py index 9756790b..71223f0d 100644 --- a/slixmpp/plugins/xep_0045/stanza.py +++ b/slixmpp/plugins/xep_0045/stanza.py @@ -7,6 +7,7 @@ See the file LICENSE for copying permission. """ +from typing import Iterable, Set import logging from slixmpp.xmlstream import ElementBase, ET, JID @@ -23,7 +24,26 @@ class MUCBase(ElementBase): name = 'x' namespace = NS_USER plugin_attrib = 'muc' - interfaces = {'affiliation', 'role', 'jid', 'nick', 'room'} + interfaces = {'affiliation', 'role', 'jid', 'nick', 'room', 'status_codes'} + + def get_status_codes(self) -> Set[str]: + status = self.xml.findall(f'{{{NS_USER}}}status') + return {int(status.attrib['code']) for status in status} + + def set_status_codes(self, codes: Iterable[int]): + self.del_status_codes() + for code in set(codes): + self._add_status_code(code) + + def del_status_codes(self): + status = self.xml.findall(f'{{{NS_USER}}}status') + for elem in status: + self.xml.remove(elem) + + def _add_status_code(self, code: int): + status = MUCStatus() + status['code'] = code + self.append(status) def get_item_attr(self, attr, default: str): item = self.xml.find(f'{{{NS_USER}}}item') @@ -49,12 +69,10 @@ class MUCBase(ElementBase): def set_affiliation(self, value): self.set_item_attr('affiliation', value) - return self def del_affiliation(self): # TODO: set default affiliation self.del_item_attr('affiliation') - return self def get_jid(self): return JID(self.get_item_attr('jid', '')) @@ -63,11 +81,9 @@ class MUCBase(ElementBase): if not isinstance(value, str): value = str(value) self.set_item_attr('jid', value) - return self def del_jid(self): self.del_item_attr('jid') - return self def get_role(self): return self.get_item_attr('role', '') @@ -75,12 +91,10 @@ class MUCBase(ElementBase): def set_role(self, value): # TODO: check for valid role self.set_item_attr('role', value) - return self def del_role(self): # TODO: set default role self.del_item_attr('role') - return self def get_nick(self): return self.parent()['from'].resource @@ -160,7 +174,15 @@ class MUCInvite(ElementBase): name = 'invite' plugin_attrib = 'invite' namespace = NS_USER - interfaces = {'to', 'reason'} + interfaces = {'to', 'from', 'reason'} + sub_interfaces = {'reason'} + + +class MUCDecline(ElementBase): + name = 'decline' + plugin_attrib = 'decline' + namespace = NS_USER + interfaces = {'to', 'from', 'reason'} sub_interfaces = {'reason'} @@ -196,3 +218,12 @@ class MUCAdminItem(ElementBase): plugin_attrib = 'item' interfaces = {'role', 'affiliation', 'nick', 'jid'} + +class MUCStatus(ElementBase): + namespace = NS_USER + name = 'status' + plugin_attrib = 'status' + interfaces = {'code'} + + def set_code(self, code: int): + self.xml.attrib['code'] = str(code) |