# HG changeset patch # User Goffi # Date 1350841568 -7200 # Node ID 9a3913fb0a6ced8b013d5a92dade5a3fbbd97180 # Parent d67f0ce83530843dd4a465094dffc2fe89349b35 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 diff -r d67f0ce83530 -r 9a3913fb0a6c src/core/xmpp.py --- 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": diff -r d67f0ce83530 -r 9a3913fb0a6c src/plugins/plugin_misc_text_commands.py --- 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))