
    i5                    j   d Z ddlmZ ddlZddlmZmZmZmZm	Z	m
Z
mZ ddlmZmZmZ ddlmZ ddlmZmZ d	Ze	r$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$m%Z%m&Z'm(Z)  G d d          Z G d d          Z G d de          Z! G d d          Z& G d de          Z# G d d          Z(ddZ*dS ) a:  
The MIT License (MIT)

Copyright (c) 2015-present Rapptz

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.
    )annotationsN)AnyDictListOptionalTYPE_CHECKINGTypeTuple   )_get_as_snowflake
parse_timeMISSING)User)try_enumExpireBehaviour)IntegrationAccountIntegrationApplicationIntegrationStreamIntegrationBotIntegrationPartialIntegration)Guild)Role)ConnectionState)r   r   r   r   IntegrationTyper   r   c                  &    e Zd ZdZdZddZdd	Zd
S )r   zRepresents an integration account.

    .. versionadded:: 1.4

    Attributes
    -----------
    id: :class:`str`
        The account ID.
    name: :class:`str`
        The account name.
    idnamedataIntegrationAccountPayloadreturnNonec                :    |d         | _         |d         | _        d S )Nr   r   r   selfr    s     [/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/discord/integrations.py__init__zIntegrationAccount.__init__H   s    Dzf			    strc                (    d| j          d| j        dS )Nz<IntegrationAccount id= name=>r   r&   s    r'   __repr__zIntegrationAccount.__repr__L   s    FFF	FFFFr)   N)r    r!   r"   r#   r"   r*   )__name__
__module____qualname____doc__	__slots__r(   r/    r)   r'   r   r   9   sS        
 
 I& & & &G G G G G Gr)   r   c                  <    e Zd ZdZdZdd	ZddZddZddddZdS )r   a  Represents a guild integration.

    .. versionadded:: 1.4

    Attributes
    -----------
    id: :class:`int`
        The integration ID.
    name: :class:`str`
        The integration name.
    guild: :class:`Guild`
        The guild of the integration.
    type: :class:`str`
        The integration type (i.e. Twitch).
    enabled: :class:`bool`
        Whether the integration is currently enabled.
    account: :class:`IntegrationAccount`
        The account linked to this integration.
    user: :class:`User`
        The user that added this integration.
    scopes: List[:class:`str`]
        The OAuth2 scopes the application has been authorized for.

        .. versionadded:: 2.7
    )	guildr   _statetyper   accountuserenabledscopesr    IntegrationPayloadr8   r   r"   r#   c               V    || _         |j        | _        |                     |           d S Nr8   r9   
_from_datar&   r    r8   s      r'   r(   zIntegration.__init__w   *    !
',|r)   r*   c                B    d| j         j         d| j         d| j        dS N<z id=r,   r-   	__class__r1   r   r   r.   s    r'   r/   zIntegration.__repr__|   ,    M4>*MMMMtyMMMMr)   c                Z   t          |d                   | _        |d         | _        |d         | _        t	          |d                   | _        |                    d          }|rt          | j        |          nd | _	        |d         | _
        |                    dg           | _        d S )	Nr   r:   r   r;   r<   stater    r=   r>   )intr   r:   r   r   r;   getr   r9   r<   r=   r>   )r&   r    r<   s      r'   rC   zIntegration._from_data   s    4:%)&\	f	+=d9o+N+NxxJN$XDt{$F$F$F$FTX	!)_!%(B!7!7r)   NreasonrR   Optional[str]c               x   K   | j         j                            | j        j        | j        |           d{V  dS )a  |coro|

        Deletes the integration.

        You must have :attr:`~Permissions.manage_guild` to do this.

        Parameters
        -----------
        reason: :class:`str`
            The reason the integration was deleted. Shows up on the audit log.

            .. versionadded:: 2.0

        Raises
        -------
        Forbidden
            You do not have permission to delete the integration.
        HTTPException
            Deleting the integration failed.
        rQ   N)r9   httpdelete_integrationr8   r   )r&   rR   s     r'   deletezIntegration.delete   sG      * k11$*-QW1XXXXXXXXXXXr)   )r    r?   r8   r   r"   r#   r0   )r    r?   r"   r#   )rR   rS   r"   r#   )	r1   r2   r3   r4   r5   r(   r/   rC   rW   r6   r)   r'   r   r   P   s         4
