
    cjhS@                       d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZmZmZ dZer(ddlZddlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z$ ddl"m%Z&  G d d      Z% edd      Z' G d de      Z#y)ae  
The MIT License (MIT)

Copyright (c) 2015-2021 Rapptz
Copyright (c) 2021-present Pycord Development

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
    )annotations)TYPE_CHECKINGAnyTypeVar   )Asset)Colour)InvalidArgument)	RoleFlags)Hashable)Permissions)MISSING_bytes_to_base64_data_get_as_snowflakesnowflake_time)RoleTagsRoleN)Guild)Member)ConnectionState)RolePositionUpdate)r   )r   c                  <    e Zd ZdZdZd	dZd
dZd
dZd
dZddZ	y)r   a  Represents tags on a role.

    A role tag is a piece of extra information attached to a managed role
    that gives it context for the reason the role is managed.

    While this can be accessed, a useful interface is also provided in the
    :class:`Role` and :class:`Guild` classes as well.

    .. versionadded:: 1.6

    Attributes
    ----------
    bot_id: Optional[:class:`int`]
        The bot's user ID that manages this role.
    integration_id: Optional[:class:`int`]
        The integration ID that manages the role.
    )bot_idintegration_id_premium_subscriberc                ~    t        |d      | _        t        |d      | _        |j                  dt              | _        y )Nr   r   premium_subscriber)r   r   r   getr   r   selfdatas     ?/var/www/html/venv/lib/python3.12/site-packages/discord/role.py__init__zRoleTags.__init__O   s6    "3D("C*;DBR*S
 04xx8Lg/V     c                    | j                   duS )z*Whether the role is associated with a bot.N)r   r    s    r"   is_bot_managedzRoleTags.is_bot_managedX   s    {{$&&r$   c                    | j                   du S )zLWhether the role is the premium subscriber, AKA "boost", role for the guild.N)r   r&   s    r"   is_premium_subscriberzRoleTags.is_premium_subscriber\   s    ''4//r$   c                    | j                   duS )z.Whether the role is managed by an integration.N)r   r&   s    r"   is_integrationzRoleTags.is_integration`   s    ""$..r$   c                ^    d| j                    d| j                   d| j                          dS )Nz<RoleTags bot_id=z integration_id=z premium_subscriber=>)r   r   r)   r&   s    r"   __repr__zRoleTags.__repr__d   s=    },<T=P=P<Q R""&"<"<">!?qB	
r$   N)r!   RoleTagPayloadreturnboolr1   str)
__name__
__module____qualname____doc__	__slots__r#   r'   r)   r+   r.    r$   r"   r   r   6   s(    $IW'0/
r$   r   Rr   )boundc                  Z   e Zd ZdZdZddZddZddZddZddZ	ddZ
dd	Zd d
Zd!dZd!dZd!dZd!dZd!dZed"d       Zed#d       Zed#d       Zed$d       Zedd       Zed%d       Zed&d       Zd'dZeeeeeeeeeed
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d(dZddd)dZy)*r   a  Represents a Discord role in a :class:`Guild`.

    .. container:: operations

        .. describe:: x == y

            Checks if two roles are equal.

        .. describe:: x != y

            Checks if two roles are not equal.

        .. describe:: x > y

            Checks if a role is higher than another in the hierarchy.

        .. describe:: x < y

            Checks if a role is lower than another in the hierarchy.

        .. describe:: x >= y

            Checks if a role is higher or equal to another in the hierarchy.

        .. describe:: x <= y

            Checks if a role is lower or equal to another in the hierarchy.

        .. describe:: hash(x)

            Return the role's hash.

        .. describe:: str(x)

            Returns the role's name.

    Attributes
    ----------
    id: :class:`int`
        The ID for the role.
    name: :class:`str`
        The name of the role.
    guild: :class:`Guild`
        The guild the role belongs to.
    hoist: :class:`bool`
         Indicates if the role will be displayed separately from other members.
    position: :class:`int`
        The position of the role. This number is usually positive. The bottom
        role has a position of 0.

        .. warning::

            Multiple roles can have the same position number. As a consequence
            of this, comparing via role position is prone to subtle bugs if
            checking for role hierarchy. The recommended and correct way to
            compare for roles in the hierarchy is using the comparison
            operators on the role objects themselves.

    managed: :class:`bool`
        Indicates if the role is managed by the guild through some form of
        integrations such as Twitch.
    mentionable: :class:`bool`
        Indicates if the role can be mentioned by users.
    tags: Optional[:class:`RoleTags`]
        The role tags associated with this role.
    unicode_emoji: Optional[:class:`str`]
        The role's unicode emoji.
        Only available to guilds that contain ``ROLE_ICONS`` in :attr:`Guild.features`.

        .. versionadded:: 2.0

    flags: :class:`RoleFlags`
        Extra attributes of the role.

        .. versionadded:: 2.6
    )idname_permissions_colourpositionmanagedmentionablehoistguildtagsunicode_emoji_icon_stateflagsc               h    || _         || _        t        |d         | _        | j	                  |       y )Nr>   )rF   rJ   intr>   _update)r    rF   stater!   s       r"   r#   zRole.__init__   s+    !
