Merge branch 'muc-mypy-fixes' into 'master'
XEP-0045: Fix issues found by mypy See merge request poezio/slixmpp!95
This commit is contained in:
commit
ce0d615786
@ -207,6 +207,7 @@ class XEP_0045(BasePlugin):
|
|||||||
entry = self.rooms[room][nick]
|
entry = self.rooms[room][nick]
|
||||||
if entry is not None and entry['jid'].full == jid:
|
if entry is not None and entry['jid'].full == jid:
|
||||||
return nick
|
return nick
|
||||||
|
return None
|
||||||
|
|
||||||
def join_muc(self, room: JID, nick: str, maxhistory="0", password='',
|
def join_muc(self, room: JID, nick: str, maxhistory="0", password='',
|
||||||
pstatus='', pshow='', pfrom=''):
|
pstatus='', pshow='', pfrom=''):
|
||||||
@ -228,8 +229,15 @@ class XEP_0045(BasePlugin):
|
|||||||
self.rooms[room] = {}
|
self.rooms[room] = {}
|
||||||
self.our_nicks[room] = nick
|
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='', *,
|
async def destroy(self, room: JID, reason='', altroom='', *,
|
||||||
ifrom: Optional[JID] = None, **iqkwargs) -> Iq:
|
ifrom: Optional[JID] = None, **iqkwargs):
|
||||||
"""Destroy a room."""
|
"""Destroy a room."""
|
||||||
iq = self.xmpp.make_iq_set(ifrom=ifrom, ito=room)
|
iq = self.xmpp.make_iq_set(ifrom=ifrom, ito=room)
|
||||||
iq.enable('mucowner_query')
|
iq.enable('mucowner_query')
|
||||||
@ -241,7 +249,7 @@ class XEP_0045(BasePlugin):
|
|||||||
await iq.send(**iqkwargs)
|
await iq.send(**iqkwargs)
|
||||||
|
|
||||||
async def set_affiliation(self, room: JID, jid: Optional[JID] = None, nick: Optional[str] = None, *, affiliation: str,
|
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."""
|
""" Change room affiliation."""
|
||||||
if affiliation not in AFFILIATIONS:
|
if affiliation not in AFFILIATIONS:
|
||||||
raise ValueError('%s is not a valid affiliation' % affiliation)
|
raise ValueError('%s is not a valid affiliation' % affiliation)
|
||||||
@ -255,11 +263,13 @@ class XEP_0045(BasePlugin):
|
|||||||
item['nick'] = nick
|
item['nick'] = nick
|
||||||
if jid:
|
if jid:
|
||||||
item['jid'] = jid
|
item['jid'] = jid
|
||||||
|
if reason:
|
||||||
|
item['reason'] = reason
|
||||||
iq['mucadmin_query'].append(item)
|
iq['mucadmin_query'].append(item)
|
||||||
await iq.send(**iqkwargs)
|
await iq.send(**iqkwargs)
|
||||||
|
|
||||||
async def set_role(self, room: JID, nick: str, role: str, *,
|
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.
|
""" Change role property of a nick in a room.
|
||||||
Typically, roles are temporary (they last only as long as you are in the
|
Typically, roles are temporary (they last only as long as you are in the
|
||||||
room), whereas affiliations are permanent (they last across groupchat
|
room), whereas affiliations are permanent (they last across groupchat
|
||||||
@ -272,6 +282,8 @@ class XEP_0045(BasePlugin):
|
|||||||
item = MUCAdminItem()
|
item = MUCAdminItem()
|
||||||
item['role'] = role
|
item['role'] = role
|
||||||
item['nick'] = nick
|
item['nick'] = nick
|
||||||
|
if reason:
|
||||||
|
item['reason'] = reason
|
||||||
iq['mucadmin_query'].append(item)
|
iq['mucadmin_query'].append(item)
|
||||||
await iq.send(**iqkwargs)
|
await iq.send(**iqkwargs)
|
||||||
|
|
||||||
@ -389,11 +401,11 @@ class XEP_0045(BasePlugin):
|
|||||||
""" Get the list of nicks in a room.
|
""" Get the list of nicks in a room.
|
||||||
"""
|
"""
|
||||||
if room not in self.rooms.keys():
|
if room not in self.rooms.keys():
|
||||||
return None
|
raise ValueError("Room %s is not joined" % room)
|
||||||
return self.rooms[room].keys()
|
return self.rooms[room].keys()
|
||||||
|
|
||||||
def get_users_by_affiliation(self, room: JID, affiliation='member', *, ifrom: Optional[JID] = None):
|
def get_users_by_affiliation(self, room: JID, affiliation='member', *, ifrom: Optional[JID] = None):
|
||||||
# Preserve old API
|
# Preserve old API
|
||||||
if affiliation not in AFFILIATIONS:
|
if affiliation not in AFFILIATIONS:
|
||||||
raise TypeError
|
raise ValueError("Affiliation %s does not exist" % affiliation)
|
||||||
return self.get_affiliation_list(room, affiliation, ifrom=ifrom)
|
return self.get_affiliation_list(room, affiliation, ifrom=ifrom)
|
||||||
|
@ -220,7 +220,8 @@ class MUCAdminItem(ElementBase):
|
|||||||
namespace = NS_ADMIN
|
namespace = NS_ADMIN
|
||||||
name = 'item'
|
name = 'item'
|
||||||
plugin_attrib = 'item'
|
plugin_attrib = 'item'
|
||||||
interfaces = {'role', 'affiliation', 'nick', 'jid'}
|
interfaces = {'role', 'affiliation', 'nick', 'jid', 'reason'}
|
||||||
|
sub_interfaces = {'reason'}
|
||||||
|
|
||||||
|
|
||||||
class MUCStatus(ElementBase):
|
class MUCStatus(ElementBase):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user