diff options
Diffstat (limited to 'src/multiuserchat.py')
-rw-r--r-- | src/multiuserchat.py | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/multiuserchat.py b/src/multiuserchat.py index 10ea0daf..264f0e4a 100644 --- a/src/multiuserchat.py +++ b/src/multiuserchat.py @@ -67,13 +67,14 @@ def leave_groupchat(xmpp, jid, own_nick, msg): """ xmpp.plugin['xep_0045'].leaveMUC(jid, own_nick, msg) -def eject_user(xmpp, jid, nick, reason): +def set_user_role(xmpp, jid, nick, reason, role): """ - (try to) Eject an user from the room + (try to) Set the role of a MUC user + (role = 'none': eject user) """ iq = xmpp.makeIqSet() query = ET.Element('{%s}query' % NS_MUC_ADMIN) - item = ET.Element('{%s}item' % NS_MUC_ADMIN, {'nick':nick, 'role':'none'}) + item = ET.Element('{%s}item' % NS_MUC_ADMIN, {'nick':nick, 'role':role}) if reason: reason_el = ET.Element('{%s}reason' % NS_MUC_ADMIN) reason_el.text = reason @@ -81,4 +82,26 @@ def eject_user(xmpp, jid, nick, reason): query.append(item) iq.append(query) iq['to'] = jid - return iq.send() + try: + return iq.send() + except Exception as e: + return e.iq + +def set_user_affiliation(xmpp, jid, nick, reason, affiliation): + """ + (try to) Set the affiliation of a MUC user + """ + iq = xmpp.makeIqSet() + query = ET.Element('{%s}query' % NS_MUC_ADMIN) + item = ET.Element('{%s}item' % NS_MUC_ADMIN, {'nick':nick, 'affiliation':affiliation}) + if reason: + reason_el = ET.Element('{%s}reason' % NS_MUC_ADMIN) + reason_el.text = reason + item.append(reason_el) + query.append(item) + iq.append(query) + iq['to'] = jid + try: + return iq.send() + except Exception as e: + return e.iq |