Commit 1f014b6b authored by mathieui's avatar mathieui
Browse files

Merge branch 'affiliations-list' into 'master'

Fix #2280: Allow /affiliation to list all affiliations

Closes #2280

See merge request poezio/poezio!19
parents 854bb0ce 4e0d3d81
......@@ -7,6 +7,7 @@ It keeps track of many things such as part/joins, maintains an
user list, and updates private tabs when necessary.
import asyncio
import bisect
import curses
import logging
......@@ -20,6 +21,7 @@ from datetime import datetime
from typing import Dict, Callable, List, Optional, Union, Set
from slixmpp import InvalidJID, JID
from slixmpp.exceptions import IqError, IqTimeout
from poezio.tabs import ChatTab, Tab, SHOW_NAME
from poezio import common
......@@ -1596,24 +1598,55 @@ class MucTab(ChatTab):
nick, role, reason = args[0], args[1].lower(), args[2]
self.change_role(nick, role, reason)
def command_affiliation(self, args):
@command_args_parser.quoted(0, 2)
def command_affiliation(self, args) -> None:
/affiliation <nick or jid> <affiliation>
/affiliation [<nick or jid> [<affiliation>]]
Changes the affiliation of a user
affiliations can be: outcast, none, member, admin, owner
def callback(iq):
if iq['type'] == 'error':
self.core.room_error(iq, self.jid.bare)
room = JID(
if not room:
self.core.information('affiliation: requires a valid chat address', 'Error')
if args is None:
# List affiliations
if not args:
return None
if len(args) != 2:
nick, affiliation = args[0], args[1].lower()
# Set affiliation
self.change_affiliation(nick, affiliation)
async def get_users_affiliations(self, jid: JID) -> None:
iqs = await asyncio.gather(
self.core.xmpp['xep_0045'].get_users_by_affiliation(jid, 'owner'),
self.core.xmpp['xep_0045'].get_users_by_affiliation(jid, 'admin'),
self.core.xmpp['xep_0045'].get_users_by_affiliation(jid, 'member'),
self.core.xmpp['xep_0045'].get_users_by_affiliation(jid, 'outcast'),
except (IqError, IqTimeout) as exn:
self.core.room_error(, jid)
return None
for iq in iqs:
query = iq.xml.find('{%s}query' % MUC_ADMIN_NS)
for item in query.findall('{%s}item' % MUC_ADMIN_NS):
'%s: %s' % (item.get('jid'), item.get('affiliation'))
return None
def command_say(self, line, correct=False):
......@@ -1936,7 +1969,7 @@ class MucTab(ChatTab):
'<nick or jid> <affiliation>',
'[<nick or jid> [<affiliation>]]',
'desc': ('Set the affiliation of a user. Affiliations can be:'
' outcast, none, member, admin, owner.'),
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment