Mercurial > libervia-backend
diff sat/plugins/plugin_xep_0045.py @ 3573:813595f88612
merge changes from main branch
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 17 Jun 2021 13:05:58 +0200 |
parents | 888109774673 ae5f63e5ed2c |
children | 8289ac1b34f4 |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0045.py Thu Jun 03 15:21:43 2021 +0200 +++ b/sat/plugins/plugin_xep_0045.py Thu Jun 17 13:05:58 2021 +0200 @@ -674,10 +674,19 @@ @command (all): JID - JID: room to join (on the same service if full jid is not specified) """ - if mess_data["unparsed"].strip(): - room_jid = self.text_cmds.getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host) - nick = (self.getRoomNick(client, room_jid) or - client.jid.user) + room_raw = mess_data["unparsed"].strip() + if room_raw: + if self.isJoinedRoom(client, mess_data["to"]): + # we use the same service as the one from the room where the command has + # been entered if full jid is not entered + muc_service = mess_data["to"].host + nick = self.getRoomNick(client, mess_data["to"]) or client.jid.user + else: + # the command has been entered in a one2one conversation, so we use + # our server MUC service as default service + muc_service = client.muc_service or "" + nick = client.jid.user + room_jid = self.text_cmds.getRoomJID(room_raw, muc_service) self.join(client, room_jid, nick, {}) return False @@ -688,8 +697,9 @@ @command (group): [ROOM_JID] - ROOM_JID: jid of the room to live (current room if not specified) """ - if mess_data["unparsed"].strip(): - room = self.text_cmds.getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host) + room_raw = mess_data["unparsed"].strip() + if room_raw: + room = self.text_cmds.getRoomJID(room_raw, mess_data["to"].host) else: room = mess_data["to"] @@ -720,12 +730,16 @@ self.text_cmds.feedBack(client, feedback, mess_data) return False - d = self.kick(client, nick, mess_data["to"], {} if len(options) == 1 else {'reason': options[1]}) + reason = ' '.join(options[1:]) if len(options) > 1 else None + + d = self.kick(client, nick, mess_data["to"], {"reason": reason}) def cb(__): feedback_msg = _('You have kicked {}').format(nick) - if len(options) > 1: - feedback_msg += _(' for the following reason: {}').format(options[1]) + if reason is not None: + feedback_msg += _(' for the following reason: {reason}').format( + reason=reason + ) self.text_cmds.feedBack(client, feedback_msg, mess_data) return True d.addCallback(cb) @@ -744,17 +758,24 @@ entity_jid = jid.JID(jid_s).userhostJID() assert(entity_jid.user) assert(entity_jid.host) - except (RuntimeError, jid.InvalidFormat, AttributeError, IndexError, AssertionError): - feedback = _("You must provide a valid JID to ban, like in '/ban contact@example.net'") + except (RuntimeError, jid.InvalidFormat, AttributeError, IndexError, + AssertionError): + feedback = _( + "You must provide a valid JID to ban, like in '/ban contact@example.net'" + ) self.text_cmds.feedBack(client, feedback, mess_data) return False - d = self.ban(client, entity_jid, mess_data["to"], {} if len(options) == 1 else {'reason': options[1]}) + reason = ' '.join(options[1:]) if len(options) > 1 else None + + d = self.ban(client, entity_jid, mess_data["to"], {"reason": reason}) def cb(__): feedback_msg = _('You have banned {}').format(entity_jid) - if len(options) > 1: - feedback_msg += _(' for the following reason: {}').format(options[1]) + if reason is not None: + feedback_msg += _(' for the following reason: {reason}').format( + reason=reason + ) self.text_cmds.feedBack(client, feedback_msg, mess_data) return True d.addCallback(cb) @@ -791,7 +812,8 @@ d = self.affiliate(client, entity_jid, mess_data["to"], {'affiliation': affiliation}) def cb(__): - feedback_msg = _('New affiliation for %(entity)s: %(affiliation)s').format(entity=entity_jid, affiliation=affiliation) + feedback_msg = _('New affiliation for {entity}: {affiliation}').format( + entity=entity_jid, affiliation=affiliation) self.text_cmds.feedBack(client, feedback_msg, mess_data) return True d.addCallback(cb)