
    cjhH                    j   d 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mZ dd	lmZ dd
lmZ dZer@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* ddl$m+Z, e
jZ                  Z- G d d      Z' G d d      Z% G d d      Z+ G d de      Z)y)aF  
The MIT License (MIT)

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)	timedelta)cached_property)TYPE_CHECKING   )utils)AutoModActionTypeAutoModEventTypeAutoModKeywordPresetTypeAutoModTriggerTypetry_enum)Hashable)Object)AutoModRuleAutoModActionAutoModActionMetadataAutoModTriggerMetadata)	Snowflake)ForumChannelTextChannelVoiceChannel)Guild)Member)Role)ConnectionState)r   )r   )r   )r   c                  P    e Zd ZdZdZeeef	 	 	 	 	 ddZd	dZed
d       Z	ddZ
y)r   a  Represents an action's metadata.

    Depending on the action's type, different attributes will be used.

    .. versionadded:: 2.0

    Attributes
    ----------
    channel_id: :class:`int`
        The ID of the channel to send the message to.
        Only for actions of type :attr:`AutoModActionType.send_alert_message`.
    timeout_duration: :class:`datetime.timedelta`
        How long the member that triggered the action should be timed out for.
        Only for actions of type :attr:`AutoModActionType.timeout`.
    custom_message: :class:`str`
        An additional message shown to members when their message is blocked.
        Maximum 150 characters.
        Only for actions of type :attr:`AutoModActionType.block_message`.
    
channel_idtimeout_durationcustom_messagec                .    || _         || _        || _        y Nr   )selfr   r   r    s       B/var/www/html/venv/lib/python3.12/site-packages/discord/automod.py__init__zAutoModActionMetadata.__init__]   s      *+;#1    c                    i }| j                   t        ur| j                   |d<   | j                  t        ur| j                  j                         |d<   | j                  t        ur| j                  |d<   |S )Nr   duration_secondsr    )r   MISSINGr   total_secondsr    )r#   datas     r$   to_dictzAutoModActionMetadata.to_dictg   sm    ??')!%D  /'+'<'<'J'J'LD#$g-%)%8%8D!"r&   c                    i }|j                  d      x}t        |      |d<   |j                  d      x}t        |      |d<   |j                  d      x}||d<    | di |S )Nr   r(   )secondsr   r     )getintr   )clsr+   kwargsr   r(   r    s         r$   	from_dictzAutoModActionMetadata.from_dictu   s|    ((<00J=#&z?F<  $); <<I)2;K)LF%&"hh'788NE'5F#$}V}r&   c                    d}g }|D ]-  }t        | |      x}t        us|j                  | d|        / dj                  |      }d| dS )Nr   = z<AutoModActionMetadata >getattrr)   appendjoinr#   
repr_attrsinnerattrvalues        r$   __repr__zAutoModActionMetadata.__repr__   sh    


  	0D t,,W<vQug./	0 (q11r&   N)r   r1   r   r   r    strreturndict)r+   AutoModActionMetadataPayloadrE   rC   __name__
__module____qualname____doc__	__slots__r)   r%   r,   classmethodr4   rB   r/   r&   r$   r   r   @   sX    ,I "&-%	22 $2 	2  2r&   r   c                  >    e Zd ZdZdZddZd	dZed
d       ZddZ	y)r   a  Represents an action for a guild's auto moderation rule.

    .. versionadded:: 2.0

    Attributes
    ----------
    type: :class:`AutoModActionType`
        The action's type.
    metadata: :class:`AutoModActionMetadata`
        The action's metadata.
    typemetadatac                     || _         || _        y r"   rQ   )r#   action_typerS   s      r$   r%   zAutoModAction.__init__   s    '2	/7r&   c                d    | j                   j                  | j                  j                         dS )NrQ   )rR   rA   rS   r,   r#   s    r$   r,   zAutoModAction.to_dict   s'    IIOO--/
 	
r&   c                b     | t        t        |d         t        j                  |d               S )NrR   rS   )r   r	   r   r4   )r2   r+   s     r$   r4   zAutoModAction.from_dict   s1    &V5!++D,<=
 	
