# HG changeset patch # User souliane # Date 1384885919 -3600 # Node ID f47d7c09c60b9c2b2927ab717df029506d0e4dd6 # Parent ecc5a5b34ee13d111b8e7f6a391d5c3144040ff0 plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger diff -r ecc5a5b34ee1 -r f47d7c09c60b src/plugins/plugin_xep_0045.py --- a/src/plugins/plugin_xep_0045.py Mon Nov 18 14:25:40 2013 +0100 +++ b/src/plugins/plugin_xep_0045.py Tue Nov 19 19:31:59 2013 +0100 @@ -130,6 +130,44 @@ return '' return self.clients[profile].joined_rooms[room_jid_s].nick + def getRoomNickOfUser(self, room, user_jid, secure=True): + """Returns the nick of the given user in the room. + @room: instance of wokkel.muc.Room + @user: JID or unicode (JID userhost). + @param secure: set to True for a secure check + @return: the nick or None if the user didn't join the room. + """ + if not isinstance(user_jid, jid.JID): + user_jid = jid.JID(user_jid) + for user in room.roster.values(): + if user.entity is not None: + if user.entity.userhostJID() == user_jid.userhostJID(): + return user.nick + elif not secure: + # FIXME: this is NOT ENOUGH to check an identity!! + # See in which conditions user.entity could be None. + if user.nick == user_jid.user: + return user.nick + return None + + def getRoomNicksOfUsers(self, room, users=[], secure=True): + """Returns the nicks of the given users in the room. + @room: instance of wokkel.muc.Room + @users: list of JID or unicode (JID userhost). + @param secure: set to True for a secure check + @return: (x, y) with x a list containing the nicks of + the users who are in the room, and y the missing users. + """ + nicks = [] + missing = [] + for user in users: + nick = self.getRoomNickOfUser(room, user, secure) + if nick is None: + missing.append(user) + else: + nicks.append(nick) + return nicks, missing + def isNickInRoom(self, room_jid, nick, profile): """Tell if a nick is currently present in a room""" profile = self.host.memory.getProfileName(profile) @@ -308,6 +346,8 @@ self.host.bridge.roomUserJoined(room.roomJID.userhost(), user.nick, user_data, self.parent.profile) def userLeftRoom(self, room, user): + if not self.host.trigger.point("MUC user left", room, user, self.parent.profile): + return if user.nick == room.nick: # we left the room room_jid_s = room.roomJID.userhost()