
    i%\                    *   d 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 ddlmZ ddlmZmZmZmZ ddlmZ dd	lmZmZ dd
lmZmZmZmZ er4ddlmZm Z!m"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z(m)Z) ddl*m+Z+ ddl,m-Z- e	ee!f         Z.dZ/ G d de          Z0d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.
    )annotations)datetime)TYPE_CHECKINGAsyncIteratorDictOptionalUnionoverloadLiteral   )Asset)EventStatus
EntityTypePrivacyLeveltry_enum)Hashable)ObjectOLDEST_OBJECT)
parse_time_get_as_snowflake_bytes_to_base64_dataMISSING)GuildScheduledEvent GuildScheduledEventWithUserCountEntityMetadata)	Snowflake)Guild)VoiceChannelStageChannel)ConnectionState)User)ScheduledEventc                     e Zd ZdZdZdLd	ZdMd
ZdNdZdOdZe	dPd            Z
e	dQd            Ze	dRd            Ze	dOd            ZdSdZdddTdZdddTdZdddTdZed d d d d d d d d!dUd,            Zed d d d d d d d d!dVd1            Zed d d d d d d d d!dWd4            Zed d d d d d d d d!dXd6            Zed d d d d d d d d!dYd7            Zeeeeeeeeeedd8dZd;Zddd[d<Zddded=d\dEZd]dHZd^dKZdS )_r"   a  Represents a scheduled event in a guild.

    .. versionadded:: 2.0

    .. container:: operations

        .. describe:: x == y

            Checks if two scheduled events are equal.

        .. describe:: x != y

            Checks if two scheduled events are not equal.

        .. describe:: hash(x)

            Returns the scheduled event's hash.

    Attributes
    ----------
    id: :class:`int`
        The scheduled event's ID.
    name: :class:`str`
        The name of the scheduled event.
    description: Optional[:class:`str`]
        The description of the scheduled event.
    entity_type: :class:`EntityType`
        The type of entity this event is for.
    entity_id: Optional[:class:`int`]
        The ID of the entity this event is for if available.
    start_time: :class:`datetime.datetime`
        The time that the scheduled event will start in UTC.
    end_time: Optional[:class:`datetime.datetime`]
        The time that the scheduled event will end in UTC.
    privacy_level: :class:`PrivacyLevel`
        The privacy level of the scheduled event.
    status: :class:`EventStatus`
        The status of the scheduled event.
    user_count: :class:`int`
        The number of users subscribed to the scheduled event.
    creator: Optional[:class:`User`]
        The user that created the scheduled event.
    creator_id: Optional[:class:`int`]
        The ID of the user that created the scheduled event.

        .. versionadded:: 2.2
    location: Optional[:class:`str`]
        The location of the scheduled event.
    )_state_usersidguild_idnamedescriptionentity_type	entity_id