r&   c                "    d| j                    dS )Nz<AutoModAction type=r8   )rR   rW   s    r$   rB   zAutoModAction.__repr__   s    %dii[22r&   N)rU   r	   rS   r   rD   )r+   AutoModActionPayloadrH   )
rJ   rK   rL   rM   rN   r%   r,   rO   r4   rB   r/   r&   r$   r   r      s1    
I
8
 
 
3r&   r   c                  \    e Zd ZdZdZeeeeef	 	 	 	 	 	 	 	 	 ddZd	dZed
d       Z	ddZ
y)r   a
  Represents a rule's trigger metadata, defining additional data used to determine when a rule triggers.

    Depending on the trigger type, different metadata attributes will be used:

    +-----------------------------+--------------------------------------------------------------------------------+
    |   Attribute                 |   Trigger Types                                                                |
    +=============================+================================================================================+
    | :attr:`keyword_filter`      | :attr:`AutoModTriggerType.keyword`                                             |
    +-----------------------------+--------------------------------------------------------------------------------+
    | :attr:`regex_patterns`      | :attr:`AutoModTriggerType.keyword`                                             |
    +-----------------------------+--------------------------------------------------------------------------------+
    | :attr:`presets`             | :attr:`AutoModTriggerType.keyword_preset`                                      |
    +-----------------------------+--------------------------------------------------------------------------------+
    | :attr:`allow_list`          | :attr:`AutoModTriggerType.keyword`\, :attr:`AutoModTriggerType.keyword_preset` |
    +-----------------------------+--------------------------------------------------------------------------------+
    | :attr:`mention_total_limit` | :attr:`AutoModTriggerType.mention_spam`                                        |
    +-----------------------------+--------------------------------------------------------------------------------+

    Each attribute has limits that may change based on the trigger type.
    See `here <https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata-field-limits>`_
    for information on attribute limits.

    .. versionadded:: 2.0

    Attributes
    ----------
    keyword_filter: List[:class:`str`]
        A list of substrings to filter.

    regex_patterns: List[:class:`str`]
        A list of regex patterns to filter using Rust-flavored regex, which is not
        fully compatible with regex syntax supported by the builtin `re` module.

        .. versionadded:: 2.4

    presets: List[:class:`AutoModKeywordPresetType`]
        A list of preset keyword sets to filter.

    allow_list: List[:class:`str`]
        A list of substrings to allow, overriding keyword and regex matches.

        .. versionadded:: 2.4

    mention_total_limit: :class:`int`
        The total number of unique role and user mentions allowed.

        .. versionadded:: 2.4
    keyword_filterregex_patternspresets
allow_listmention_total_limitc                J    || _         || _        || _        || _        || _        y r"   r\   )r#   r]   r^   r_   r`   ra   s         r$   r%   zAutoModTriggerMetadata.__init__   s*     -,$#6 r&   c                   i }| j                   t        ur| j                   |d<   | j                  t        ur| j                  |d<   | j                  t        ur'| j                  D cg c]  }|j                   c}|d<   | j
                  t        ur| j
                  |d<   | j                  t        ur| j                  |d<   |S c c}w )Nr]   r^   r_   r`   ra   )r]   r)   r^   r_   rA   r`   ra   )r#   r+   wordsets      r$   r,   zAutoModTriggerMetadata.to_dict  s    g-%)%8%8D!"g-%)%8%8D!"<<w&<@LLIw}}IDO??')!%D##72*.*B*BD&' Js   %Cc                H   i }|j                  d      x}||d<   |j                  d      x}||d<   |j                  d      x}!|D cg c]  }t        t        |       c}|d<   |j                  d      x}||d<   |j                  d      x}||d<    | di |S c c}w )Nr]   r^   r_   r`   ra   r/   )r0   r   r   )	r2   r+   r3   r]   r^   r_   rd   r`   ra   s	            r$   r4   z AutoModTriggerMetadata.from_dict  s    "hh'788NE'5F#$"hh'788NE'5F#$xx	**G7KR!@G17;!F9 ((<00J=#-F< #'88,A#BBO,?F()}V}!s   
Bc                    d}g }|D ]-  }t        | |      x}t        us|j                  | d|        / dj                  |      }d| dS )Nr\   r6   r7   z<AutoModTriggerMetadata r8   r9   r=   s        r$   rB   zAutoModTriggerMetadata.__repr__1  sh    

  	0D t,,W<vQug./	0 )%22r&   N)
