Mercurial > libervia-backend
changeset 527:9a3913fb0a6c
plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
- /parrot command add parrot link between the current entity/room and the entity given as an argument (must be a valid jid)
- similarly, /unparrot remove the 2 links between those entities.
- Parrot is a new dependency of text commands
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 21 Oct 2012 19:46:08 +0200 |
parents | d67f0ce83530 |
children | f899f6e2a9d1 |
files | src/core/xmpp.py src/plugins/plugin_misc_text_commands.py |
diffstat | 2 files changed, 44 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/core/xmpp.py Sun Oct 21 19:43:14 2012 +0200 +++ b/src/core/xmpp.py Sun Oct 21 19:46:08 2012 +0200 @@ -106,7 +106,7 @@ def onMessage(self, message): debug (_(u"got message from: %s"), message["from"]) - if not self.host.trigger.point("MessageReceived",message, profile=self.parent.profile): + if not self.host.trigger.point("MessageReceived", message, profile=self.parent.profile): return for e in message.elements(): if e.name == "body":
--- a/src/plugins/plugin_misc_text_commands.py Sun Oct 21 19:43:14 2012 +0200 +++ b/src/plugins/plugin_misc_text_commands.py Sun Oct 21 19:46:08 2012 +0200 @@ -27,7 +27,7 @@ "import_name": "text-commands", "type": "Misc", "protocols": [], -"dependencies": ["XEP-0045"], +"dependencies": ["XEP-0045", "EXP-PARROT"], "main": "TextCommands", "handler": "no", "description": _("""IRC like text commands""") @@ -159,6 +159,48 @@ return False + def cmd_parrot(self, mess_data, profile): + """activate Parrot mode between 2 entities, in both directions.""" + debug("Catched parrot command") + + 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: + self._feedBack("Can't activate Parrot mode for invalid jid", mess_data, profile) + return False + + link_right_jid = mess_data['to'] + + self.host.plugins["EXP-PARROT"].addParrot(link_left_jid, link_right_jid, profile) + self.host.plugins["EXP-PARROT"].addParrot(link_right_jid, link_left_jid, profile) + + self._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") + + 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: + self._feedBack("Can't deactivate Parrot mode for invalid jid", mess_data, profile) + return False + + link_right_jid = mess_data['to'] + + self.host.plugins["EXP-PARROT"].removeParrot(link_left_jid, profile) + self.host.plugins["EXP-PARROT"].removeParrot(link_right_jid, profile) + + self._feedBack("Parrot mode deactivated for %s and %s" % (unicode(link_left_jid), unicode(link_right_jid)), mess_data, profile) + + return False + def cmd_help(self, mess_data, profile): """show help on available commands""" commands=filter(lambda method: method.startswith('cmd_'), dir(self))