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
This commit is contained in:
Goffi 2014-06-07 16:35:29 +02:00
commit 87b3e413ee
4 changed files with 74 additions and 71 deletions

View file

@ -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 @@ class TextCommands(object):
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 @@ class TextCommands(object):
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