r]   	list[str]r^   rg   r_   zlist[AutoModKeywordPresetType]r`   rg   ra   r1   rD   )r+   AutoModTriggerMetadataPayloadrH   rI   r/   r&   r$   r   r      ss    /bI %,$+29 '#*7!7 "7 0	7
 7 !7(  ,3r&   r   c            	          e Zd ZdZ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dddZeeeeeeed
d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy
)r   a  Represents a guild's auto moderation rule.

    .. versionadded:: 2.0

    .. container:: operations

        .. describe:: x == y

            Checks if two rules are equal.

        .. describe:: x != y

            Checks if two rules are not equal.

        .. describe:: hash(x)

            Returns the rule's hash.

        .. describe:: str(x)

            Returns the rule's name.

    Attributes
    ----------
    id: :class:`int`
        The rule's ID.
    name: :class:`str`
        The rule's name.
    creator_id: :class:`int`
        The ID of the user who created this rule.
    event_type: :class:`AutoModEventType`
        Indicates in what context the rule is checked.
    trigger_type: :class:`AutoModTriggerType`
        Indicates what type of information is checked to determine whether the rule is triggered.
    trigger_metadata: :class:`AutoModTriggerMetadata`
        The rule's trigger metadata.
    actions: List[:class:`AutoModAction`]
        The actions to perform when the rule is triggered.
    enabled: :class:`bool`
        Whether this rule is enabled.
    exempt_role_ids: List[:class:`int`]
        The IDs of the roles that are exempt from this rule.
    exempt_channel_ids: List[:class:`int`]
        The IDs of the channels that are exempt from this rule.
    )__dict___stateidguild_idname
creator_id
event_typetrigger_typetrigger_metadataactionsenabledexempt_role_idsexempt_channel_idsc               >   || _         t        |d         | _        t        |d         | _        |d   | _        t        |d         | _        t        t        |d         | _        t        t        |d         | _
        t        j                  |d         | _        |d   D cg c]  }t        j                  |       c}| _        |d	   | _        |d
   D cg c]  }t        |       c}| _        |d   D cg c]  }t        |       c}| _        y c c}w c c}w c c}w )Nrl   rm   rn   ro   rp   rq   rr   rs   rt   exempt_rolesexempt_channels)rk   r1   rl   rm   rn   ro   r   r
   rp   r   rq   r   r4   rr   r   rs   rt   ru   rv   )r#   stater+   drcs         r$   r%   zAutoModRule.__init__  s    (-4: j!12f	"4#56,4d<0-
 19^ 41
 #,,T2D-EF 	 15Y-
+,M##A&-
 ")_;?;O*Pa3q6*P>BCT>U-Vc!f-V-
 +Q-Vs   DD5Dc                <    d| j                    d| j                   dS )Nz<AutoModRule name=z id=r8   )rn   rl   rW   s    r$   rB   zAutoModRule.__repr__  s    #DII;d477)1==r&   c                    | j                   S r"   )rn   rW   s    r$   __str__zAutoModRule.__str__  s    yyr&   c                L    | j                   j                  | j                        S )zThe guild this rule belongs to.)rk   
_get_guildrm   rW   s    r$   guildzAutoModRule.guild  s     {{%%dmm44r&   c                f    | j                   y| j                   j                  | j                        S )z!The member who created this rule.N)r   
get_memberro   rW   s    r$   creatorzAutoModRule.creator  s*     ::zz$$T__55r&   c                    | j                   #| j                  D cg c]  }t        |       c}S | j                  D cg c]*  }| j                   j                  |      xs t        |      , c}S c c}w c c}w )zThe roles that are exempt
        from this rule.

        If a role is not found in the guild's cache,
        then it will be returned as an :class:`Object`.
        )r   ru   r   get_role)r#   role_ids     r$   rx   zAutoModRule.exempt_roles  sr     ::373G3GHF7OHH  //
 JJ(;F7O;
 	
 I

   A0/A5c                    | j                   #| j                  D cg c]  }t        |       c}S | j                  D cg c]*  }| j                   j                  |      xs t        |      , c}S c c}w c c}w )zThe channels that are exempt from this rule.

        If a channel is not found in the guild's cache,
        then it will be returned as an :class:`Object`.
        )r   rv   r   get_channel)r#   r   s     r$   ry   zAutoModRule.exempt_channels  st     ::9=9P9PQ:F:&QQ #55
 JJ"":.D&2DD
 	
 R
r   Nc                   K   | j                   j                  j                  | j                  | j                  |       d{    y7 w)ae  |coro|

        Deletes this rule.

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

        Raises
        ------
        Forbidden
            You do not have the Manage Guild permission.
        HTTPException
            The operation failed.
        reasonN)rk   httpdelete_auto_moderation_rulerm   rl   )r#   r   s     r$   deletezAutoModRule.delete  s>     " kk::MM4776 ; 
 	
 	
s   A A
AA
)rn   rp   rr   rs   rt   rx   ry   r   c               p  K   | j                   j                  }	i }
|t        ur||
d<   |t        ur|j                  |
d<   |t        ur|j	                         |
d<   |t        ur!|D cg c]  }|j	                          c}|
d<   |t        ur||
d<   |t        ur|D cg c]  }|j
                   c}|
d<   |t        ur|D cg c]  }|j
                   c}|
d<   |
rH|	j                  | j                  | j
                  |
|       d	{   }t        | j                   |
      S y	c c}w c c}w c c}w 7 +w)a  |coro|

        Edits this rule.

        Parameters
        ----------
        name: :class:`str`
            The rule's new name.
        event_type: :class:`AutoModEventType`
            The new context in which the rule is checked.
        trigger_metadata: :class:`AutoModTriggerMetadata`
            The new trigger metadata.
        actions: List[:class:`AutoModAction`]
            The new actions to perform when the rule is triggered.
        enabled: :class:`bool`
            Whether this rule is enabled.
        exempt_roles: List[:class:`abc.Snowflake`]
            The roles that will be exempt from this rule.
        exempt_channels: List[:class:`abc.Snowflake`]
            The channels that will be exempt from this rule.
        reason: Optional[:class:`str`]
            The reason for editing this rule. Shows up in the audit log.

        Returns
        -------
        Optional[:class:`.AutoModRule`]
            The newly updated rule, if applicable. This is only returned
            when fields are updated.

        Raises
        ------
        Forbidden
            You do not have the Manage Guild permission.
        HTTPException
            The operation failed.
        rn   rp   rr   rs   rt   rx   ry   r   N)rz   r+   )	rk   r   r)   rA   r,   rl   edit_auto_moderation_rulerm   r   )r#   rn   rp   rr   rs   rt   rx   ry   r   r   payloadar|   r}   r+   s                  r$   editzAutoModRule.edit  s9    ` {{w"GFOW$$.$4$4GL!7**:*B*B*DG&''!7>!?!!))+!?GI'!!(GI w&5A&Bqtt&BGN#')8G)H1!$$)HG%&77tww 8  D T[[t<<	  "@ 'C *Is6   A$D6&D%=D6D*/D6D/4D6D4	,D6)rz   r   r+   AutoModRulePayloadrH   )rE   zGuild | None)rE   zMember | None)rE   zlist[Role | Object])rE   z8list[TextChannel | ForumChannel | VoiceChannel | Object]r"   )r   
str | NonerE   None)rn   rC   rp   r
   rr   r   rs   zlist[AutoModAction]rt   boolrx   list[Snowflake]ry   r   r   r   rE   zAutoModRule | None)rJ   rK   rL   rM   rN   r%   rB   r   r   r   r   rx   ry   r   r)   r   r/   r&   r$   r   r   C  s   ,\I W W !	W6> 5 5 6 6 
 
 
	A
 

0 '.3:'.(/+2!M= M= %	M=
 1M= %M= M= &M= )M= M= 
M=r&   r   N).rM   
__future__r   datetimer   	functoolsr   typingr    r   enumsr	   r
   r   r   r   mixinsr   objectr   __all__abcr   channelr   r   r   r   r   memberr   roler   rz   r   types.automodr   rZ   r   rG   r   r   r   rh   r)   r/   r&   r$   <module>r      s   0 #  %       @@&DT@V
--R2 R2j&3 &3RB3 B3Jm=( m=r&   