# HG changeset patch # User Goffi # Date 1467131181 -7200 # Node ID bdc6a5b079224857cbf9eb968b4f697778f9743c # Parent da6d1988dfcb07453c41c429dddc95ebe8244398 plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate diff -r da6d1988dfcb -r bdc6a5b07922 src/plugins/plugin_xep_0045.py --- a/src/plugins/plugin_xep_0045.py Mon Jun 27 22:49:36 2016 +0200 +++ b/src/plugins/plugin_xep_0045.py Tue Jun 28 18:26:21 2016 +0200 @@ -157,7 +157,7 @@ if condition == 'conflict': # we have a nickname conflict, we try again with "_" suffixed to current nickname nick += '_' - return client.join(room_jid, nick, password).addCallbacks(self._joinCb, self._joinEb, callbackKeywords={client: client}, errbackArgs=[client, room_jid, nick, password]) + return client._muc_client.join(room_jid, nick, password).addCallbacks(self._joinCb, self._joinEb, callbackKeywords={client: client}, errbackArgs=[client, room_jid, nick, password]) msg_suffix = ' with condition "{}"'.format(failure.value.condition) mess = D_(u"Error while joining the room {room}{suffix}".format( @@ -352,21 +352,6 @@ """ return self.host.memory.getConfig(CONFIG_SECTION, 'default_muc', default_conf['default_muc']) - def join(self, client, room_jid, nick, options): - def _errDeferred(exc_obj=Exception, txt=u'Error while joining room'): - d = defer.Deferred() - d.errback(exc_obj(txt)) - return d - - if room_jid in client._muc_client.joined_rooms: - log.warning(_(u'{profile} is already in room {room_jid}').format(profile=client.profile, room_jid = room_jid.userhost())) - return defer.fail(exceptions.ConflictError(_(u"The room has already been joined"))) - log.info(_(u"[{profile}] is joining room {room} with nick {nick}").format(profile=client.profile, room=room_jid.userhost(), nick=nick)) - - password = options["password"] if "password" in options else None - - return client._muc_client.join(room_jid, nick, password).addCallbacks(self._joinCb, self._joinEb, callbackKeywords={'client': client}, errbackArgs=[client, room_jid, nick, password]) - def _join(self, room_jid_s, nick, options=None, profile_key=C.PROF_KEY_NONE): """join method used by bridge @@ -389,6 +374,21 @@ d = self.join(client, room_jid, nick, options) return d.addCallback(lambda room: room.roomJID.userhost()) + def join(self, client, room_jid, nick, options): + def _errDeferred(exc_obj=Exception, txt=u'Error while joining room'): + d = defer.Deferred() + d.errback(exc_obj(txt)) + return d + + if room_jid in client._muc_client.joined_rooms: + log.warning(_(u'{profile} is already in room {room_jid}').format(profile=client.profile, room_jid = room_jid.userhost())) + return defer.fail(exceptions.ConflictError(_(u"The room has already been joined"))) + log.info(_(u"[{profile}] is joining room {room} with nick {nick}").format(profile=client.profile, room=room_jid.userhost(), nick=nick)) + + password = options["password"] if "password" in options else None + + return client._muc_client.join(room_jid, nick, password).addCallbacks(self._joinCb, self._joinEb, callbackKeywords={'client': client}, errbackArgs=[client, room_jid, nick, password]) + def _nick(self, room_jid_s, nick, profile_key=C.PROF_KEY_NONE): client = self.host.getClient(profile_key) return self.nick(client, jid.JID(room_jid_s), nick) @@ -467,7 +467,7 @@ nick = mess_data["unparsed"].strip() if nick: room = mess_data["to"] - self.nick(room, nick, client.profile) + self.nick(client, room, nick) return False @@ -496,7 +496,7 @@ else: room = mess_data["to"] - self.leave(room, client.profile) + self.leave(client, room) return False @@ -523,7 +523,7 @@ self.host.plugins[C.TEXT_CMDS].feedBack(client, feedback, mess_data) return False - d = self.kick(nick, mess_data["to"], {} if len(options) == 1 else {'reason': options[1]}, client.profile) + d = self.kick(client, nick, mess_data["to"], {} if len(options) == 1 else {'reason': options[1]}) def cb(dummy): feedback_msg = _(u'You have kicked {}').format(nick) @@ -552,7 +552,7 @@ self.host.plugins[C.TEXT_CMDS].feedBack(client, feedback, mess_data) return False - d = self.ban(entity_jid, mess_data["to"], {} if len(options) == 1 else {'reason': options[1]}, client.profile) + d = self.ban(client, entity_jid, mess_data["to"], {} if len(options) == 1 else {'reason': options[1]}) def cb(dummy): feedback_msg = _(u'You have banned {}').format(entity_jid) @@ -591,7 +591,7 @@ self.host.plugins[C.TEXT_CMDS].feedBack(client, feedback, mess_data) return False - d = self.affiliate(entity_jid, mess_data["to"], {'affiliation': affiliation}, client.profile) + d = self.affiliate(client, entity_jid, mess_data["to"], {'affiliation': affiliation}) def cb(dummy): feedback_msg = _(u'New affiliation for %(entity)s: %(affiliation)s').format(entity=entity_jid, affiliation=affiliation)