comparison src/plugins/plugin_misc_text_commands.py @ 1052:e88bff4c8b77

core (XMPP): sendMessage refactoring: - better separation of message sending actions - use of more generic exceptions to hook the behaviour (SkipHistory and CancelError) - use of raise instead of return - use of failure.trap
author Goffi <goffi@goffi.org>
date Sat, 07 Jun 2014 16:35:29 +0200
parents 24fe24cfb363
children 246712d2e7bc
comparison
equal deleted inserted replaced
1051:854880a31717 1052:e88bff4c8b77
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from sat.core.constants import Const as C 21 from sat.core.constants import Const as C
22 from sat.core.sat_main import MessageSentAndStored 22 from sat.core import exceptions
23 from twisted.words.protocols.jabber import jid 23 from twisted.words.protocols.jabber import jid
24 from twisted.internet import defer 24 from twisted.internet import defer
25 from twisted.python.failure import Failure
26 from sat.core.log import getLogger 25 from sat.core.log import getLogger
27 log = getLogger(__name__) 26 log = getLogger(__name__)
27 from twisted.python import failure
28 28
29 PLUGIN_INFO = { 29 PLUGIN_INFO = {
30 "name": "Text commands", 30 "name": "Text commands",
31 "import_name": C.TEXT_CMDS, 31 "import_name": C.TEXT_CMDS,
32 "type": "Misc", 32 "type": "Misc",
126 126
127 """ 127 """
128 if ret: 128 if ret:
129 return mess_data 129 return mess_data
130 else: 130 else:
131 return Failure(MessageSentAndStored("text commands took over", mess_data)) 131 log.debug("text commands took over")
132 raise failure.Failure(exceptions.CancelError())
132 133
133 try: 134 try:
134 mess_data["unparsed"] = msg[1 + len(command):] # part not yet parsed of the message 135 mess_data["unparsed"] = msg[1 + len(command):] # part not yet parsed of the message
135 d = defer.maybeDeferred(self._commands[command], mess_data, profile) 136 d = defer.maybeDeferred(self._commands[command], mess_data, profile)
136 d.addCallback(retHandling) 137 d.addCallback(retHandling)
137 except KeyError: 138 except KeyError:
138 self.feedBack(_("Unknown command /%s. ") % command + self.HELP_SUGGESTION, mess_data, profile) 139 self.feedBack(_("Unknown command /%s. ") % command + self.HELP_SUGGESTION, mess_data, profile)
139 return Failure(MessageSentAndStored("text commands took over", mess_data)) 140 self.debug("text commands took over")
141 raise failure.Failure(exceptions.CancelError())
140 142
141 return d or mess_data # if a command is detected, we should have a deferred, else we send the message normally 143 return d or mess_data # if a command is detected, we should have a deferred, else we send the message normally
142 144
143 def getRoomJID(self, arg, service_jid): 145 def getRoomJID(self, arg, service_jid):
144 """Return a room jid with a shortcut 146 """Return a room jid with a shortcut