start_timeend_timeprivacy_levelstatus_cover_image
user_countcreator
channel_id
creator_idlocationstater    dataGuildScheduledEventPayloadreturnNonec               L    || _         i | _        |                     |           d S N)r$   r%   _update)selfr6   r7   s      X/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/discord/scheduled_event.py__init__zScheduledEvent.__init__   s(    ')T    c                   t          |d                   | _        t          |d                   | _        |d         | _        |                    d          | _        t          t          |d                   | _        t          |d          | _
        t          |d                   | _        t          t          |d                   | _        t          t          |d                   | _        |                    d	d           | _        |                    d
d          | _        t          |d          | _        |                    d          }|r| j                            |          nd | _        | j        +| j        $| j                            | j                  | _        t          |                    d                    | _        t          |d          | _        |                    d          }|                     |           d S )Nr&   r'   r(   r)   r*   r+   scheduled_start_timer/   imager1   r   r4   r2   scheduled_end_timer3   entity_metadata)intr&   r'   r(   getr)   r   r   r*   r   r+   r   r,   r   r.   r   r/   r0   r1   r4   r$   
store_userr2   get_userr-   r3   _unroll_metadata)r>   r7   r2   metadatas       r?   r=   zScheduledEvent._update   s   4: j!122f	*.((=*A*A'/
D<O'P'P(9$(L(L$.t4J/K$L$L+3L$x.+Q+Q#+Kh#H#H+/88GT+B+B#xxa88):4)N)N((9%%JQ'[t{'='=g'F'F'FW[?&4<+?;//@@DL,6txx@T7U7U,V,V):4)N)N88-..h'''''rA   Optional[EntityMetadata]c                B    |r|                     d          nd | _        d S )Nr5   )rH   r5   )r>   r7   s     r?   rK   zScheduledEvent._unroll_metadata   s#    ?C'Mtxx
';';';rA   strc           	     H    d| j          d| j        d| j        d| j        d	S )Nz<GuildScheduledEvent id=z name=z
 guild_id=z	 creator=>)r&   r(   r'   r2   r>   s    r?   __repr__zScheduledEvent.__repr__   s7    {$'{{{{PTP]{{jnjv{{{{rA   Optional[Asset]c                ^    | j         dS t          j        | j        | j        | j                   S )z<Optional[:class:`Asset`]: The scheduled event's cover image.N)r0   r   !_from_scheduled_event_cover_imager$   r&   rR   s    r?   cover_imagezScheduledEvent.cover_image   s.     $46t{DGTM^___rA   Optional[Guild]c                @    | j                             | j                  S )z?Optional[:class:`Guild`]: The guild this scheduled event is in.)r$   
_get_guildr'   rR   s    r?   guildzScheduledEvent.guild   s     {%%dm444rA   +Optional[Union[VoiceChannel, StageChannel]]c                @    | j                             | j                  S )zfOptional[Union[:class:`VoiceChannel`, :class:`StageChannel`]]: The channel this scheduled event is in.)r[   get_channelr3   rR   s    r?   channelzScheduledEvent.channel   s     z%%do666rA   c                &    d| j          d| j         S )z.:class:`str`: The url for the scheduled event.zhttps://discord.com/events//)r'   r&   rR   s    r?   urlzScheduledEvent.url   s     GT]FFTWFFFrA   r/   r   reasonOptional[str]c                  K   d|j         i} | j        j        j        | j        | j        fi |d|i d {V }t          | j        |          }| j        |_        |S )Nr/   rc   r6   r7   )valuer$   httpedit_scheduled_eventr'   r&   r"   r%   )r>   r/   rc   payloadr7   ss         r?   __modify_statuszScheduledEvent.__modify_status   sx      V\*:T[%:4=$'llU\lleklllllllll4888;rA   Nrc   c                  K   | j         t          j        urt          d          |                     t          j        |           d{V S )a  |coro|

        Starts the scheduled event.

        Shorthand for:

        .. code-block:: python3

            await event.edit(status=EventStatus.active)

        Parameters
        -----------
        reason: Optional[:class:`str`]
            The reason for starting the scheduled event.

        Raises
        ------
        ValueError
            The scheduled event has already started or has ended.
        Forbidden
            You do not have the proper permissions to start the scheduled event.
        HTTPException
            The scheduled event could not be started.

        Returns
        -------
        :class:`ScheduledEvent`
            The scheduled event that was started.
        (This scheduled event is already running.N)r/   r   	scheduled
ValueError_ScheduledEvent__modify_statusactiver>   rc   s     r?   startzScheduledEvent.start   sR      < ;k333GHHH))+*<fEEEEEEEEErA   c                  K   | j         t          j        urt          d          |                     t          j        |           d{V S )a  |coro|

        Ends the scheduled event.

        Shorthand for:

        .. code-block:: python3

            await event.edit(status=EventStatus.completed)

        Parameters
        -----------
        reason: Optional[:class:`str`]
            The reason for ending the scheduled event.

        Raises
        ------
        ValueError
            The scheduled event is not active or has already ended.
        Forbidden
            You do not have the proper permissions to end the scheduled event.
        HTTPException
            The scheduled event could not be ended.

        Returns
        -------
        :class:`ScheduledEvent`
            The scheduled event that was ended.
        z#This scheduled event is not active.N)r/   r   rs   rq   rr   endedrt   s     r?   endzScheduledEvent.end   sR      < ;k000BCCC))+*;VDDDDDDDDDrA   c                  K   | j         t          j        urt          d          |                     t          j        |           d{V S )a  |coro|

        Cancels the scheduled event.

        Shorthand for:

        .. code-block:: python3

            await event.edit(status=EventStatus.cancelled)

        Parameters
        -----------
        reason: Optional[:class:`str`]
            The reason for cancelling the scheduled event.

        Raises
        ------
        ValueError
            The scheduled event is already running.
        Forbidden
            You do not have the proper permissions to cancel the scheduled event.
        HTTPException
            The scheduled event could not be cancelled.

        Returns
        -------
        :class:`ScheduledEvent`
            The scheduled event that was cancelled.
        ro   N)r/   r   rp   rq   rr   	cancelledrt   s     r?   cancelzScheduledEvent.cancel
  sR      < ;k333GHHH))+*?HHHHHHHHHrA   .)r(   r)   r,   r-   r.   r/   rD   rc   r(   r)   r,   r   r-   Optional[datetime]r.   r   rD   bytesc               
   K   d S r<    )	r>   r(   r)   r,   r-   r.   r/   rD   rc   s	            r?   editzScheduledEvent.edit-  s       rA   r_   r   r*   4Literal[EntityType.voice, EntityType.stage_instance]c       
        
   K   d S r<   r   )r>   r(   r)   r_   r,   r-   r.   r*   r/   rD   rc   s              r?   r   zScheduledEvent.edit;         rA   Literal[EntityType.external]r5   c       
        
   K   d S r<   r   )r>   r(   r)   r,   r-   r.   r*   r/   rD   r5   rc   s              r?   r   zScheduledEvent.editK  r   rA   !Union[VoiceChannel, StageChannel]c       	        
   K   d S r<   r   )
