diff 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
line wrap: on
line diff
--- a/src/plugins/plugin_misc_text_commands.py	Tue Jun 03 17:10:12 2014 +0200
+++ b/src/plugins/plugin_misc_text_commands.py	Sat Jun 07 16:35:29 2014 +0200
@@ -19,12 +19,12 @@
 
 from sat.core.i18n import _
 from sat.core.constants import Const as C
-from sat.core.sat_main import MessageSentAndStored
+from sat.core import exceptions
 from twisted.words.protocols.jabber import jid
 from twisted.internet import defer
-from twisted.python.failure import Failure
 from sat.core.log import getLogger
 log = getLogger(__name__)
+from twisted.python import failure
 
 PLUGIN_INFO = {
     "name": "Text commands",
@@ -128,7 +128,8 @@
                 if ret:
                     return mess_data
                 else:
-                    return Failure(MessageSentAndStored("text commands took over", mess_data))
+                    log.debug("text commands took over")
+                    raise failure.Failure(exceptions.CancelError())
 
             try:
                 mess_data["unparsed"] = msg[1 + len(command):]  # part not yet parsed of the message
@@ -136,7 +137,8 @@
                 d.addCallback(retHandling)
             except KeyError:
                 self.feedBack(_("Unknown command /%s. ") % command + self.HELP_SUGGESTION, mess_data, profile)
-                return Failure(MessageSentAndStored("text commands took over", mess_data))
+                self.debug("text commands took over")
+                raise failure.Failure(exceptions.CancelError())
 
         return d or mess_data  # if a command is detected, we should have a deferred, else we send the message normally