plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate

This commit is contained in:
Goffi 2016-06-28 18:26:21 +02:00
commit 8b425a2e44

View file

@ -157,7 +157,7 @@ class XEP_0045(object):
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 @@ class XEP_0045(object):
"""
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 @@ class XEP_0045(object):
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 @@ class XEP_0045(object):
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 @@ class XEP_0045(object):
else:
room = mess_data["to"]
self.leave(room, client.profile)
self.leave(client, room)
return False
@ -523,7 +523,7 @@ class XEP_0045(object):
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 @@ class XEP_0045(object):
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 @@ class XEP_0045(object):
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)