r>   r(   r)   r_   r,   r-   r.   r/   rD   rc   s
             r?   r   zScheduledEvent.edit[         rA   c       	        
   K   d S r<   r   )
r>   r(   r)   r,   r-   r.   r/   rD   r5   rc   s
             r?   r   zScheduledEvent.editj  r   rA   )r(   r)   r_   r,   r-   r.   r*   r/   rD   r5   rc   Optional[Snowflake]r   c               J  K   i }i }|t           ur||d<   |t           ur-|j        t          d          |                                |d<   |t           ur||d<   |t           ur.t	          |t
                    st          d          |j        |d<   |t           ur.t	          |t                    st          d          |j        |d	<   |	t           ur|	t          |	          n|	}||d
<   |pt          |dt                     }|t           u re|rKt	          |t                    r6|j        t          u rt          j        }na|j        t           u rt          j        }nF|
t           dfvrt          j        }n.t	          |t                    st          d          |j        |d<   |t          d|j        j                   |p| j        }|| j        u}|t          j        t          j        fv rG|t           u s||rt          d          n
|j        |d<   |
t           dfvrt          d          d|d<   nb|t           dfvrt          d          d|d<   |
t           u s|
|rt          d          n|
|d<   | j        s|t           u s|t          d          |t           ur5|.|j        t          d          |                                |d<   n||d<   |r||d<    | j        j        j        | j        | j        fi |d|i d{V }t9          | j        |          }| j        |_        |S )ay  |coro|

        Edits the scheduled event.

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

        Parameters
        -----------
        name: :class:`str`
            The name of the scheduled event.
        description: :class:`str`
            The description of the scheduled event.
        channel: Optional[:class:`~discord.abc.Snowflake`]
            The channel to put the scheduled event in. If the channel is
            a :class:`StageInstance` or :class:`VoiceChannel` then
            it automatically sets the entity type.

            Required if the entity type is either :attr:`EntityType.voice` or
            :attr:`EntityType.stage_instance`.
        start_time: :class:`datetime.datetime`
            The time that the scheduled event will start. This must be a timezone-aware
            datetime object. Consider using :func:`utils.utcnow`.
        end_time: Optional[:class:`datetime.datetime`]
            The time that the scheduled event will end. This must be a timezone-aware
            datetime object. Consider using :func:`utils.utcnow`.

            If the entity type is either :attr:`EntityType.voice` or
            :attr:`EntityType.stage_instance`, the end_time can be cleared by
            passing ``None``.

            Required if the entity type is :attr:`EntityType.external`.
        privacy_level: :class:`PrivacyLevel`
            The privacy level of the scheduled event.
        entity_type: :class:`EntityType`
            The new entity type. If the channel is a :class:`StageInstance`
            or :class:`VoiceChannel` then this is automatically set to the
            appropriate entity type.
        status: :class:`EventStatus`
            The new status of the scheduled event.
        image: Optional[:class:`bytes`]
            The new image of the scheduled event or ``None`` to remove the image.
        location: :class:`str`
            The new location of the scheduled event.

            Required if the entity type is :attr:`EntityType.external`.
        reason: Optional[:class:`str`]
            The reason for editing the scheduled event. Shows up on the audit log.

        Raises
        -------
        TypeError
            ``image`` was not a :term:`py:bytes-like object`, or ``privacy_level``
            was not a :class:`PrivacyLevel`, or ``entity_type`` was not an
            :class:`EntityType`, ``status`` was not an :class:`EventStatus`, or
            an argument was provided that was incompatible with the scheduled event's
            entity type.
        ValueError
            ``start_time`` or ``end_time`` was not a timezone-aware datetime object.
        Forbidden
            You do not have permissions to edit the scheduled event.
        HTTPException
            Editing the scheduled event failed.

        Returns
        --------
        :class:`ScheduledEvent`
            The edited scheduled event.
        r(   Nzstart_time must be an aware datetime. Consider using discord.utils.utcnow() or datetime.datetime.now().astimezone() for local time.rC   r)   z+privacy_level must be of type PrivacyLevel.r.   z"status must be of type EventStatusr/   rD   _scheduled_event_entity_typez&entity_type must be of type EntityTyper*   zKinvalid GuildChannel type passed, must be VoiceChannel or StageChannel not z?channel must be set when entity_type is voice or stage_instancer3   zBlocation cannot be set when entity_type is voice or stage_instancerF   z2channel cannot be set when entity_type is externalz1location must be set when entity_type is externalr5   z1end_time must be set when entity_type is externalzend_time must be an aware datetime. Consider using discord.utils.utcnow() or datetime.datetime.now().astimezone() for local time.rE   rc   rf   )r   tzinforq   	isoformat
