comparison 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
comparison
equal deleted inserted replaced
1001:eb3601ff73bc 1002:291eb8216f6e
40 40
41 class TextCommands(object): 41 class TextCommands(object):
42 #FIXME: doc strings for commands have to be translatable 42 #FIXME: doc strings for commands have to be translatable
43 # plugins need a dynamic translation system (translation 43 # plugins need a dynamic translation system (translation
44 # should be downloadable independently) 44 # should be downloadable independently)
45
46 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.")
45 47
46 def __init__(self, host): 48 def __init__(self, host):
47 log.info(_("Text commands initialization")) 49 log.info(_("Text commands initialization"))
48 self.host = host 50 self.host = host
49 host.trigger.add("sendMessage", self.sendMessageTrigger) 51 host.trigger.add("sendMessage", self.sendMessageTrigger)
131 try: 133 try:
132 mess_data["unparsed"] = msg[1 + len(command):] # part not yet parsed of the message 134 mess_data["unparsed"] = msg[1 + len(command):] # part not yet parsed of the message
133 d = defer.maybeDeferred(self._commands[command], mess_data, profile) 135 d = defer.maybeDeferred(self._commands[command], mess_data, profile)
134 d.addCallback(retHandling) 136 d.addCallback(retHandling)
135 except KeyError: 137 except KeyError:
136 pass 138 self.feedBack(_("Unknown command /%s. ") % command + self.HELP_SUGGESTION, mess_data, profile)
137 139 return Failure(MessageSentAndStored("text commands took over", mess_data))
138 return d or mess_data # if a command is detected, we should have a deferred, else be send the message normally 140
141 return d or mess_data # if a command is detected, we should have a deferred, else we send the message normally
139 142
140 def getRoomJID(self, arg, service_jid): 143 def getRoomJID(self, arg, service_jid):
141 """Return a room jid with a shortcut 144 """Return a room jid with a shortcut
142 @param arg: argument: can be a full room jid (e.g.: sat@chat.jabberfr.org) 145 @param arg: argument: can be a full room jid (e.g.: sat@chat.jabberfr.org)
143 or a shortcut (e.g.: sat or sat@ for sat on current service) 146 or a shortcut (e.g.: sat or sat@ for sat on current service)
157 else: 160 else:
158 _from = self.host.getJidNStream(profile)[0] 161 _from = self.host.getJidNStream(profile)[0]
159 162
160 self.host.bridge.newMessage(unicode(mess_data["to"]), message, mess_data['type'], unicode(_from), {}, profile=profile) 163 self.host.bridge.newMessage(unicode(mess_data["to"]), message, mess_data['type'], unicode(_from), {}, profile=profile)
161 164
165 def feedBackWrongContext(self, command, types, mess_data, profile):
166 """Give a generic message to the user when a command has been used in a wrong context.
167
168 @param command (string): the command name (without the slash)
169 @param types (string, list): the message types to which the command applies.
170 @param mess_data (dict): original message data
171 @param profile: %(doc_profile)s
172 """
173 if not isinstance(types, str):
174 types = _(' or ').join(types)
175 feedback = _("/%(command)s command only applies on %(type)s messages. ") % {'command': command, 'type': types}
176 self.host.plugins[C.TEXT_CMDS].feedBack(feedback + self.HELP_SUGGESTION, mess_data, profile)
177
162 def cmd_whois(self, mess_data, profile): 178 def cmd_whois(self, mess_data, profile):
163 """show informations on entity""" 179 """show informations on entity"""
164 log.debug("Catched whois command") 180 log.debug("Catched whois command")
165 181
166 entity = mess_data["unparsed"].strip() 182 entity = mess_data["unparsed"].strip()