/affiliation command
(without the 'outcast' affiliation ATM)
This commit is contained in:
parent
69c6b38894
commit
b29f11ce19
2 changed files with 34 additions and 9 deletions
|
@ -86,3 +86,22 @@ def set_user_role(xmpp, jid, nick, reason, role):
|
||||||
return iq.send()
|
return iq.send()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return e.iq
|
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
|
||||||
|
|
24
src/tabs.py
24
src/tabs.py
|
@ -405,6 +405,7 @@ class MucTab(ChatTab):
|
||||||
self.commands['unignore'] = (self.command_unignore, _("Usage: /unignore <nickname>\nUnignore: Remove the specified nickname from the ignore list."), self.completion_unignore)
|
self.commands['unignore'] = (self.command_unignore, _("Usage: /unignore <nickname>\nUnignore: Remove the specified nickname from the ignore list."), self.completion_unignore)
|
||||||
self.commands['kick'] = (self.command_kick, _("Usage: /kick <nick> [reason]\nKick: Kick the user with the specified nickname. You also can give an optional reason."), None)
|
self.commands['kick'] = (self.command_kick, _("Usage: /kick <nick> [reason]\nKick: Kick the user with the specified nickname. You also can give an optional reason."), None)
|
||||||
self.commands['role'] = (self.command_role, _("Usage: /role <nick> <role> [reason]\nRole: Set the role of an user. Roles can be: none, visitor, participant, moderator. You also can give an optional reason."), None)
|
self.commands['role'] = (self.command_role, _("Usage: /role <nick> <role> [reason]\nRole: Set the role of an user. Roles can be: none, visitor, participant, moderator. You also can give an optional reason."), None)
|
||||||
|
self.commands['affiliation'] = (self.command_affiliation, _("Usage: /affiliation <nick> <affiliation> [reason]\nAffiliation: Set the affiliation of an user. Affiliations can be: outcast, none, member, admin, owner. You also can give an optional reason."), None)
|
||||||
self.commands['topic'] = (self.command_topic, _("Usage: /topic <subject>\nTopic: Change the subject of the room"), self.completion_topic)
|
self.commands['topic'] = (self.command_topic, _("Usage: /topic <subject>\nTopic: Change the subject of the room"), self.completion_topic)
|
||||||
self.commands['query'] = (self.command_query, _('Usage: /query <nick> [message]\nQuery: Open a private conversation with <nick>. This nick has to be present in the room you\'re currently in. If you specified a message after the nickname, it will immediately be sent to this user'), None)
|
self.commands['query'] = (self.command_query, _('Usage: /query <nick> [message]\nQuery: Open a private conversation with <nick>. This nick has to be present in the room you\'re currently in. If you specified a message after the nickname, it will immediately be sent to this user'), None)
|
||||||
self.commands['part'] = (self.command_part, _("Usage: /part [message]\nPart: disconnect from a room. You can specify an optional message."), None)
|
self.commands['part'] = (self.command_part, _("Usage: /part [message]\nPart: disconnect from a room. You can specify an optional message."), None)
|
||||||
|
@ -651,22 +652,27 @@ class MucTab(ChatTab):
|
||||||
if res['type'] == 'error':
|
if res['type'] == 'error':
|
||||||
self.core.room_error(res, self.get_name())
|
self.core.room_error(res, self.get_name())
|
||||||
|
|
||||||
def _command_change_role(self, role, command, arg):
|
def command_affiliation(self, arg):
|
||||||
"""
|
"""
|
||||||
Changes the role of the nick in args[0]
|
/affiliation <nick> <role> [reason]
|
||||||
|
Changes the affiliation of an user
|
||||||
|
roles can be: none, visitor, participant, moderator
|
||||||
"""
|
"""
|
||||||
args = common.shell_split(arg)
|
args = common.shell_split(arg)
|
||||||
if len(args) < 1:
|
if len(args) < 2:
|
||||||
self.core.command_help(command)
|
self.core.command_help('role')
|
||||||
return
|
return
|
||||||
nick = args[0]
|
nick, affiliation = args[0],args[1]
|
||||||
if len(args) >= 2:
|
if len(args) > 2:
|
||||||
reason = ' '.join(args[1:])
|
reason = ' '.join(args[2:])
|
||||||
else:
|
else:
|
||||||
reason = ''
|
reason = ''
|
||||||
if not self.get_room().joined:
|
if not self.get_room().joined or \
|
||||||
|
not affiliation in ('none', 'member', 'admin', 'owner'):
|
||||||
|
# replace this ↑ with this ↓ when the ban list support is done
|
||||||
|
# not affiliation in ('outcast', 'none', 'member', 'admin', 'owner'):
|
||||||
return
|
return
|
||||||
res = muc.set_user_role(self.core.xmpp, self.get_name(), nick, reason, role)
|
res = muc.set_user_affiliation(self.core.xmpp, self.get_name(), nick, reason, affiliation)
|
||||||
if res['type'] == 'error':
|
if res['type'] == 'error':
|
||||||
self.core.room_error(res, self.get_name())
|
self.core.room_error(res, self.get_name())
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue