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
This commit is contained in:
parent
c7f12fc904
commit
42b1b6c4ed
1 changed files with 62 additions and 21 deletions
|
|
@ -43,6 +43,8 @@ class TextCommands(object):
|
|||
# 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 @@ class TextCommands(object):
|
|||
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 @@ class TextCommands(object):
|
|||
|
||||
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")
|
||||
|
|
|
|||
Loading…
Reference in a new issue