comparison src/plugins/plugin_xep_0045.py @ 715:f47d7c09c60b

plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
author souliane <souliane@mailoo.org>
date Tue, 19 Nov 2013 19:31:59 +0100
parents 8bd63daecdbf
children 03744d9ebc13
comparison
equal deleted inserted replaced
714:ecc5a5b34ee1 715:f47d7c09c60b
128 profile = self.host.memory.getProfileName(profile_key) 128 profile = self.host.memory.getProfileName(profile_key)
129 if not self.__check_profile(profile) or room_jid_s not in self.clients[profile].joined_rooms: 129 if not self.__check_profile(profile) or room_jid_s not in self.clients[profile].joined_rooms:
130 return '' 130 return ''
131 return self.clients[profile].joined_rooms[room_jid_s].nick 131 return self.clients[profile].joined_rooms[room_jid_s].nick
132 132
133 def getRoomNickOfUser(self, room, user_jid, secure=True):
134 """Returns the nick of the given user in the room.
135 @room: instance of wokkel.muc.Room
136 @user: JID or unicode (JID userhost).
137 @param secure: set to True for a secure check
138 @return: the nick or None if the user didn't join the room.
139 """
140 if not isinstance(user_jid, jid.JID):
141 user_jid = jid.JID(user_jid)
142 for user in room.roster.values():
143 if user.entity is not None:
144 if user.entity.userhostJID() == user_jid.userhostJID():
145 return user.nick
146 elif not secure:
147 # FIXME: this is NOT ENOUGH to check an identity!!
148 # See in which conditions user.entity could be None.
149 if user.nick == user_jid.user:
150 return user.nick
151 return None
152
153 def getRoomNicksOfUsers(self, room, users=[], secure=True):
154 """Returns the nicks of the given users in the room.
155 @room: instance of wokkel.muc.Room
156 @users: list of JID or unicode (JID userhost).
157 @param secure: set to True for a secure check
158 @return: (x, y) with x a list containing the nicks of
159 the users who are in the room, and y the missing users.
160 """
161 nicks = []
162 missing = []
163 for user in users:
164 nick = self.getRoomNickOfUser(room, user, secure)
165 if nick is None:
166 missing.append(user)
167 else:
168 nicks.append(nick)
169 return nicks, missing
170
133 def isNickInRoom(self, room_jid, nick, profile): 171 def isNickInRoom(self, room_jid, nick, profile):
134 """Tell if a nick is currently present in a room""" 172 """Tell if a nick is currently present in a room"""
135 profile = self.host.memory.getProfileName(profile) 173 profile = self.host.memory.getProfileName(profile)
136 if not self.__check_profile(profile): 174 if not self.__check_profile(profile):
137 raise exceptions.ProfileUnknownError("Unknown or disconnected profile") 175 raise exceptions.ProfileUnknownError("Unknown or disconnected profile")
306 return 344 return
307 user_data = {'entity': user.entity.full() if user.entity else '', 'affiliation': user.affiliation, 'role': user.role} 345 user_data = {'entity': user.entity.full() if user.entity else '', 'affiliation': user.affiliation, 'role': user.role}
308 self.host.bridge.roomUserJoined(room.roomJID.userhost(), user.nick, user_data, self.parent.profile) 346 self.host.bridge.roomUserJoined(room.roomJID.userhost(), user.nick, user_data, self.parent.profile)
309 347
310 def userLeftRoom(self, room, user): 348 def userLeftRoom(self, room, user):
349 if not self.host.trigger.point("MUC user left", room, user, self.parent.profile):
350 return
311 if user.nick == room.nick: 351 if user.nick == room.nick:
312 # we left the room 352 # we left the room
313 room_jid_s = room.roomJID.userhost() 353 room_jid_s = room.roomJID.userhost()
314 info(_("Room [%(room)s] left (%(profile)s))") % {"room": room_jid_s, 354 info(_("Room [%(room)s] left (%(profile)s))") % {"room": room_jid_s,
315 "profile": self.parent.profile}) 355 "profile": self.parent.profile})