changeset 517:59b32c04e105

plugin text commands: added /help command
author Goffi <goffi@goffi.org>
date Sat, 20 Oct 2012 19:22:51 +0200
parents 7ee15fbe8c08
children 75216d94a89d
files src/plugins/plugin_misc_text_commands.py
diffstat 1 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_text_commands.py	Sat Oct 20 18:18:40 2012 +0200
+++ b/src/plugins/plugin_misc_text_commands.py	Sat Oct 20 19:22:51 2012 +0200
@@ -34,6 +34,9 @@
 }
 
 class TextCommands():
+    #FIXME: doc strings for commands have to be translatable
+    #       plugins need a dynamic translation system (translation
+    #       should be downloadable independently)
 
     def __init__(self, host):
         info(_("Text commands initialization"))
@@ -75,6 +78,7 @@
         return jid.JID(u"%s@%s" % (arg, service_jid))
 
     def cmd_nick(self, mess_data, profile):
+        """change nickname"""
         debug("Catched nick command")
         
         if mess_data['type'] != "groupchat":
@@ -91,6 +95,7 @@
         return False
     
     def cmd_join(self, mess_data, profile):
+        """join a new room (on the same service if full jid is not specified)"""
         debug("Catched join command")
         
         if mess_data['type'] != "groupchat":
@@ -107,6 +112,7 @@
         return False
 
     def cmd_leave(self, mess_data, profile):
+        """quit a room"""
         debug("Catched leave command")
         
         if mess_data['type'] != "groupchat":
@@ -128,6 +134,7 @@
         return self.cmd_leave(mess_data, profile)
 
     def cmd_title(self, mess_data, profile):
+        """Change room's subject"""
         debug("Catched title command")
         
         if mess_data['type'] != "groupchat":
@@ -143,3 +150,29 @@
 
         return False
 
+    def cmd_help(self, mess_data, profile):
+        """show help on available commands"""
+        commands=filter(lambda method: method.startswith('cmd_'), dir(self))
+        longuest = max([len(command) for command in commands])
+        help_cmds = []
+        
+        for command in commands:
+            method = getattr(self, command)
+            try:
+                help_str = method.__doc__.split('\n')[0]
+            except AttributeError:
+                help_str = ''
+            spaces = (longuest - len(command)) * ' '
+            help_cmds.append("    /%s: %s %s" % (command[4:], spaces, help_str))
+
+        if mess_data["type"] == 'groupchat':
+            _from = mess_data["to"].userhostJID()
+        else:
+            _from = self.host.getJidNStream(profile)[0]
+
+        help_mess = _(u"Text commands available:\n%s") % (u'\n'.join(help_cmds),) 
+        
+        self.host.bridge.newMessage(unicode(mess_data["to"]), help_mess, mess_data['type'], unicode(_from), {}, profile=profile)
+
+        
+