comparison 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
comparison
equal deleted inserted replaced
3541:888109774673 3573:813595f88612
672 """join a new room 672 """join a new room
673 673
674 @command (all): JID 674 @command (all): JID
675 - JID: room to join (on the same service if full jid is not specified) 675 - JID: room to join (on the same service if full jid is not specified)
676 """ 676 """
677 if mess_data["unparsed"].strip(): 677 room_raw = mess_data["unparsed"].strip()
678 room_jid = self.text_cmds.getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host) 678 if room_raw:
679 nick = (self.getRoomNick(client, room_jid) or 679 if self.isJoinedRoom(client, mess_data["to"]):
680 client.jid.user) 680 # we use the same service as the one from the room where the command has
681 # been entered if full jid is not entered
682 muc_service = mess_data["to"].host
683 nick = self.getRoomNick(client, mess_data["to"]) or client.jid.user
684 else:
685 # the command has been entered in a one2one conversation, so we use
686 # our server MUC service as default service
687 muc_service = client.muc_service or ""
688 nick = client.jid.user
689 room_jid = self.text_cmds.getRoomJID(room_raw, muc_service)
681 self.join(client, room_jid, nick, {}) 690 self.join(client, room_jid, nick, {})
682 691
683 return False 692 return False
684 693
685 def cmd_leave(self, client, mess_data): 694 def cmd_leave(self, client, mess_data):
686 """quit a room 695 """quit a room
687 696
688 @command (group): [ROOM_JID] 697 @command (group): [ROOM_JID]
689 - ROOM_JID: jid of the room to live (current room if not specified) 698 - ROOM_JID: jid of the room to live (current room if not specified)
690 """ 699 """
691 if mess_data["unparsed"].strip(): 700 room_raw = mess_data["unparsed"].strip()
692 room = self.text_cmds.getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host) 701 if room_raw:
702 room = self.text_cmds.getRoomJID(room_raw, mess_data["to"].host)
693 else: 703 else:
694 room = mess_data["to"] 704 room = mess_data["to"]
695 705
696 self.leave(client, room) 706 self.leave(client, room)
697 707
718 except (IndexError, AssertionError): 728 except (IndexError, AssertionError):
719 feedback = _("You must provide a member's nick to kick.") 729 feedback = _("You must provide a member's nick to kick.")
720 self.text_cmds.feedBack(client, feedback, mess_data) 730 self.text_cmds.feedBack(client, feedback, mess_data)
721 return False 731 return False
722 732
723 d = self.kick(client, nick, mess_data["to"], {} if len(options) == 1 else {'reason': options[1]}) 733 reason = ' '.join(options[1:]) if len(options) > 1 else None
734
735 d = self.kick(client, nick, mess_data["to"], {"reason": reason})
724 736
725 def cb(__): 737 def cb(__):
726 feedback_msg = _('You have kicked {}').format(nick) 738 feedback_msg = _('You have kicked {}').format(nick)
727 if len(options) > 1: 739 if reason is not None:
728 feedback_msg += _(' for the following reason: {}').format(options[1]) 740 feedback_msg += _(' for the following reason: {reason}').format(
741 reason=reason
742 )
729 self.text_cmds.feedBack(client, feedback_msg, mess_data) 743 self.text_cmds.feedBack(client, feedback_msg, mess_data)
730 return True 744 return True
731 d.addCallback(cb) 745 d.addCallback(cb)
732 return d 746 return d
733 747
742 try: 756 try:
743 jid_s = options[0] 757 jid_s = options[0]
744 entity_jid = jid.JID(jid_s).userhostJID() 758 entity_jid = jid.JID(jid_s).userhostJID()
745 assert(entity_jid.user) 759 assert(entity_jid.user)
746 assert(entity_jid.host) 760 assert(entity_jid.host)
747 except (RuntimeError, jid.InvalidFormat, AttributeError, IndexError, AssertionError): 761 except (RuntimeError, jid.InvalidFormat, AttributeError, IndexError,
748 feedback = _("You must provide a valid JID to ban, like in '/ban contact@example.net'") 762 AssertionError):
763 feedback = _(
764 "You must provide a valid JID to ban, like in '/ban contact@example.net'"
765 )
749 self.text_cmds.feedBack(client, feedback, mess_data) 766 self.text_cmds.feedBack(client, feedback, mess_data)
750 return False 767 return False
751 768
752 d = self.ban(client, entity_jid, mess_data["to"], {} if len(options) == 1 else {'reason': options[1]}) 769 reason = ' '.join(options[1:]) if len(options) > 1 else None
770
771 d = self.ban(client, entity_jid, mess_data["to"], {"reason": reason})
753 772
754 def cb(__): 773 def cb(__):
755 feedback_msg = _('You have banned {}').format(entity_jid) 774 feedback_msg = _('You have banned {}').format(entity_jid)
756 if len(options) > 1: 775 if reason is not None:
757 feedback_msg += _(' for the following reason: {}').format(options[1]) 776 feedback_msg += _(' for the following reason: {reason}').format(
777 reason=reason
778 )
758 self.text_cmds.feedBack(client, feedback_msg, mess_data) 779 self.text_cmds.feedBack(client, feedback_msg, mess_data)
759 return True 780 return True
760 d.addCallback(cb) 781 d.addCallback(cb)
761 return d 782 return d
762 783
789 return False 810 return False
790 811
791 d = self.affiliate(client, entity_jid, mess_data["to"], {'affiliation': affiliation}) 812 d = self.affiliate(client, entity_jid, mess_data["to"], {'affiliation': affiliation})
792 813
793 def cb(__): 814 def cb(__):
794 feedback_msg = _('New affiliation for %(entity)s: %(affiliation)s').format(entity=entity_jid, affiliation=affiliation) 815 feedback_msg = _('New affiliation for {entity}: {affiliation}').format(
816 entity=entity_jid, affiliation=affiliation)
795 self.text_cmds.feedBack(client, feedback_msg, mess_data) 817 self.text_cmds.feedBack(client, feedback_msg, mess_data)
796 return True 818 return True
797 d.addCallback(cb) 819 d.addCallback(cb)
798 return d 820 return d
799 821