Allow setting the affiliation of a JID, and add outcast affiliation
(also, remove the reason of the affiliation change for the time being)
This commit is contained in:
parent
f76959c78c
commit
ed4f74faf1
2 changed files with 17 additions and 23 deletions
|
@ -88,21 +88,11 @@ def set_user_role(xmpp, jid, nick, reason, role):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return e.iq
|
return e.iq
|
||||||
|
|
||||||
def set_user_affiliation(xmpp, jid, nick, reason, affiliation):
|
def set_user_affiliation(xmpp, muc_jid, affiliation, nick=None, jid=None, reason=None):
|
||||||
"""
|
"""
|
||||||
(try to) Set the affiliation of a MUC user
|
(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:
|
try:
|
||||||
return iq.send()
|
return xmpp.plugin['xep_0045'].set_affiliation(muc_jid, jid, nick, affiliation)
|
||||||
except Exception as e:
|
except:
|
||||||
return e.iq
|
return False
|
||||||
|
|
22
src/tabs.py
22
src/tabs.py
|
@ -533,7 +533,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."), self.completion_ignore)
|
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."), self.completion_ignore)
|
||||||
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."), self.completion_role)
|
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."), self.completion_role)
|
||||||
self.commands['affiliation'] = (self.command_affiliation, _("Usage: /affiliation <nick> <affiliation> [reason]\nAffiliation: Set the affiliation of an user. Affiliations can be: none, member, admin, owner. You also can give an optional reason."), self.completion_affiliation)
|
self.commands['affiliation'] = (self.command_affiliation, _("Usage: /affiliation <nick or jid> <affiliation>\nAffiliation: Set the affiliation of an user. Affiliations can be: outcast, none, member, admin, owner."), self.completion_affiliation)
|
||||||
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.'), self.completion_ignore)
|
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.'), self.completion_ignore)
|
||||||
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)
|
||||||
|
@ -606,6 +606,10 @@ class MucTab(ChatTab):
|
||||||
n += 1
|
n += 1
|
||||||
if n == 2:
|
if n == 2:
|
||||||
userlist = [user.nick for user in self.users]
|
userlist = [user.nick for user in self.users]
|
||||||
|
userlist.remove(self.own_nick)
|
||||||
|
jidlist = [user.jid.bare for user in self.users]
|
||||||
|
jidlist.remove(self.core.xmpp.boundjid.bare)
|
||||||
|
userlist.extend(jidlist)
|
||||||
return the_input.auto_completion(userlist, '')
|
return the_input.auto_completion(userlist, '')
|
||||||
elif n == 3:
|
elif n == 3:
|
||||||
possible_affiliations = ['none', 'member', 'admin', 'owner']
|
possible_affiliations = ['none', 'member', 'admin', 'owner']
|
||||||
|
@ -861,7 +865,7 @@ class MucTab(ChatTab):
|
||||||
|
|
||||||
def command_affiliation(self, arg):
|
def command_affiliation(self, arg):
|
||||||
"""
|
"""
|
||||||
/affiliation <nick> <role> [reason]
|
/affiliation <nick> <role>
|
||||||
Changes the affiliation of an user
|
Changes the affiliation of an user
|
||||||
roles can be: none, visitor, participant, moderator
|
roles can be: none, visitor, participant, moderator
|
||||||
"""
|
"""
|
||||||
|
@ -874,14 +878,14 @@ class MucTab(ChatTab):
|
||||||
reason = ' '.join(args[2:])
|
reason = ' '.join(args[2:])
|
||||||
else:
|
else:
|
||||||
reason = ''
|
reason = ''
|
||||||
if not self.joined or \
|
if not self.joined:
|
||||||
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_affiliation(self.core.xmpp, self.get_name(), nick, reason, affiliation)
|
if nick in [user.nick for user in self.users]:
|
||||||
if res['type'] == 'error':
|
res = muc.set_user_affiliation(self.core.xmpp, self.get_name(), affiliation, nick=nick)
|
||||||
self.core.room_error(res, self.get_name())
|
else:
|
||||||
|
res = muc.set_user_affiliation(self.core.xmpp, self.get_name(), affiliation, jid=nick)
|
||||||
|
if not res:
|
||||||
|
self.core.information('Could not set affiliation', 'Error')
|
||||||
|
|
||||||
def command_say(self, line):
|
def command_say(self, line):
|
||||||
needed = 'inactive' if self.core.status.show in ('xa', 'away') else 'active'
|
needed = 'inactive' if self.core.status.show in ('xa', 'away') else 'active'
|
||||||
|
|
Loading…
Reference in a new issue