plugin text commands: added /help command
This commit is contained in:
parent
b5ddf942f7
commit
8d34cacc1d
1 changed files with 33 additions and 0 deletions
|
|
@ -34,6 +34,9 @@ PLUGIN_INFO = {
|
|||
}
|
||||
|
||||
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 @@ class TextCommands():
|
|||
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 @@ class TextCommands():
|
|||
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 @@ class TextCommands():
|
|||
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 @@ class TextCommands():
|
|||
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 @@ class TextCommands():
|
|||
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue