Add support for partnered servers. Fixes #387.
This commit allows you to edit a server's invite splash, query if something has partnered features, and retrieve the invite splash + URL.
This commit is contained in:
		@@ -2290,20 +2290,25 @@ class Client:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        Parameters
 | 
					        Parameters
 | 
				
			||||||
        ----------
 | 
					        ----------
 | 
				
			||||||
        server : :class:`Server`
 | 
					        server: :class:`Server`
 | 
				
			||||||
            The server to edit.
 | 
					            The server to edit.
 | 
				
			||||||
        name : str
 | 
					        name: str
 | 
				
			||||||
            The new name of the server.
 | 
					            The new name of the server.
 | 
				
			||||||
        icon : bytes
 | 
					        icon: bytes
 | 
				
			||||||
            A *bytes-like* object representing the icon. See :meth:`edit_profile`
 | 
					            A *bytes-like* object representing the icon. See :meth:`edit_profile`
 | 
				
			||||||
            for more details. Could be ``None`` to denote
 | 
					            for more details. Could be ``None`` to denote no icon.
 | 
				
			||||||
        region : :class:`ServerRegion`
 | 
					        splash: bytes
 | 
				
			||||||
 | 
					            A *bytes-like* object representing the invite splash. See
 | 
				
			||||||
 | 
					            :meth:`edit_profile` for more details. Could be ``None`` to denote
 | 
				
			||||||
 | 
					            no invite splash. Only available for partnered servers with
 | 
				
			||||||
 | 
					            ``INVITE_SPLASH`` feature.
 | 
				
			||||||
 | 
					        region: :class:`ServerRegion`
 | 
				
			||||||
            The new region for the server's voice communication.
 | 
					            The new region for the server's voice communication.
 | 
				
			||||||
        afk_channel : :class:`Channel`
 | 
					        afk_channel: :class:`Channel`
 | 
				
			||||||
            The new channel that is the AFK channel. Could be ``None`` for no AFK channel.
 | 
					            The new channel that is the AFK channel. Could be ``None`` for no AFK channel.
 | 
				
			||||||
        afk_timeout : int
 | 
					        afk_timeout: int
 | 
				
			||||||
            The number of seconds until someone is moved to the AFK channel.
 | 
					            The number of seconds until someone is moved to the AFK channel.
 | 
				
			||||||
        owner : :class:`Member`
 | 
					        owner: :class:`Member`
 | 
				
			||||||
            The new owner of the server to transfer ownership to. Note that you must
 | 
					            The new owner of the server to transfer ownership to. Note that you must
 | 
				
			||||||
            be owner of the server to do this.
 | 
					            be owner of the server to do this.
 | 
				
			||||||
        verification_level: :class:`VerificationLevel`
 | 
					        verification_level: :class:`VerificationLevel`
 | 
				
			||||||
@@ -2333,7 +2338,18 @@ class Client:
 | 
				
			|||||||
            else:
 | 
					            else:
 | 
				
			||||||
                icon = None
 | 
					                icon = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            splash_bytes = fields['splash']
 | 
				
			||||||
 | 
					        except KeyError:
 | 
				
			||||||
 | 
					            splash = server.splash
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            if splash_bytes is not None:
 | 
				
			||||||
 | 
					                splash = utils._bytes_to_base64_data(splash_bytes)
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                splash = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        fields['icon'] = icon
 | 
					        fields['icon'] = icon
 | 
				
			||||||
 | 
					        fields['splash'] = splash
 | 
				
			||||||
        if 'afk_channel' in fields:
 | 
					        if 'afk_channel' in fields:
 | 
				
			||||||
            fields['afk_channel_id'] = fields['afk_channel'].id
 | 
					            fields['afk_channel_id'] = fields['afk_channel'].id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -97,13 +97,22 @@ class Server(Hashable):
 | 
				
			|||||||
        1 then they do.
 | 
					        1 then they do.
 | 
				
			||||||
    verification_level: :class:`VerificationLevel`
 | 
					    verification_level: :class:`VerificationLevel`
 | 
				
			||||||
        The server's verification level.
 | 
					        The server's verification level.
 | 
				
			||||||
 | 
					    features: List[str]
 | 
				
			||||||
 | 
					        A list of features that the server has. They are currently as follows:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        - ``VIP_REGIONS``: Server has VIP voice regions
 | 
				
			||||||
 | 
					        - ``VANITY_URL``: Server has a vanity invite URL (e.g. discord.gg/discord-api)
 | 
				
			||||||
 | 
					        - ``INVITE_SPLASH``: Server's invite page has a special splash.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    splash: str
 | 
				
			||||||
 | 
					        The server's invite splash.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    __slots__ = ['afk_timeout', 'afk_channel', '_members', '_channels', 'icon',
 | 
					    __slots__ = ['afk_timeout', 'afk_channel', '_members', '_channels', 'icon',
 | 
				
			||||||
                 'name', 'id', 'owner', 'unavailable', 'name', 'region',
 | 
					                 'name', 'id', 'owner', 'unavailable', 'name', 'region',
 | 
				
			||||||
                 '_default_role', '_default_channel', 'roles', '_member_count',
 | 
					                 '_default_role', '_default_channel', 'roles', '_member_count',
 | 
				
			||||||
                 'large', 'owner_id', 'mfa_level', 'emojis',
 | 
					                 'large', 'owner_id', 'mfa_level', 'emojis', 'features',
 | 
				
			||||||
                 'verification_level' ]
 | 
					                 'verification_level', 'splash' ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, **kwargs):
 | 
					    def __init__(self, **kwargs):
 | 
				
			||||||
        self._channels = {}
 | 
					        self._channels = {}
 | 
				
			||||||
@@ -191,6 +200,8 @@ class Server(Hashable):
 | 
				
			|||||||
        self.roles = [Role(server=self, **r) for r in guild.get('roles', [])]
 | 
					        self.roles = [Role(server=self, **r) for r in guild.get('roles', [])]
 | 
				
			||||||
        self.mfa_level = guild.get('mfa_level')
 | 
					        self.mfa_level = guild.get('mfa_level')
 | 
				
			||||||
        self.emojis = [Emoji(server=self, **r) for r in guild.get('emojis', [])]
 | 
					        self.emojis = [Emoji(server=self, **r) for r in guild.get('emojis', [])]
 | 
				
			||||||
 | 
					        self.features = guild.get('features', [])
 | 
				
			||||||
 | 
					        self.splash = guild.get('splash')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for mdata in guild.get('members', []):
 | 
					        for mdata in guild.get('members', []):
 | 
				
			||||||
            roles = [self.default_role]
 | 
					            roles = [self.default_role]
 | 
				
			||||||
@@ -205,7 +216,7 @@ class Server(Hashable):
 | 
				
			|||||||
            self._add_member(member)
 | 
					            self._add_member(member)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self._sync(guild)
 | 
					        self._sync(guild)
 | 
				
			||||||
        self.large = None if member_count is None else self._member_count > 250
 | 
					        self.large = None if member_count is None else self._member_count >= 250
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if 'owner_id' in guild:
 | 
					        if 'owner_id' in guild:
 | 
				
			||||||
            self.owner_id = guild['owner_id']
 | 
					            self.owner_id = guild['owner_id']
 | 
				
			||||||
@@ -257,6 +268,13 @@ class Server(Hashable):
 | 
				
			|||||||
            return ''
 | 
					            return ''
 | 
				
			||||||
        return 'https://discordapp.com/api/guilds/{0.id}/icons/{0.icon}.jpg'.format(self)
 | 
					        return 'https://discordapp.com/api/guilds/{0.id}/icons/{0.icon}.jpg'.format(self)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @property
 | 
				
			||||||
 | 
					    def splash_url(self):
 | 
				
			||||||
 | 
					        """Returns the URL version of the server's invite splash. Returns an empty string if it has no splash."""
 | 
				
			||||||
 | 
					        if self.splash is None:
 | 
				
			||||||
 | 
					            return ''
 | 
				
			||||||
 | 
					        return 'https://cdn.discordapp.com/splashes/{0.id}/{0.splash}.jpg?size=2048'.format(self)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def member_count(self):
 | 
					    def member_count(self):
 | 
				
			||||||
        """Returns the true member count regardless of it being loaded fully or not."""
 | 
					        """Returns the true member count regardless of it being loaded fully or not."""
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user