changeset 508:7c6609dddb2c

plugin text commands: /leave management: - _getRoomJid manage room jid argument: the argument can be full jid or a shortcut. in case of shortcut, room or room@ can be used for shortcut room@service.domain.tld where service.domain.tld is the same as the one of the room where the command is entered - /leave alone leave the current room, /leave [room] leave the given room - /part is a synonym of /leave
author Goffi <goffi@goffi.org>
date Fri, 28 Sep 2012 00:31:10 +0200
parents f98bef71a918
children 64ff046dc201
files src/plugins/plugin_misc_text_commands.py
diffstat 1 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_text_commands.py	Fri Sep 28 00:26:24 2012 +0200
+++ b/src/plugins/plugin_misc_text_commands.py	Fri Sep 28 00:31:10 2012 +0200
@@ -19,6 +19,7 @@
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
+from twisted.words.protocols.jabber import jid
 from logging import debug, info, warning, error
 
 PLUGIN_INFO = {
@@ -60,6 +61,18 @@
                     pass
         return True
 
+    def _getRoomJID(self, arg, service_jid):
+        """Return a room jid with a shortcut
+        @param arg: argument: can be a full room jid (e.g.: sat@chat.jabberfr.org)
+                    or a shortcut (e.g.: sat or sat@ for sat on current service)
+        @param service_jid: jid of the current service (e.g.: chat.jabberfr.org)
+        """
+        nb_arobas = arg.count('@')
+        if nb_arobas == 1:
+            if arg[-1] !='@':
+                return jid.JID(arg)
+            return jid.JID(arg+service_jid)
+        return jid.JID(u"%s@%s" % (arg, service_jid))
 
     def cmd_nick(self, mess_data, profile):
         debug("Catched nick command")
@@ -76,3 +89,25 @@
         self.host.plugins["XEP-0045"].nick(room,nick,profile)
 
         return False
+    
+    def cmd_leave(self, mess_data, profile):
+        debug("Catched leave command")
+        
+        if mess_data['type'] != "groupchat":
+            #/leave command does nothing if we are not on a group chat
+            info("Ignoring /leave command on a non groupchat message")
+            return True
+         
+        if mess_data["unparsed"].strip():
+            room = self._getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host) 
+        else:
+            room = mess_data["to"]
+
+        self.host.plugins["XEP-0045"].leave(room,profile)
+
+        return False
+
+    def cmd_part(self, mess_data, profile):
+        """just a synonym of /leave"""
+        return self.cmd_leave(mess_data, profile)
+