summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2020-12-27 19:44:31 +0100
committermathieui <mathieui@mathieui.net>2020-12-27 19:44:31 +0100
commitce0d615786bccb1998df277d693880bb247e069d (patch)
treea12fd365eb1dc56b46cf1229ff5599231ebdcafd
parentd91eea3a3afdeb3cfe6ea4c913dcaff32a07b318 (diff)
parent1e08c900185dec05111fb9f158497c8b3ff634d3 (diff)
downloadslixmpp-ce0d615786bccb1998df277d693880bb247e069d.tar.gz
slixmpp-ce0d615786bccb1998df277d693880bb247e069d.tar.bz2
slixmpp-ce0d615786bccb1998df277d693880bb247e069d.tar.xz
slixmpp-ce0d615786bccb1998df277d693880bb247e069d.zip
Merge branch 'muc-mypy-fixes' into 'master'
XEP-0045: Fix issues found by mypy See merge request poezio/slixmpp!95
-rw-r--r--slixmpp/plugins/xep_0045/muc.py22
-rw-r--r--slixmpp/plugins/xep_0045/stanza.py3
2 files changed, 19 insertions, 6 deletions
diff --git a/slixmpp/plugins/xep_0045/muc.py b/slixmpp/plugins/xep_0045/muc.py
index 82c07edd..4220978d 100644
--- a/slixmpp/plugins/xep_0045/muc.py
+++ b/slixmpp/plugins/xep_0045/muc.py
@@ -207,6 +207,7 @@ class XEP_0045(BasePlugin):
entry = self.rooms[room][nick]
if entry is not None and entry['jid'].full == jid:
return nick
+ return None
def join_muc(self, room: JID, nick: str, maxhistory="0", password='',
pstatus='', pshow='', pfrom=''):
@@ -228,8 +229,15 @@ class XEP_0045(BasePlugin):
self.rooms[room] = {}
self.our_nicks[room] = nick
+ def set_subject(self, room: JID, subject: str, *, mfrom: Optional[JID] = None):
+ """Set a room’s subject."""
+ msg = self.xmpp.make_message(room, mfrom=mfrom)
+ msg['type'] = 'groupchat'
+ msg['subject'] = subject
+ msg.send()
+
async def destroy(self, room: JID, reason='', altroom='', *,
- ifrom: Optional[JID] = None, **iqkwargs) -> Iq:
+ ifrom: Optional[JID] = None, **iqkwargs):
"""Destroy a room."""
iq = self.xmpp.make_iq_set(ifrom=ifrom, ito=room)
iq.enable('mucowner_query')
@@ -241,7 +249,7 @@ class XEP_0045(BasePlugin):
await iq.send(**iqkwargs)
async def set_affiliation(self, room: JID, jid: Optional[JID] = None, nick: Optional[str] = None, *, affiliation: str,
- ifrom: Optional[JID] = None, **iqkwargs):
+ reason: str = '', ifrom: Optional[JID] = None, **iqkwargs):
""" Change room affiliation."""
if affiliation not in AFFILIATIONS:
raise ValueError('%s is not a valid affiliation' % affiliation)
@@ -255,11 +263,13 @@ class XEP_0045(BasePlugin):
item['nick'] = nick
if jid:
item['jid'] = jid
+ if reason:
+ item['reason'] = reason
iq['mucadmin_query'].append(item)
await iq.send(**iqkwargs)
async def set_role(self, room: JID, nick: str, role: str, *,
- ifrom: Optional[JID] = None, **iqkwargs) -> Iq:
+ reason: str = '', ifrom: Optional[JID] = None, **iqkwargs):
""" Change role property of a nick in a room.
Typically, roles are temporary (they last only as long as you are in the
room), whereas affiliations are permanent (they last across groupchat
@@ -272,6 +282,8 @@ class XEP_0045(BasePlugin):
item = MUCAdminItem()
item['role'] = role
item['nick'] = nick
+ if reason:
+ item['reason'] = reason
iq['mucadmin_query'].append(item)
await iq.send(**iqkwargs)
@@ -389,11 +401,11 @@ class XEP_0045(BasePlugin):
""" Get the list of nicks in a room.
"""
if room not in self.rooms.keys():
- return None
+ raise ValueError("Room %s is not joined" % room)
return self.rooms[room].keys()
def get_users_by_affiliation(self, room: JID, affiliation='member', *, ifrom: Optional[JID] = None):
# Preserve old API
if affiliation not in AFFILIATIONS:
- raise TypeError
+ raise ValueError("Affiliation %s does not exist" % affiliation)
return self.get_affiliation_list(room, affiliation, ifrom=ifrom)
diff --git a/slixmpp/plugins/xep_0045/stanza.py b/slixmpp/plugins/xep_0045/stanza.py
index 64224949..8de938fb 100644
--- a/slixmpp/plugins/xep_0045/stanza.py
+++ b/slixmpp/plugins/xep_0045/stanza.py
@@ -220,7 +220,8 @@ class MUCAdminItem(ElementBase):
namespace = NS_ADMIN
name = 'item'
plugin_attrib = 'item'
- interfaces = {'role', 'affiliation', 'nick', 'jid'}
+ interfaces = {'role', 'affiliation', 'nick', 'jid', 'reason'}
+ sub_interfaces = {'reason'}
class MUCStatus(ElementBase):