From 4225b694d0f83fdd5cd6b389e999743ddab59d9e Mon Sep 17 00:00:00 2001 From: Goffi Date: Fri, 28 Sep 2012 00:48:52 +0200 Subject: [PATCH] plugin text commands: added /join command --- src/plugins/plugin_misc_text_commands.py | 16 ++++++++++++++++ src/plugins/plugin_xep_0045.py | 8 ++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/plugins/plugin_misc_text_commands.py b/src/plugins/plugin_misc_text_commands.py index 0a3ff657..7d29225a 100755 --- a/src/plugins/plugin_misc_text_commands.py +++ b/src/plugins/plugin_misc_text_commands.py @@ -90,6 +90,22 @@ class TextCommands(): return False + def cmd_join(self, mess_data, profile): + debug("Catched join command") + + if mess_data['type'] != "groupchat": + #/leave command does nothing if we are not on a group chat + info("Ignoring /join command on a non groupchat message") + return True + + if mess_data["unparsed"].strip(): + room = self._getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host) + nick = (self.host.plugins["XEP-0045"].getRoomNick(mess_data["to"].userhost(), profile) or + self.host.getClient(profile).jid.user) + self.host.plugins["XEP-0045"].join(room, nick, {}, profile) + + return False + def cmd_leave(self, mess_data, profile): debug("Catched leave command") diff --git a/src/plugins/plugin_xep_0045.py b/src/plugins/plugin_xep_0045.py index b0990802..0a258080 100755 --- a/src/plugins/plugin_xep_0045.py +++ b/src/plugins/plugin_xep_0045.py @@ -117,15 +117,15 @@ class XEP_0045(): result.append((room.roomJID.userhost(), [user.nick for user in room.roster.values()], room.nick)) return result - def getRoomNick(self, room_jid, profile_key='@DEFAULT@'): + def getRoomNick(self, room_jid_s, profile_key='@DEFAULT@'): """return nick used in room by user - @param room_jid: unicode room id + @param room_jid_s: unicode room id @profile_key: profile @return: nick or empty string in case of error""" profile = self.host.memory.getProfileName(profile_key) - if not self.__check_profile(profile) or not self.clients[profile].joined_rooms.has_key(room_jid): + if not self.__check_profile(profile) or not self.clients[profile].joined_rooms.has_key(room_jid_s): return '' - return self.clients[profile].joined_rooms[room_jid].nick + return self.clients[profile].joined_rooms[room_jid_s].nick def getRoomsSubjects(self, profile_key='@DEFAULT@'): """Return received subjects of rooms"""