isinstancer   	TypeErrorrg   r   r   getattrr   typer   r   voicer   stage_instanceexternal	__class____name__r*   r&   r-   r$   rh   ri   r'   r"   r%   )r>   r(   r)   r_   r,   r-   r.   r*   r/   rD   r5   rc   rj   rL   image_as_str_entity_type_entity_type_changedr7   rk   s                      r?   r   zScheduledEvent.edity  s     f w"GFOW$$ (  Z   /9.B.B.D.DG*+g%%%0GM"''m\:: O MNNN'4':GO$  fk22 F DEEE &GHJOJ[*?*F*F*FafL+GG!^WW6TV]%^%^'!! 2:gv66 2<<//","2KK\\11",";K'400(1k:66 J HIII%0%6GM"z^e^o^xzz   #6d&6+43CCJ5z7GHHH'!!W_' g#$efffg )0
%.. deee)-G%&&wo-- TUUU$(GL!7""h&6' Y#$WXXXY (0$= Uh'&9&9X=M STTT7""#?*$ \   190B0B0D0D,--08,- 	2)1G%&:T[%:4=$'llU\lleklllllllll4888;rA   c               n   K   | j         j                            | j        | j        |           d{V  dS )a  |coro|

        Deletes the scheduled event.

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

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

        Raises
        ------
        Forbidden
            You do not have permissions to delete the scheduled event.
        HTTPException
            Deleting the scheduled event failed.
        rm   N)r$   rh   delete_scheduled_eventr'   r&   rt   s     r?   deletezScheduledEvent.delete-  sE      & k55dmTWU[5\\\\\\\\\\\rA   )limitbeforeafteroldest_firstr   Optional[int]r   r   r   boolAsyncIterator[User]c                 K   d fd}d fd	}|	 j         pd
}|t          u rd
u}n|}d
}|r|}
}	rfd}n|}
}	rt          k    rfd}	 |dnt          |d          }|dk     rd
S  |	||
|           d
{V \  }}
}|rt	          |          }|rt          ||          } fd|D             }d}t          |d          D ]
\  }}|W V  |dk     rd
S )a  |coro|

        Retrieves all :class:`User` that are subscribed to this event.

        This requires :attr:`Intents.members` to get information about members
        other than yourself.

        Raises
        -------
        HTTPException
            Retrieving the members failed.

        Returns
        --------
        List[:class:`User`]
            All subscribed users of this event.
        retrieverG   r   r   r   r   c                   K   |r|j         nd }j        j                            j        j         | d|           d {V }|r6||t          |          z  }t          |d         d         d                   }|||fS )NF)r   with_memberr   userr&   r&   r&   r$   rh   get_scheduled_event_usersr'   lenr   )r   r   r   	before_idusersr>   s        r?   _before_strategyz.ScheduledEvent.users.<locals>._before_strategy\  s      %+5		I+*DDtwhER[ E        E  <$SZZ'E59V#4T#:;;;&%''rA   r   c                   K   |r|j         nd }j        j                            j        j         | d|           d {V }|r6||t          |          z  }t          |d         d         d                   }|||fS )NF)r   r   r   r   r   r&   r   r   )r   r   r   after_idr   r>   s        r?   _after_strategyz-ScheduledEvent.users.<locals>._after_strategyj  s      #(2uxxdH+*DDtwhEQY E        E  :$SZZ'E%(6"24"8999%&&rA   Nc                2    | d         d         j         k     S Nr   r&   r   )ur   s    r?   <lambda>z&ScheduledEvent.users.<locals>.<lambda>  s    aio	&A rA   c                2    | d         d         j         k    S r   r   )r   r   s    r?   r   z&ScheduledEvent.users.<locals>.<lambda>  s    aio&@ rA   Td   r   c              3  X   K   | ]$}j                             |d                    V  %dS )r   N)r$   rI   ).0raw_userr>   s     r?   	<genexpr>z'ScheduledEvent.users.<locals>.<genexpr>  s8      SS(T[++HV,<==SSSSSSrA   r   )r   rG   r   r   r   r   )r   rG   r   r   r   r   )r1   r   r   minreversedfilter	enumerate)r>   r   r   r   r   r   r   reverse	predicatestrategyr6   r   r7   r   countr   s   ` ``            r?   r   zScheduledEvent.usersB  s     4	( 	( 	( 	( 	( 	(	' 	' 	' 	' 	' 	' =O+tE7""4'GG"G	 	A-ueH BAAAA	.eH A-//@@@@		#mssUCH!||'/x%'G'G!G!G!G!G!G!GD% &~~ /i..SSSSdSSSEE(22  t




