diff src/plugins/plugin_misc_text_commands.py @ 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 24c0d51449e7
children 790be337cc41
line wrap: on
line diff
--- 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))