changeset 515:29b5ef129488

plugin XEP-0045, plugin text commands: added '/title' command
author Goffi <goffi@goffi.org>
date Sat, 20 Oct 2012 18:02:14 +0200 (2012-10-20)
parents fe79a724e6fa
children 7ee15fbe8c08
files src/plugins/plugin_misc_text_commands.py src/plugins/plugin_xep_0045.py
diffstat 2 files changed, 27 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_text_commands.py	Sat Oct 20 17:24:30 2012 +0200
+++ b/src/plugins/plugin_misc_text_commands.py	Sat Oct 20 18:02:14 2012 +0200
@@ -127,3 +127,19 @@
         """just a synonym of /leave"""
         return self.cmd_leave(mess_data, profile)
 
+    def cmd_title(self, mess_data, profile):
+        debug("Catched title command")
+        
+        if mess_data['type'] != "groupchat":
+            #/leave command does nothing if we are not on a group chat
+            info("Ignoring /title command on a non groupchat message")
+            return True
+         
+        subject = mess_data["unparsed"].strip()
+        
+        if subject:
+            room = mess_data["to"]
+            self.host.plugins["XEP-0045"].subject(room, subject, profile)
+
+        return False
+
--- a/src/plugins/plugin_xep_0045.py	Sat Oct 20 17:24:30 2012 +0200
+++ b/src/plugins/plugin_xep_0045.py	Sat Oct 20 18:02:14 2012 +0200
@@ -190,6 +190,14 @@
             raise UnknownRoom("This room has not been joined") 
         return self.clients[profile].leave(room_jid)
 
+    def subject(self, room_jid, subject, profile_key): 
+        profile = self.host.memory.getProfileName(profile_key)
+        if not self.__check_profile(profile):
+            raise exceptions.UnknownProfileError("Unknown or disconnected profile")
+        if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()):
+            raise UnknownRoom("This room has not been joined") 
+        return self.clients[profile].subject(room_jid, subject)
+
     def mucNick(self, room_jid_s, nick, profile_key='@DEFAULT@'):
         """Change nickname in a room"""
         return self.nick(jid.JID(room_jid_s), nick, profile_key)
@@ -216,6 +224,9 @@
         self.__changing_nicks = set() # used to keep trace of who is changing nick,
                                       # and to discard userJoinedRoom signal in this case
         print "init SatMUCClient OK"
+
+    def subject(self, room, subject):
+        return muc.MUCClientProtocol.subject(self, room, subject)
     
     def unavailableReceived(self, presence):
         #XXX: we override this method to manage nickname change
@@ -279,7 +290,6 @@
         self.rec_subjects[room.roomJID.userhost()] = (room.roomJID.userhost(), subject)
         self.host.bridge.roomNewSubject(room.roomJID.userhost(), subject, self.parent.profile)
 
-    
     #def connectionInitialized(self):
         #pass