parent
6c63cdb509
commit
ae0888bd3d
1 changed files with 31 additions and 13 deletions
|
@ -240,7 +240,6 @@ class MucTab(ChatTab):
|
||||||
"""
|
"""
|
||||||
Change the affiliation of a nick or JID
|
Change the affiliation of a nick or JID
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not self.joined:
|
if not self.joined:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -250,26 +249,45 @@ class MucTab(ChatTab):
|
||||||
'The affiliation must be one of ' +
|
'The affiliation must be one of ' +
|
||||||
', '.join(valid_affiliations), 'Error')
|
', '.join(valid_affiliations), 'Error')
|
||||||
return
|
return
|
||||||
if nick_or_jid in [user.nick for user in self.users]:
|
jid = None
|
||||||
nick = nick_or_jid
|
nick = None
|
||||||
jid = None
|
for user in self.users:
|
||||||
else:
|
if user.nick == nick_or_jid:
|
||||||
nick = None
|
jid = user.jid
|
||||||
|
nick = user.nick
|
||||||
|
break
|
||||||
|
if jid is None:
|
||||||
try:
|
try:
|
||||||
jid = JID(nick_or_jid)
|
jid = JID(nick_or_jid)
|
||||||
except InvalidJID:
|
except InvalidJID:
|
||||||
self.core.information('Invalid JID or missing occupant: %s' % nick_or_jid, 'Error')
|
self.core.information(
|
||||||
|
f'Invalid JID or missing occupant: {nick_or_jid}',
|
||||||
|
'Error'
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
async def do_set_affiliation(room: JID, jid: Optional[JID], nick: Optional[str], affiliation: str, reason: str):
|
async def do_set_affiliation(room: JID, jid: JID, nick: Optional[str], affiliation: str, reason: str):
|
||||||
try:
|
try:
|
||||||
await self.core.xmpp['xep_0045'].set_affiliation(room, jid, nick, affiliation=affiliation, reason=reason)
|
await self.core.xmpp['xep_0045'].set_affiliation(
|
||||||
except (IqError, IqTimeout) as e:
|
room,
|
||||||
|
nick=nick,
|
||||||
|
jid=jid,
|
||||||
|
affiliation=affiliation,
|
||||||
|
reason=reason
|
||||||
|
)
|
||||||
self.core.information(
|
self.core.information(
|
||||||
"Could not set affiliation '%s' for '%s': %s" %
|
f"Affiliation of {jid} set to {affiliation} successfully",
|
||||||
(affiliation, nick_or_jid, e), "Warning")
|
"Info"
|
||||||
|
)
|
||||||
|
except (IqError, IqTimeout) as exc:
|
||||||
|
self.core.information(
|
||||||
|
f"Could not set affiliation '{affiliation}' for '{jid}': {exc}",
|
||||||
|
"Warning",
|
||||||
|
)
|
||||||
|
|
||||||
asyncio.ensure_future(do_set_affiliation(self.jid.bare, jid, nick, affiliation, reason))
|
asyncio.ensure_future(
|
||||||
|
do_set_affiliation(self.jid.bare, jid, nick, affiliation, reason)
|
||||||
|
)
|
||||||
|
|
||||||
def change_role(self, nick: str, role: str, reason: str = '') -> None:
|
def change_role(self, nick: str, role: str, reason: str = '') -> None:
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue