Mercurial > libervia-backend
diff src/plugins/plugin_misc_text_commands.py @ 1002:291eb8216f6e
plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
- give a feedback instead of sending the message when the command is invalid or used in a wrong context
- add command /join for XEP-0249
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 30 Apr 2014 16:34:09 +0200 |
parents | 301b342c697a |
children | 24fe24cfb363 |
line wrap: on
line diff
--- a/src/plugins/plugin_misc_text_commands.py Sun Apr 27 18:51:03 2014 +0200 +++ b/src/plugins/plugin_misc_text_commands.py Wed Apr 30 16:34:09 2014 +0200 @@ -43,6 +43,8 @@ # plugins need a dynamic translation system (translation # should be downloadable independently) + HELP_SUGGESTION = _("Type '/help' to get a list of the available commands. If you didn't want to use a command, please start your message with '//' to escape the slash.") + def __init__(self, host): log.info(_("Text commands initialization")) self.host = host @@ -133,9 +135,10 @@ d = defer.maybeDeferred(self._commands[command], mess_data, profile) d.addCallback(retHandling) except KeyError: - pass + self.feedBack(_("Unknown command /%s. ") % command + self.HELP_SUGGESTION, mess_data, profile) + return Failure(MessageSentAndStored("text commands took over", mess_data)) - return d or mess_data # if a command is detected, we should have a deferred, else be send the message normally + return d or mess_data # if a command is detected, we should have a deferred, else we send the message normally def getRoomJID(self, arg, service_jid): """Return a room jid with a shortcut @@ -159,6 +162,19 @@ self.host.bridge.newMessage(unicode(mess_data["to"]), message, mess_data['type'], unicode(_from), {}, profile=profile) + def feedBackWrongContext(self, command, types, mess_data, profile): + """Give a generic message to the user when a command has been used in a wrong context. + + @param command (string): the command name (without the slash) + @param types (string, list): the message types to which the command applies. + @param mess_data (dict): original message data + @param profile: %(doc_profile)s + """ + if not isinstance(types, str): + types = _(' or ').join(types) + feedback = _("/%(command)s command only applies on %(type)s messages. ") % {'command': command, 'type': types} + self.host.plugins[C.TEXT_CMDS].feedBack(feedback + self.HELP_SUGGESTION, mess_data, profile) + def cmd_whois(self, mess_data, profile): """show informations on entity""" log.debug("Catched whois command")