plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
- registerTextCommands can be called by a plugin in its __init__ method, it looks for methods starting with "cmd_" and register them as new commands
- addWhoIsCb: add a callback to /whois command, the callback can complete whois informations
- plugins parrot, XEP-0045 and XEP-0092 now manage their own commands
This commit is contained in:
parent
1339efa9f0
commit
8a52f6defa
1 changed files with 217 additions and 148 deletions
|
|
@ -18,6 +18,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from sat.core.i18n import _
|
||||
from sat.core.constants import Const as C
|
||||
from logging import debug, info, warning, error
|
||||
from twisted.words.protocols.jabber import jid
|
||||
|
||||
|
|
@ -30,6 +31,7 @@ PLUGIN_INFO = {
|
|||
"type": "EXP",
|
||||
"protocols": [],
|
||||
"dependencies": ["XEP-0045"],
|
||||
"recommendations": [C.TEXT_CMDS],
|
||||
"main": "Exp_Parrot",
|
||||
"handler": "no",
|
||||
"description": _("""Implementation of parrot mode (repeat messages between 2 entities)""")
|
||||
|
|
@ -48,6 +50,10 @@ class Exp_Parrot(object):
|
|||
self.host = host
|
||||
host.trigger.add("MessageReceived", self.MessageReceivedTrigger, priority=100)
|
||||
#host.trigger.add("sendMessage", self.sendMessageTrigger, priority=100)
|
||||
try:
|
||||
self.host.plugins[C.TEXT_CMDS].registerTextCommands(self)
|
||||
except KeyError:
|
||||
info(_("Text commands not available"))
|
||||
|
||||
#def sendMessageTrigger(self, mess_data, treatments, profile):
|
||||
# """ Deactivate other triggers if recipient is in parrot links """
|
||||
|
|
@ -122,3 +128,50 @@ class Exp_Parrot(object):
|
|||
del client.parrot_links[source_jid.userhostJID()]
|
||||
except (AttributeError, KeyError):
|
||||
pass
|
||||
|
||||
def cmd_parrot(self, mess_data, profile):
|
||||
"""activate Parrot mode between 2 entities, in both directions."""
|
||||
#TODO: these commands must not be hardcoded, an interface should be made
|
||||
# to allow plugins to register simple commands like this.
|
||||
|
||||
debug("Catched parrot command")
|
||||
txt_cmd = self.host.plugins[C.TEXT_CMDS]
|
||||
|
||||
try:
|
||||
link_left_jid = jid.JID(mess_data["unparsed"].strip())
|
||||
if not link_left_jid.user or not link_left_jid.host:
|
||||
raise jid.InvalidFormat
|
||||
except jid.InvalidFormat:
|
||||
txt_cmd.feedBack("Can't activate Parrot mode for invalid jid", mess_data, profile)
|
||||
return False
|
||||
|
||||
link_right_jid = mess_data['to']
|
||||
|
||||
self.addParrot(link_left_jid, link_right_jid, profile)
|
||||
self.addParrot(link_right_jid, link_left_jid, profile)
|
||||
|
||||
txt_cmd.feedBack("Parrot mode activated for %s" % (unicode(link_left_jid), ), mess_data, profile)
|
||||
|
||||
return False
|
||||
|
||||
def cmd_unparrot(self, mess_data, profile):
|
||||
"""remove Parrot mode between 2 entities, in both directions."""
|
||||
debug("Catched unparrot command")
|
||||
txt_cmd = self.host.plugins[C.TEXT_CMDS]
|
||||
|
||||
try:
|
||||
link_left_jid = jid.JID(mess_data["unparsed"].strip())
|
||||
if not link_left_jid.user or not link_left_jid.host:
|
||||
raise jid.InvalidFormat
|
||||
except jid.InvalidFormat:
|
||||
txt_cmd.feedBack("Can't deactivate Parrot mode for invalid jid", mess_data, profile)
|
||||
return False
|
||||
|
||||
link_right_jid = mess_data['to']
|
||||
|
||||
self.removeParrot(link_left_jid, profile)
|
||||
self.removeParrot(link_right_jid, profile)
|
||||
|
||||
txt_cmd.feedBack("Parrot mode deactivated for %s and %s" % (unicode(link_left_jid), unicode(link_right_jid)), mess_data, profile)
|
||||
|
||||
return False
|
||||
|
|
|
|||
Loading…
Reference in a new issue