summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--poezio/core/commands.py2
-rw-r--r--poezio/core/core.py2
-rw-r--r--poezio/multiuserchat.py2
-rw-r--r--poezio/tabs/basetabs.py2
-rw-r--r--poezio/tabs/muctab.py49
5 files changed, 45 insertions, 12 deletions
diff --git a/poezio/core/commands.py b/poezio/core/commands.py
index f3498ed9..b00cf24a 100644
--- a/poezio/core/commands.py
+++ b/poezio/core/commands.py
@@ -3,7 +3,7 @@ Global commands which are to be linked to the Core class
"""
import asyncio
-from xml.etree import cElementTree as ET
+from xml.etree import ElementTree as ET
from typing import List, Optional, Tuple
import logging
diff --git a/poezio/core/core.py b/poezio/core/core.py
index 6065f215..525d02a6 100644
--- a/poezio/core/core.py
+++ b/poezio/core/core.py
@@ -16,7 +16,7 @@ import time
import uuid
from collections import defaultdict
from typing import Callable, Dict, List, Optional, Set, Tuple, Type
-from xml.etree import cElementTree as ET
+from xml.etree import ElementTree as ET
from functools import partial
from slixmpp import JID, InvalidJID
diff --git a/poezio/multiuserchat.py b/poezio/multiuserchat.py
index 47244e3d..30c36a77 100644
--- a/poezio/multiuserchat.py
+++ b/poezio/multiuserchat.py
@@ -10,7 +10,7 @@ Add some facilities that are not available on the XEP_0045
slix plugin
"""
-from xml.etree import cElementTree as ET
+from xml.etree import ElementTree as ET
from poezio.common import safeJID
from slixmpp import JID
diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py
index 7749de6c..73db87f2 100644
--- a/poezio/tabs/basetabs.py
+++ b/poezio/tabs/basetabs.py
@@ -20,7 +20,7 @@ import asyncio
import time
from math import ceil, log10
from datetime import datetime
-from xml.etree import cElementTree as ET
+from xml.etree import ElementTree as ET
from typing import (
Any,
Callable,
diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py
index 3e754ae6..3985a6c7 100644
--- a/poezio/tabs/muctab.py
+++ b/poezio/tabs/muctab.py
@@ -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)
- @command_args_parser.quoted(2)
- 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(self.name)
+ if not room:
+ self.core.information('affiliation: requires a valid chat address', 'Error')
+ return
- if args is None:
+ # List affiliations
+ if not args:
+ asyncio.ensure_future(self.get_users_affiliations(room))
+ return None
+
+ if len(args) != 2:
return self.core.command.help('affiliation')
nick, affiliation = args[0], args[1].lower()
+ # Set affiliation
self.change_affiliation(nick, affiliation)
+ async def get_users_affiliations(self, jid: JID) -> None:
+ MUC_ADMIN_NS = 'http://jabber.org/protocol/muc#admin'
+
+ try:
+ 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(exn.iq, jid)
+ return None
+
+ self._text_buffer.add_message('Affiliations:')
+ for iq in iqs:
+ query = iq.xml.find('{%s}query' % MUC_ADMIN_NS)
+ for item in query.findall('{%s}item' % MUC_ADMIN_NS):
+ self._text_buffer.add_message(
+ '%s: %s' % (item.get('jid'), item.get('affiliation'))
+ )
+ self.core.refresh_window()
+ return None
+
@command_args_parser.raw
def command_say(self, line, correct=False):
"""
@@ -1936,7 +1969,7 @@ class MucTab(ChatTab):
'func':
self.command_affiliation,
'usage':
- '<nick or jid> <affiliation>',
+ '[<nick or jid> [<affiliation>]]',
'desc': ('Set the affiliation of a user. Affiliations can be:'
' outcast, none, member, admin, owner.'),
'shortdesc':