From 07cd259beda5e1f5f6c82529bdd918d909c7b951 Mon Sep 17 00:00:00 2001 From: Denis Fomin Date: Sat, 11 Aug 2012 14:59:05 +0400 Subject: [PATCH] Add 'role' and 'affiliate' command to command system. --- .../implementation/middleware.py | 2 +- src/command_system/implementation/standard.py | 24 +++++++++++++++++++ src/command_system/mapping.py | 8 +++---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/command_system/implementation/middleware.py b/src/command_system/implementation/middleware.py index ce764e816..7c517ea51 100644 --- a/src/command_system/implementation/middleware.py +++ b/src/command_system/implementation/middleware.py @@ -71,7 +71,7 @@ class ChatCommandProcessor(CommandProcessor): except CommandError, error: self.echo_error("%s: %s" % (error.name, error.message)) except Exception: - self.echo_error("Error during command execution!") + self.echo_error(_("Error during command execution!")) print_exc() else: self.command_succeeded = True diff --git a/src/command_system/implementation/standard.py b/src/command_system/implementation/standard.py index 148ee8849..cce5ff9a8 100644 --- a/src/command_system/implementation/standard.py +++ b/src/command_system/implementation/standard.py @@ -352,6 +352,30 @@ class StandardGroupChatCommands(CommandContainer): raise CommandError(_("Nickname not found")) self.connection.gc_set_role(self.room_jid, who, 'none', reason or str()) + @command(raw=True) + @doc(_("""Set occupant role in group chat. + Role can be given as one of the following values: + moderator, participant, visitor, none""")) + def role(self, who, role): + if role not in ('moderator', 'participant', 'visitor', 'none'): + raise CommandError(_("Invalid role given")) + if not who in gajim.contacts.get_nick_list(self.account, self.room_jid): + raise CommandError(_("Nickname not found")) + self.connection.gc_set_role(self.room_jid, who, role) + + @command(raw=True) + @doc(_("""Set occupant affiliation in group chat. + Affiliation can be given as one of the following values: + owner, admin, member, outcast, none""")) + def affiliate(self, who, affiliation): + if affiliation not in ('owner', 'admin', 'member', 'outcast', 'none'): + raise CommandError(_("Invalid affiliation given")) + if not who in gajim.contacts.get_nick_list(self.account, self.room_jid): + raise CommandError(_("Nickname not found")) + contact = gajim.contacts.get_gc_contact(self.account, self.room_jid, who) + self.connection.gc_set_affiliation(self.room_jid, contact.jid, + affiliation) + @command @doc(_("Display names of all group chat occupants")) def names(self, verbose=False): diff --git a/src/command_system/mapping.py b/src/command_system/mapping.py index c8ae3a430..3ba68ff4c 100644 --- a/src/command_system/mapping.py +++ b/src/command_system/mapping.py @@ -162,7 +162,7 @@ def adapt_arguments(command, arguments, args, opts): try: stopper, (start, end) = args[spec_len - 2] except IndexError: - raise CommandError("Missing arguments", command) + raise CommandError(_("Missing arguments"), command) # The essential point of the whole play. After # boundaries are being determined (supposingly correct) @@ -172,7 +172,7 @@ def adapt_arguments(command, arguments, args, opts): raw = raw.strip() or None if not raw and not command.empty: - raise CommandError("Missing arguments", command) + raise CommandError(_("Missing arguments"), command) # Discard residual arguments and all of the options as # raw command does not support options and if an option @@ -192,7 +192,7 @@ def adapt_arguments(command, arguments, args, opts): if command.empty: args.append((None, (0, 0))) else: - raise CommandError("Missing arguments", command) + raise CommandError(_("Missing arguments"), command) # The first stage of transforming options we have got to a format # that can be used to associate them with declared keyword @@ -259,7 +259,7 @@ def adapt_arguments(command, arguments, args, opts): for arg, (spec_key, spec_value) in zip(overlapped, spec_kwargs): opts.append((spec_key, arg)) else: - raise CommandError("Excessive arguments", command) + raise CommandError(_("Excessive arguments"), command) # Detect every switch and ensure it will not receive any arguments. # Normally this does not happen unless overlapping is enabled.