',4:Tr$   c                    | j                   S N)r?   r&   s    r"   __str__zRole.__str__   s    yyr$   c                <    d| j                    d| j                  dS )Nz	<Role id=z name=r-   )r>   r?   r&   s    r"   r.   zRole.__repr__   s    477)6$))a88r$   c                   t        |t              rt        | t              st        S | j                  |j                  k7  rt	        d      | j                  j
                  }| j
                  |k(  r|j
                  |k7  S | j                  |j                  k  ry| j                  |j                  k(  r+t        | j
                        t        |j
                        kD  S y)Nz/cannot compare roles from two different guilds.TF)
isinstancer   NotImplementedrF   RuntimeErrorr>   rB   rM   )r    otherguild_ids      r"   __lt__zRole.__lt__   s    %&jt.D!!::$PQQ ::==77h88x''==5>>)==ENN*tww<#ehh-//r$   c                P    t         j                  ||       }|t        u rt        S | S rQ   r   rZ   rV   r    rX   rs      r"   __le__zRole.__le__   s'    KKt$!!ur$   c                .    t         j                  ||       S rQ   )r   rZ   )r    rX   s     r"   __gt__zRole.__gt__   s    {{5$''r$   c                P    t         j                  | |      }|t        u rt        S | S rQ   r\   r]   s      r"   __ge__zRole.__ge__   s'    KKe$!!ur$   c                B   |d   | _         t        |j                  dd            | _        |j                  dd      | _        |j                  dd      | _        |j                  dd      | _        |j                  dd      | _        |j                  d	d      | _        |j                  d
      | _	        |j                  d      | _
        t        j                  |j                  dd            | _        |  	 t        |d         | _        y # t         $ r
 d | _        Y y w xY w)Nr?   permissionsr   rB   colorrE   FrC   rD   iconrH   rK   rG   )r?   rM   r   r@   rB   rA   rE   rC   rD   rI   rH   r   _from_valuerK   r   rG   KeyErrorr   s     r"   rN   zRole._update   s    f	!$TXXmQ%?!@!XXj!4 HHWa088GU3
!XXi7!%-!?!%&!1
)-/)B ) 5 5dhhw6J K
	 f.DI 	DI	s   7D DDc                H    | j                   j                  | j                  k(  S )z'Checks if the role is the default role.)rF   r>   r&   s    r"   
is_defaultzRole.is_default  s    zz}}''r$   c                V    | j                   duxr | j                   j                         S )zRWhether the role is associated with a bot.

        .. versionadded:: 1.6
        N)rG   r'   r&   s    r"   r'   zRole.is_bot_managed  %    
 yy$C)A)A)CCr$   c                V    | j                   duxr | j                   j                         S )ztWhether the role is the premium subscriber, AKA "boost", role for the guild.

        .. versionadded:: 1.6
        N)rG   r)   r&   s    r"   r)   zRole.is_premium_subscriber  s%    
 yy$J)H)H)JJr$   c                V    | j                   duxr | j                   j                         S )zVWhether the role is managed by an integration.

        .. versionadded:: 1.6
        N)rG   r+   r&   s    r"   r+   zRole.is_integration!  rm   r$   c                    | j                   j                  }| j                          xrC | j                   xr4 |j                  | kD  xs# |j
                  | j                   j                  k(  S )zfWhether the role is able to be assigned or removed by the bot.

        .. versionadded:: 2.0
        )rF   merk   rC   top_roler>   owner_id)r    rq   s     r"   is_assignablezRole.is_assignable(  s]    
 ZZ]]!! ELL Et#Cruu