s{{)	rA   r   r!   c                $    || j         |j        <   d S r<   )r%   r&   )r>   r   s     r?   	_add_userzScheduledEvent._add_user  s    #DGrA   user_idrG   c                <    | j                             |d            d S r<   )r%   pop)r>   r   s     r?   	_pop_userzScheduledEvent._pop_user  s    &&&&&rA   )r6   r    r7   r8   r9   r:   )r7   r8   r9   r:   )r7   rM   )r9   rO   )r9   rT   )r9   rX   )r9   r\   )r/   r   rc   rd   r9   r"   )rc   rd   r9   r"   )r(   rO   r)   rO   r,   r   r-   r|   r.   r   r/   r   rD   r}   rc   rd   r9   r"   )r(   rO   r)   rO   r_   r   r,   r   r-   r|   r.   r   r*   r   r/   r   rD   r}   rc   rd   r9   r"   )r(   rO   r)   rO   r,   r   r-   r   r.   r   r*   r   r/   r   rD   r}   r5   rO   rc   rd   r9   r"   )r(   rO   r)   rO   r_   r   r,   r   r-   r|   r.   r   r/   r   rD   r}   rc   rd   r9   r"   )r(   rO   r)   rO   r,   r   r-   r   r.   r   r/   r   rD   r}   r5   rO   rc   rd   r9   r"   )r(   rO   r)   rO   r_   r   r,   r   r-   r|   r.   r   r*   r   r/   r   rD   r}   r5   rO   rc   rd   r9   r"   )rc   rd   r9   r:   )
r   r   r   r   r   r   r   r   r9   r   )r   r!   r9   r:   )r   rG   r9   r:   )r   
__module____qualname____doc__	__slots__r@   r=   rK   rS   propertyrW   r[   r_   rb   rr   ru   rx   r{   r
   r   r   r   r   r   r   r   rA   r?   r"   r"   :   s       0 0dI*   
( ( ( (4N N N N| | | | ` ` ` X` 5 5 5 X5 7 7 7 X7 G G G XG    6: !F !F !F !F !F !FF 48 !E !E !E !E !E !EF 7; !I !I !I !I !I !IF  "'*&)! #     X  "'*&)! #     X  " &)! #     X  "'*&)! #     X  " &)! #     X" "'.&'.&-")% $r r r r r rh 7; ] ] ] ] ] ]0  $&*%)$] ] ] ] ] ]~$ $ $ $' ' ' ' ' 'rA   r"   N)1r   
__future__r   r   typingr   r   r   r   r	   r
   r   assetr   enumsr   r   r   r   mixinsr   objectr   r   utilsr   r   r   r   types.scheduled_eventr   BaseGuildScheduledEventPayloadr   'GuildScheduledEventWithUserCountPayloadr   abcr   r[   r   r_   r   r   r6   r    r   r!   r8   __all__r"   r   rA   r?   <module>r      s   0 # " " " " "       Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y       B B B B B B B B B B B B       ) ) ) ) ) ) ) ) P P P P P P P P P P P P p          33333333&&&&&&!&'EGn'n!ok	' k	' k	' k	' k	'X k	' k	' k	' k	' k	'rA   