I   
N N N N	8 	8 	8 	8 7; Y Y Y Y Y Y Y Yr)   r   c                  r     e Zd ZdZdZd fdZedd	            Zedd            Ze	e	e	dddZ
ddZ xZS )r   a  Represents a stream integration for Twitch or YouTube.

    .. versionadded:: 2.0

    Attributes
    ----------
    id: :class:`int`
        The integration ID.
    name: :class:`str`
        The integration name.
    guild: :class:`Guild`
        The guild of the integration.
    type: :class:`str`
        The integration type (i.e. Twitch).
    enabled: :class:`bool`
        Whether the integration is currently enabled.
    syncing: :class:`bool`
        Where the integration is currently syncing.
    enable_emoticons: Optional[:class:`bool`]
        Whether emoticons should be synced for this integration (currently twitch only).
    expire_behaviour: :class:`ExpireBehaviour`
        The behaviour of expiring subscribers. Aliased to ``expire_behavior`` as well.
    expire_grace_period: :class:`int`
        The grace period (in days) for expiring subscribers.
    user: :class:`User`
        The user for the integration.
    account: :class:`IntegrationAccount`
        The integration account information.
    synced_at: :class:`datetime.datetime`
        An aware UTC datetime representing when the integration was last synced.
    scopes: List[:class:`str`]
        The OAuth2 scopes the application has been authorized for.

        .. versionadded:: 2.7
    )revokedexpire_behaviourexpire_grace_period	synced_at_role_idsyncingenable_emoticonssubscriber_countr    StreamIntegrationPayloadr"   r#   c                j   t                                          |           |d         | _        t          t          |d                   | _        |d         | _        t          |d                   | _        t          |d          | _
        |d         | _        |d         | _        |d         | _        d S )	NrY   expire_behaviorr[   r\   role_idr^   r_   r`   )superrC   rY   r   r   rZ   r[   r   r\   r   r]   r^   r_   r`   r&   r    rJ   s     r'   rC   zStreamIntegration._from_data   s    4   !)_19/4PaKb1c1c(,-B(C ,6tK7H,I,I'8y'I'I!)_&*+=&>%)*<%=r)   r   c                    | j         S )z@:class:`ExpireBehaviour`: An alias for :attr:`expire_behaviour`.)rZ   r.   s    r'   rc   z!StreamIntegration.expire_behavior   s     $$r)   Optional[Role]c                @    | j                             | j                  S )zLOptional[:class:`Role`] The role which the integration uses for subscribers.)r8   get_roler]   r.   s    r'   rolezStreamIntegration.role   s     z""4=111r)   )rZ   r[   r_   rZ   r[   rO   r_   boolc                 K   i }|t           ur.t          |t                    st          d          |j        |d<   |t           ur||d<   |t           ur||d<    | j        j        j        | j        j	        | j	        fi | d{V  dS )a  |coro|

        Edits the integration.

        You must have :attr:`~Permissions.manage_guild` to do this.

        .. versionchanged:: 2.0
            This function will now raise :exc:`TypeError` instead of
            ``InvalidArgument``.

        Parameters
        -----------
        expire_behaviour: :class:`ExpireBehaviour`
            The behaviour when an integration subscription lapses. Aliased to ``expire_behavior`` as well.
        expire_grace_period: :class:`int`
            The period (in days) where the integration will ignore lapsed subscriptions.
        enable_emoticons: :class:`bool`
            Where emoticons should be synced for this integration (currently twitch only).

        Raises
        -------
        Forbidden
            You do not have permission to edit the integration.
        HTTPException
            Editing the guild failed.
        TypeError
            ``expire_behaviour`` did not receive a :class:`ExpireBehaviour`.
        z6expire_behaviour field must be of type ExpireBehaviourrc   r[   r_   N)
r   
isinstancer   	TypeErrorvaluer9   rU   edit_integrationr8   r   )r&   rZ   r[   r_   payloads        r'   editzStreamIntegration.edit   s      F #%7**.@@ Z XYYY)9)?G%&g---@G)*7***:G&' 0dk/
twRR'RRRRRRRRRRRr)   c                   K   | j         j                            | j        j        | j                   d{V  t
          j                            t
          j        j                  | _	        dS )a(  |coro|

        Syncs the integration.

        You must have :attr:`~Permissions.manage_guild` to do this.

        Raises
        -------
        Forbidden
            You do not have permission to sync the integration.
        HTTPException
            Syncing the integration failed.
        N)