0C0C'C	
r$   c                ,    t        | j                        S )zReturns the role's permissions.)r   r@   r&   s    r"   re   zRole.permissions4  s     4,,--r$   c                ,    t        | j                        S )z9Returns the role colour. An alias exists under ``color``.)r	   rA   r&   s    r"   colourzRole.colour9  s     dll##r$   c                    | j                   S )z9Returns the role color. An alias exists under ``colour``.)rw   r&   s    r"   rf   z
Role.color>  s     {{r$   c                ,    t        | j                        S )z(Returns the role's creation time in UTC.)r   r>   r&   s    r"   
created_atzRole.created_atC  s     dgg&&r$   c                "    d| j                    dS )z3Returns a string that allows you to mention a role.z<@&r-   )r>   r&   s    r"   mentionzRole.mentionH  s     TWWIQr$   c                    | j                   j                  }| j                         r|S | j                  }|D cg c]   }|j                  j                  |      s|" c}S c c}w )z'Returns all the members with this role.)rF   membersrk   r>   _roleshas)r    all_membersrole_idmembers       r"   r~   zRole.membersM  sQ     jj((??''%0O6FMM4E4Eg4NOOOs    A!A!c                    | j                   yt        j                  | j                  | j                  | j                   d      S )zTReturns the role's icon asset, if available.

        .. versionadded:: 2.0
        Nrole)rI   r   
_from_iconrJ   r>   r&   s    r"   rg   z	Role.iconW  s4     ::TWWdjj&IIr$   c                  K   |dk  rt        d      | j                         rt        d      | j                  |k(  ry | j                  j                  }t        t        | j                  |      t        | j                  |      dz         }| j                  j                  dd  D cg c]5  }|j                  |v r%|j                  | j                  k7  r|j                  7 }}| j                  |kD  r|j                  d| j                         n|j                  | j                         t        ||      D cg c]  }|d   |d   d }}|j                  | j                  j                  ||       d {    y c c}w c c}w 7 w)Nr   z'Cannot move role to position 0 or belowzCannot move default roler   )r>   rB   reason)r
   rk   rB   rJ   httprangeminmaxrF   rolesr>   insertappendzipmove_role_position)	r    rB   r   r   change_ranger^   r   zpayloads	            r"   _movez
Role._moveb  sZ    q=!"KLL??!"<====H${{x(#dmmX*F*J

 ZZ%%ab)
zz\)adddggo DD
 
 ==8#LLDGG$LL! 58|4L-
/01Q4QqT*-
 -
 %%djjmmWV%LLL
-
 	Ms+   B$F&:E< AF7F	-F6F7F)
r?   re   rw   rf   rE   rD   rB   r   rg   rH   c       
          K   |t         ur| j                  ||       d{    i }|t         ur|}|t         ur!t        |t              r|n|j                  |d<   |t         ur||d<   |t         ur|j                  |d<   |t         ur||d<   |t         ur||d<   |	t         ur|	d|d<   nt        |	      |d<   d|d	<   |
