diff src/plugins/plugin_misc_text_commands.py @ 518:75216d94a89d

primitivus: fixed messages order in chat window
author Goffi <goffi@goffi.org>
date Sun, 21 Oct 2012 12:03:29 +0200
parents 59b32c04e105
children b7577230a7c8
line wrap: on
line diff
--- a/src/plugins/plugin_misc_text_commands.py	Sat Oct 20 19:22:51 2012 +0200
+++ b/src/plugins/plugin_misc_text_commands.py	Sun Oct 21 12:03:29 2012 +0200
@@ -77,6 +77,15 @@
             return jid.JID(arg+service_jid)
         return jid.JID(u"%s@%s" % (arg, service_jid))
 
+    def _feedBack(self, message, mess_data, profile):
+        """Give a message back to the user"""
+        if mess_data["type"] == 'groupchat':
+            _from = mess_data["to"].userhostJID()
+        else:
+            _from = self.host.getJidNStream(profile)[0]
+
+        self.host.bridge.newMessage(unicode(mess_data["to"]), message, mess_data['type'], unicode(_from), {}, profile=profile)
+
     def cmd_nick(self, mess_data, profile):
         """change nickname"""
         debug("Catched nick command")
@@ -150,6 +159,29 @@
 
         return False
 
+    def cmd_ignore(self, mess_data, profile):
+        """Add an entity to ignore list"""
+        nick = mess_data["unparsed"].strip()
+
+        if mess_data['type'] == "groupchat":
+            #if we are in a group chat, a nick must be given as argument
+            if not nick:
+                return False
+            room = mess_data["to"]
+            if not self.host.plugins["XEP-0045"].isNickInRoom(room, nick):
+                self._feedBack(u"[%s] is not in this room, can't ignore it" % (nick,), mess_data, profile)
+                return False
+            full_jid = jid.JID(u"%s/%s" % (room.userhost(), nick))
+        else:
+            if nick:
+                self._feedBack("/ignore doesn't support arguments if you are not in a room", mess_data, profile)
+                return False
+            full_jid = mess_data["to"]
+
+        self.host.getClient(profile).ignore(full_jid)
+        self._feedBack(_(u"[%s] added to ignore list") % full_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))
@@ -165,14 +197,7 @@
             spaces = (longuest - len(command)) * ' '
             help_cmds.append("    /%s: %s %s" % (command[4:], spaces, help_str))
 
-        if mess_data["type"] == 'groupchat':
-            _from = mess_data["to"].userhostJID()
-        else:
-            _from = self.host.getJidNStream(profile)[0]
-
         help_mess = _(u"Text commands available:\n%s") % (u'\n'.join(help_cmds),) 
-        
-        self.host.bridge.newMessage(unicode(mess_data["to"]), help_mess, mess_data['type'], unicode(_from), {}, profile=profile)
-
+        self._feedBack(help_mess, mess_data, profile)