From 306519f6e9a351fe11fee87733728f2fbddbf76a Mon Sep 17 00:00:00 2001
From: Alexander Cherniuk <ts33kr@gmail.com>
Date: Tue, 22 Dec 2009 21:31:11 +0200
Subject: [PATCH] Added /status, /away, /online commands. Fixed command error
 reporting

---
 src/command_system/errors.py                  |  3 ++
 src/command_system/implementation/standard.py | 29 +++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/src/command_system/errors.py b/src/command_system/errors.py
index f687b72e37..4281e9fd7b 100644
--- a/src/command_system/errors.py
+++ b/src/command_system/errors.py
@@ -30,6 +30,9 @@ class BaseError(Exception):
 
         super(BaseError, self).__init__()
 
+    def __str__(self):
+        return self.message
+
 class DefinitionError(BaseError):
     """
     Used to indicate errors occured on command definition.
diff --git a/src/command_system/implementation/standard.py b/src/command_system/implementation/standard.py
index d0e585fec6..1ae3c91dd4 100644
--- a/src/command_system/implementation/standard.py
+++ b/src/command_system/implementation/standard.py
@@ -128,6 +128,35 @@ class StandardCommonCommands(CommandContainer):
 
             self.echo(formatted)
 
+    @command(raw=True, empty=True)
+    @documentation(_("""
+    Set current the status
+
+    Status can be given as one of the following values: online, away,
+    chat, xa, dnd.
+    """))
+    def status(self, status, message):
+        if status not in ('online', 'away', 'chat', 'xa', 'dnd'):
+            raise CommandError("Invalid status given")
+        for connection in gajim.connections.itervalues():
+            connection.change_status(status, message)
+
+    @command(raw=True, empty=True)
+    @documentation(_("Set the current status to away"))
+    def away(self, message):
+        if not message:
+            message = _("Away")
+        for connection in gajim.connections.itervalues():
+            connection.change_status('away', message)
+
+    @command('back', raw=True, empty=True)
+    @documentation(_("Set the current status to online"))
+    def online(self, message):
+        if not message:
+            message = _("Available")
+        for connection in gajim.connections.itervalues():
+            connection.change_status('online', message)
+
 class StandardChatCommands(CommandContainer):
     """
     This command container contains standard command which are unique to a chat.
-- 
GitLab