r9   rU   sync_integrationr8   r   datetimenowtimezoneutcr\   r.   s    r'   synczStreamIntegration.sync  s]       k//
twGGGGGGGGG!*..x/@/DEEr)   )r    ra   r"   r#   )r"   r   )r"   rh   )rZ   r   r[   rO   r_   rl   r"   r#   )r"   r#   )r1   r2   r3   r4   r5   rC   propertyrc   rk   r   rs   rz   __classcell__rJ   s   @r'   r   r      s        " "H	I	> 	> 	> 	> 	> 	> % % % X% 2 2 2 X2 -4#*!(2S 2S 2S 2S 2S 2ShF F F F F F F Fr)   r   c                      e Zd ZdZdZdd	Zd
S )r   a)  Represents an application for a bot integration.

    .. versionadded:: 2.0

    Attributes
    ----------
    id: :class:`int`
        The ID for this application.
    name: :class:`str`
        The application's name.
    icon: Optional[:class:`str`]
        The application's icon hash.
    description: :class:`str`
        The application's description. Can be an empty string.
    summary: :class:`str`
        The summary of the application. Can be an empty string.
    user: Optional[:class:`User`]
        The bot user on this application.
    )r   r   icondescriptionsummaryr<   r    IntegrationApplicationPayloadrN   r   r"   r#   c                   t          |d                   | _        |d         | _        |d         | _        |d         | _        |d         | _        |                    d          }|rt          ||          nd | _        d S )Nr   r   r   r   r   botrM   )	rO   r   r   r   r   r   rP   r   r<   )r&   r    rN   r<   s       r'   r(   zIntegrationApplication.__init__L  sr    4:f	#'<	 $] 3 OxxDH$RDu4$@$@$@$@d			r)   N)r    r   rN   r   r"   r#   )r1   r2   r3   r4   r5   r(   r6   r)   r'   r   r   .  s?         (IS S S S S Sr)   r   c                  (     e Zd ZdZdZd fdZ xZS )	r   a!  Represents a bot integration on discord.

    .. versionadded:: 2.0

    Attributes
    ----------
    id: :class:`int`
        The integration ID.
    name: :class:`str`
        The integration name.
    guild: :class:`Guild`
        The guild of the integration.
    type: :class:`str`
        The integration type (i.e. Twitch).
    enabled: :class:`bool`
        Whether the integration is currently enabled.
    user: :class:`User`
        The user that added this integration.
    account: :class:`IntegrationAccount`
        The integration account information.
    application: :class:`IntegrationApplication`
        The application tied to this integration.
    scopes: List[:class:`str`]
        The OAuth2 scopes the application has been authorized for.

        .. versionadded:: 2.7
    )applicationr    BotIntegrationPayloadr"   r#   c                    t                                          |           t          |d         | j                  | _        d S )Nr   )r    rN   )re   rC   r   r9   r   rf   s     r'   rC   zBotIntegration._from_datau  s@    4   3ItTaObjnju3v3v3vr)   )r    r   r"   r#   )r1   r2   r3   r4   r5   rC   r|   r}   s   @r'   r   r   V  sX         8 !Iw w w w w w w w w wr)   r   c                  .    e Zd ZdZdZddZdd
ZddZdS )r   a  Represents a partial guild integration.

    .. versionadded:: 2.0

    Attributes
    -----------
    id: :class:`int`
        The integration ID.
    name: :class:`str`
        The integration name.
    guild: :class:`Guild`
        The guild of the integration.
    type: :class:`str`
        The integration type (i.e. Twitch).
    account: :class:`IntegrationAccount`
        The account linked to this integration.
    application_id: Optional[:class:`int`]
        The id of the application this integration belongs to.
    )r8   r9   r   r:   r   r;   application_idr    PartialIntegrationPayloadr8   r   c               V    || _         |j        | _        |                     |           d S rA   rB   rD   s      r'   r(   zPartialIntegration.__init__  rE   r)   r"   r*   c                B    d| j         j         d| j         d| j        dS rG   rI   r.   s    r'   r/   zPartialIntegration.__repr__  rK   r)   r#   c                    t          |d                   | _        |d         | _        |d         | _        t	          |d                   | _        t          |d          | _        d S )Nr   r:   r   r;   r   )rO   r   r:   r   r   r;   r   r   r%   s     r'   rC   zPartialIntegration._from_data  sU    4:%)&\	f	+=d9o+N+N->tEU-V-Vr)   N)r    r   r8   r   r0   )r    r   r"   r#   )r1   r2   r3   r4   r5   r(   r/   rC   r6   r)   r'   r   r   z  sk         (I   
N N N NW W W W W Wr)   r   rp   r*   r"   Tuple[Type[Integration], str]c                L    | dk    r	t           | fS | dv r	t          | fS t          | fS )Ndiscord)twitchyoutube)r   r   r   )rp   s    r'   _integration_factoryr     s:    	u$$	'	'	' %''E!!r)   )rp   r*   r"   r   )+r4   
__future__r   rv   typingr   r   r   r   r   r	   r
   utilsr   r   r   r<   r   enumsr   r   __all__r8   r   rk   r   rN   r   types.integrationr   r!   r   r?   r   ra   r   r   r   r   r   r   r   r   r6   r)   r'   <module>r      s   0 # " " " " "  H H H H H H H H H H H H H H H H H H 9 9 9 9 9 9 9 9 9 9       , , , , , , , ,  &&&&&&                 G G G G G G G G.OY OY OY OY OY OY OY OYdIF IF IF IF IF IF IF IFX%S %S %S %S %S %S %S %SP!w !w !w !w !w[ !w !w !wH,W ,W ,W ,W ,W ,W ,W ,W^" " " " " "r)   