Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0045.py @ 3543:f19718296c20
plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 03 Jun 2021 17:47:25 +0200 |
parents | be6d91572633 |
children | ae5f63e5ed2c |
comparison
equal
deleted
inserted
replaced
3542:53c1724a89ea | 3543:f19718296c20 |
---|---|
718 except (IndexError, AssertionError): | 718 except (IndexError, AssertionError): |
719 feedback = _("You must provide a member's nick to kick.") | 719 feedback = _("You must provide a member's nick to kick.") |
720 self.text_cmds.feedBack(client, feedback, mess_data) | 720 self.text_cmds.feedBack(client, feedback, mess_data) |
721 return False | 721 return False |
722 | 722 |
723 d = self.kick(client, nick, mess_data["to"], {} if len(options) == 1 else {'reason': options[1]}) | 723 reason = ' '.join(options[1:]) if len(options) > 1 else None |
724 | |
725 d = self.kick(client, nick, mess_data["to"], {"reason": reason}) | |
724 | 726 |
725 def cb(__): | 727 def cb(__): |
726 feedback_msg = _('You have kicked {}').format(nick) | 728 feedback_msg = _('You have kicked {}').format(nick) |
727 if len(options) > 1: | 729 if reason is not None: |
728 feedback_msg += _(' for the following reason: {}').format(options[1]) | 730 feedback_msg += _(' for the following reason: {reason}').format( |
731 reason=reason | |
732 ) | |
729 self.text_cmds.feedBack(client, feedback_msg, mess_data) | 733 self.text_cmds.feedBack(client, feedback_msg, mess_data) |
730 return True | 734 return True |
731 d.addCallback(cb) | 735 d.addCallback(cb) |
732 return d | 736 return d |
733 | 737 |
742 try: | 746 try: |
743 jid_s = options[0] | 747 jid_s = options[0] |
744 entity_jid = jid.JID(jid_s).userhostJID() | 748 entity_jid = jid.JID(jid_s).userhostJID() |
745 assert(entity_jid.user) | 749 assert(entity_jid.user) |
746 assert(entity_jid.host) | 750 assert(entity_jid.host) |
747 except (RuntimeError, jid.InvalidFormat, AttributeError, IndexError, AssertionError): | 751 except (RuntimeError, jid.InvalidFormat, AttributeError, IndexError, |
748 feedback = _("You must provide a valid JID to ban, like in '/ban contact@example.net'") | 752 AssertionError): |
753 feedback = _( | |
754 "You must provide a valid JID to ban, like in '/ban contact@example.net'" | |
755 ) | |
749 self.text_cmds.feedBack(client, feedback, mess_data) | 756 self.text_cmds.feedBack(client, feedback, mess_data) |
750 return False | 757 return False |
751 | 758 |
752 d = self.ban(client, entity_jid, mess_data["to"], {} if len(options) == 1 else {'reason': options[1]}) | 759 reason = ' '.join(options[1:]) if len(options) > 1 else None |
760 | |
761 d = self.ban(client, entity_jid, mess_data["to"], {"reason": reason}) | |
753 | 762 |
754 def cb(__): | 763 def cb(__): |
755 feedback_msg = _('You have banned {}').format(entity_jid) | 764 feedback_msg = _('You have banned {}').format(entity_jid) |
756 if len(options) > 1: | 765 if reason is not None: |
757 feedback_msg += _(' for the following reason: {}').format(options[1]) | 766 feedback_msg += _(' for the following reason: {reason}').format( |
767 reason=reason | |
768 ) | |
758 self.text_cmds.feedBack(client, feedback_msg, mess_data) | 769 self.text_cmds.feedBack(client, feedback_msg, mess_data) |
759 return True | 770 return True |
760 d.addCallback(cb) | 771 d.addCallback(cb) |
761 return d | 772 return d |
762 | 773 |
789 return False | 800 return False |
790 | 801 |
791 d = self.affiliate(client, entity_jid, mess_data["to"], {'affiliation': affiliation}) | 802 d = self.affiliate(client, entity_jid, mess_data["to"], {'affiliation': affiliation}) |
792 | 803 |
793 def cb(__): | 804 def cb(__): |
794 feedback_msg = _('New affiliation for %(entity)s: %(affiliation)s').format(entity=entity_jid, affiliation=affiliation) | 805 feedback_msg = _('New affiliation for {entity}: {affiliation}').format( |
806 entity=entity_jid, affiliation=affiliation) | |
795 self.text_cmds.feedBack(client, feedback_msg, mess_data) | 807 self.text_cmds.feedBack(client, feedback_msg, mess_data) |
796 return True | 808 return True |
797 d.addCallback(cb) | 809 d.addCallback(cb) |
798 return d | 810 return d |
799 | 811 |
835 room_jid = mess_data["to"] | 847 room_jid = mess_data["to"] |
836 service = jid.JID(room_jid.host) | 848 service = jid.JID(room_jid.host) |
837 elif client.muc_service is not None: | 849 elif client.muc_service is not None: |
838 service = client.muc_service | 850 service = client.muc_service |
839 else: | 851 else: |
840 msg = D_("No known default MUC service".format(unparsed)) | 852 msg = D_("No known default MUC service {unparsed}").format( |
853 unparsed=unparsed) | |
841 self.text_cmds.feedBack(client, msg, mess_data) | 854 self.text_cmds.feedBack(client, msg, mess_data) |
842 return False | 855 return False |
843 except jid.InvalidFormat: | 856 except jid.InvalidFormat: |
844 msg = D_("{} is not a valid JID!".format(unparsed)) | 857 msg = D_("{} is not a valid JID!".format(unparsed)) |
845 self.text_cmds.feedBack(client, msg, mess_data) | 858 self.text_cmds.feedBack(client, msg, mess_data) |