t         ur
|
|d	<   d|d<    | j                  j                  j                  | j                  j                  | j                  fd
|i| d{   }t        | j                  || j                        S 7 7 )w)a  |coro|

        Edits the role.

        You must have the :attr:`~Permissions.manage_roles` permission to
        use this.

        All fields are optional.

        .. versionchanged:: 1.4
            Can now pass ``int`` to ``colour`` keyword-only parameter.

        .. versionchanged:: 2.0
            Edits are no longer in-place, the newly edited role is returned instead.
            Added ``icon`` and ``unicode_emoji``.

        Parameters
        ----------
        name: :class:`str`
            The new role name to change to.
        permissions: :class:`Permissions`
            The new permissions to change to.
        colour: Union[:class:`Colour`, :class:`int`]
            The new colour to change to. (aliased to color as well)
        hoist: :class:`bool`
            Indicates if the role should be shown separately in the member list.
        mentionable: :class:`bool`
            Indicates if the role should be mentionable by others.
        position: :class:`int`
            The new role's position. This must be below your top role's
            position, or it will fail.
        reason: Optional[:class:`str`]
            The reason for editing this role. Shows up on the audit log.
        icon: Optional[:class:`bytes`]
            A :term:`py:bytes-like object` representing the icon. Only PNG/JPEG/WebP is supported.
            If this argument is passed, ``unicode_emoji`` is set to None.
            Only available to guilds that contain ``ROLE_ICONS`` in :attr:`Guild.features`.
            Could be ``None`` to denote removal of the icon.
        unicode_emoji: Optional[:class:`str`]
            The role's unicode emoji. If this argument is passed, ``icon`` is set to None.
            Only available to guilds that contain ``ROLE_ICONS`` in :attr:`Guild.features`.

        Returns
        -------
        :class:`Role`
            The newly edited role.

        Raises
        ------
        Forbidden
            You do not have permissions to change the role.
        HTTPException
            Editing the role failed.
        InvalidArgument
            An invalid position was given or the default
            role was asked to be moved.
        r   Nrf   r?   re   rE   rD   rg   rH   r   )rF   r!   rO   )r   r   rU   rM   valuer   rJ   r   	edit_rolerF   r>   r   )r    r?   re   rw   rf   rE   rD   rB   r   rg   rH   r   r!   s                r"   editz	Role.edit  sW    N 7"**Xf*555"$F )3FC)@vfllGGw"GFOg%%0%6%6GM"$GGg%%0GM"w|"&"7"=+/(''4GO$"GFO/T[[%%//JJMM477
+1
5<
 
 $**4t{{CCE 6>
s"   EE C7EE'EENr   c                  K   | j                   j                  j                  | j                  j                  | j                  |       d{    y7 w)a  |coro|

        Deletes the role.

        You must have the :attr:`~Permissions.manage_roles` permission to
        use this.

        Parameters
        ----------
        reason: Optional[:class:`str`]
            The reason for deleting this role. Shows up on the audit log.

        Raises
        ------
        Forbidden
            You do not have permissions to delete the role.
        HTTPException
            Deleting the role failed.
        r   N)rJ   r   delete_rolerF   r>   )r    r   s     r"   deletezRole.delete  s9     * kk**4::==$''&*QQQs   A
AAA)rF   r   rO   r   r!   RolePayloadr3   )r    r;   rX   r;   r1   r2   )r!   r   r0   )r1   r   )r1   r	   )r1   zdatetime.datetime)r1   zlist[Member])r1   zAsset | None)rB   rM   r   
str | Noner1   None)r?   r4   re   r   rw   Colour | intrf   r   rE   r2   rD   r2   rB   rM   r   r   rg   zbytes | NonerH   r   r1   zRole | None)r   r   r1   r   )r5   r6   r7   r8   r9   r#   rR   r.   rZ   r_   ra   rc   rN   rk   r'   r)   r+   rt   propertyre   rw   rf   rz   r|   r~   rg   r   r   r   r   r:   r$   r"   r   r   n   s   KZI"9*($(DKD

 . . $ $   ' '     P P J JMD #*&%#$$$+jD jD !	jD
 jD jD jD jD jD jD jD "jD 
jDX 48 Rr$   )(r8   
__future__r   typingr   r   r   assetr   rw   r	   errorsr
   rK   r   mixinsr   re   r   utilsr   r   r   r   __all__datetimerF   r   r   r   rO   r   types.guildr   
types.roler   r   r   r/   r;   r:   r$   r"   <module>r      sw   2 # . .   #   $ T T
 &//62
 2
j CvTR8 TRr$   