o
    aqewR                     @   s8  d dl Z d dlZd dlZd dlmZ d dlmZmZmZmZ ddl	m
Z
mZmZmZ ddhZh dZG d	d
 d
e
ZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZdS )#    N)datetime)ListOptionalSetUnion   )
BaseObject
JsonObjectJsonValidatorshow_unknown_key_warningdangerprimary>   userschannelsconversationsc                   @   s&   e Zd ZdedefddZdd ZdS )Linkurltextc                C   s   || _ || _dS )zBase class used to generate links in Slack's not-quite Markdown, not quite HTML syntax
        https://api.slack.com/docs/message-formatting#linking_to_urls
        Nr   r   )selfr   r    r   Z/var/www/html/humari/django-venv/lib/python3.10/site-packages/slack/web/classes/objects.py__init__   s   
zLink.__init__c                 C   s(   | j rd}nd}d| j | | j  dS )N| <>)r   r   )r   	separatorr   r   r   __str__   s   zLink.__str__N)__name__
__module____qualname__strr   r   r   r   r   r   r      s    r   c                
       s@   e Zd Zdddeeef dededee f fddZ  Z	S )	DateLinkN)linkdatedate_formatfallbackr$   c                   sX   t |trt| }n|}|durd| }nd}t jd| d| | |d dS )zText containing a date or time should display that date in the local timezone of the person seeing the text.
        https://api.slack.com/reference/surfaces/formatting#date-formatting
        N^r   z!date^r   )
isinstancer   int	timestampsuperr   )r   r%   r&   r'   r$   epoch	__class__r   r   r   #   s   
$zDateLink.__init__)
r   r    r!   r   r   r*   r"   r   r   __classcell__r   r   r.   r   r#   "   s    
r#   c                       s>   e Zd ZdddddddZdddedef fd	d
Z  ZS )
ObjectLink#@z	!subteam^)CGUWBSr   r   	object_idr   c                   s2   | j |d  d}t j| | |d dS )zConvenience class to create links to specific object types
        https://api.slack.com/reference/surfaces/formatting#linking-channels
        r   r3   r   N)prefix_mappinggetupperr,   r   )r   r;   r   prefixr.   r   r   r   C   s   zObjectLink.__init__)r   r    r!   r<   r"   r   r0   r   r   r.   r   r1   9   s    $	r1   c                          e Zd Z fddZ  ZS )ChannelLinkc                       t  jddd dS )zRepresents an @channel link, which notifies everyone present in this channel.
        https://api.slack.com/reference/surfaces/formatting
        z!channelchannelr   Nr,   r   r   r.   r   r   r   L      zChannelLink.__init__r   r    r!   r   r0   r   r   r.   r   rA   K       rA   c                       r@   )HereLinkc                    rB   )zRepresents an @here link, which notifies all online users of this channel.
        https://api.slack.com/reference/surfaces/formatting
        z!hereherer   NrD   rE   r.   r   r   r   T   rF   zHereLink.__init__rG   r   r   r.   r   rI   S   rH   rI   c                       r@   )EveryoneLinkc                    rB   )zRepresents an @everyone link, which notifies all users of this workspace.
        https://api.slack.com/reference/surfaces/formatting
        z	!everyoneeveryoner   NrD   rE   r.   r   r   r   \   rF   zEveryoneLink.__init__rG   r   r   r.   r   rK   [   rH   rK   c                
   @   s   e Zd Zh dZee Zedd Ze	de
e fddZe	ddeeed f d	ede
d  fd
dZ			ddede
e de
e de
e fddZdS )
TextObject>   r   typeemojic                   C   s   t dt d S )Nz?subtype is deprecated since slackclient 2.6.0, use type instead)warningswarnDeprecationWarningr   r   r   r   _subtype_warningg   s   zTextObject._subtype_warningreturnc                 C   s   | j S N)rN   rE   r   r   r   subtypen   s   zTextObject.subtypemrkdwnr   default_typec                 C   s   |sd S t |tr|tjkrt|S t|S t |tr:t|}|d}|tjkr3tdi |S tdi |S t |t	rA|S | j
dt| d d S )NrN   zUnknown type (z$) detected when parsing a TextObjectr   )r)   r"   PlainTextObjectrN   from_strMarkdownTextObjectdictcopypoprM   loggerwarning)clsr   rX   dtr   r   r   parser   s$   








zTextObject.parseNrN   rV   rO   c                 K   s*   |r|    || _|r|n|| _|| _dS )z4Super class for new text "objects" used in Block kitN)rS   r   rN   rO   )r   r   rN   rV   rO   kwargsr   r   r   r      s
   	
zTextObject.__init__)rW   )NNN)r   r    r!   
attributeslogging	getLoggerr_   staticmethodrS   propertyr   r"   rV   classmethodr   r\   rd   boolr   r   r   r   r   rM   c   s8    

rM   c                       sz   e Zd ZdZedee f fddZdddedee	 f fd	d
Z
ededd fddZededefddZ  ZS )rY   
plain_textrT   c                       t  jdhS )NrO   r,   rf   unionrE   r.   r   r   rf         zPlainTextObject.attributesN)rO   r   rO   c                      t  j|| jd || _dS )zA plain text object, meaning markdown characters will not be parsed as
        formatting information.
        https://api.slack.com/reference/block-kit/composition-objects#text
        r   rN   N)r,   r   rN   rO   )r   r   rO   r.   r   r   r         
zPlainTextObject.__init__c                 C   s   t | ddS )NT)r   rO   )rY   r:   r   r   r   rZ      s   zPlainTextObject.from_strc                 C      t |  S )zNTransforms a string into the required object shape to act as a PlainTextObject)rY   rZ   to_dictr:   r   r   r   direct_from_string      z"PlainTextObject.direct_from_string)r   r    r!   rN   rj   r   r"   rf   r   rl   r   ri   rZ   r\   rw   r0   r   r   r.   r   rY      s     rY   c                       s   e Zd ZdZedee f fddZdddedee	 f fd	d
Z
ededd fddZededefddZeddededd fddZeddededefddZ  ZS )r[   rW   rT   c                    rn   )Nverbatimro   rE   r.   r   r   rf      rq   zMarkdownTextObject.attributesN)ry   r   ry   c                   rr   )zA Markdown text object, meaning markdown characters will be parsed as
        formatting information.
        https://api.slack.com/reference/block-kit/composition-objects#text
        rs   N)r,   r   rN   ry   )r   r   ry   r.   r   r   r      rt   zMarkdownTextObject.__init__c                 C   s
   t | dS )QTransforms a string into the required object shape to act as a MarkdownTextObjectr:   r[   r:   r   r   r   rZ      s   
zMarkdownTextObject.from_strc                 C   ru   )rz   )r[   rZ   rv   r:   r   r   r   rw      rx   z%MarkdownTextObject.direct_from_stringr   r$   titlec                 C   s    |rd| }t |  | dS )^Transform a Link object directly into the required object shape to act as a MarkdownTextObjectz: r:   r{   r$   r|   r   r   r   	from_link   s   
zMarkdownTextObject.from_linkc                 C   s   t | | S )r}   )r[   r   rv   r~   r   r   r   direct_from_link   s   z#MarkdownTextObject.direct_from_link)r   )r   r    r!   rN   rj   r   r"   rf   r   rl   r   ri   rZ   r\   rw   r   r   r   r0   r   r   r.   r   r[      s     "r[   c                   @   s  e Zd Zi ZdZdZdZdZede	d e
f fddZddd	d
de	ee
ef de	ee
ef de	ee
ef de	ee
ef def
ddZede ddd Zede ddd Zede ddd Zede ddd Zeddd  Zd&d"ed#e
fd$d%Zd	S )'ConfirmObjectd   i,     confirmc                 C   2   |rt |tr	|S t |trtdi |S d S d S Nr   )r)   r   r\   )ra   r   r   r   r   rd      s   

zConfirmObject.parseYesNoN)r   denystyler|   r   r   r   c                C   s   t j|tjd| _t j|tjd| _t j|tjd| _t j|tjd| _|| _	| jr.| jj
nd| _| jr8| jj
nd| _
| jrB| jj
nd| _| jrL| jj
nd| _| j	| _dS )a*  
        An object that defines a dialog that provides a confirmation step to any
        interactive element. This dialog will ask the user to confirm their action by
        offering a confirm and deny button.
        https://api.slack.com/reference/block-kit/composition-objects#confirm
        rX   N)rM   rd   rY   rN   _titler[   _text_confirm_deny_styler   r|   r   r   r   )r   r|   r   r   r   r   r   r   r   r      s   zConfirmObject.__init__ztitle attribute cannot exceed  charactersc                 C      | j d u pt| j j| jkS rU   )r   lenr   title_max_lengthrE   r   r   r   title_length
     zConfirmObject.title_lengthtext attribute cannot exceed c                 C   r   rU   )r   r   r   text_max_lengthrE   r   r   r   text_length  r   zConfirmObject.text_lengthz confirm attribute cannot exceed c                 C   r   rU   )r   r   r   confirm_max_lengthrE   r   r   r   confirm_length  s   zConfirmObject.confirm_lengthzdeny attribute cannot exceed c                 C   r   rU   )r   r   r   deny_max_lengthrE   r   r   r   deny_length  r   zConfirmObject.deny_lengthz6style for confirm must be either "primary" or "danger"c                 C   s   | j d u p	| j dv S )N)r   r   )r   rE   r   r   r   _validate_confirm_style  s   z%ConfirmObject._validate_confirm_styleblockoption_typerT   c                 C   s   |dkr7| j r| j jdkr| j jnd| jr| jjdkr| jjndd}| jr,| jj|d< | jr5| jj|d< |S |   i }| jrG| j |d< | jrQ| j |d< | j r[| j  |d	< | jre| j |d
< | jrm| j|d< |S )Nactionr   Okayr   Cancel)ok_textdismiss_textr|   r   r   r   r   )r   r   r   r   r   validate_jsonrv   r   )r   r   jsonr   r   r   rv      s<   
zConfirmObject.to_dictr   )r   r    r!   rf   r   r   r   r   rk   r   r\   rd   r"   rY   rM   r   r
   r   r   r   r   r   rv   r   r   r   r   r      sB    





r   c                   @   s  e Zd ZdZi Zee ZdZdZ	dddddde
dee
 deee
eef  dee
 d	ee
 d
efddZede ddd Zede ddd Zede	 ddd Zedeeeed f   ded  fddZd"de
defddZede
fd d!ZdS )#OptionzOption object used in dialogs, legacy message actions, and blocks
    JSON must be retrieved with an explicit option_type - the Slack API has
    different required formats in different situations
    K   N)labelr   descriptionr   valuer   r   r   r   othersc                K   s`   |rt || _d| _nd| _|| _| jr| jjnd| _| j| _|| _|| _|| _t	| | dS )a  
        An object that represents a single selectable item in a block element (
        SelectElement, OverflowMenuElement) or dialog element
        (StaticDialogSelectElement)

        Blocks:
        https://api.slack.com/reference/messaging/composition-objects#option

        Dialogs:
        https://api.slack.com/dialogs#select_elements

        Legacy interactive attachments:
        https://api.slack.com/docs/interactive-message-field-guide#option_fields

        Args:
            label: A short, user-facing string to label this option to users.
                Cannot exceed 75 characters.
            value: A short string that identifies this particular option to your
                application. It will be part of the payload when this option is selected
                . Cannot exceed 75 characters.
            description: A user-facing string that provides more details about
                this option. Only supported in legacy message actions, not in blocks or
                dialogs.
        N)
rM   rd   r   _labelr   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   N  s   "zOption.__init__label attribute cannot exceed r   c                 C      | j d u pt| j | jkS rU   )r   r   label_max_lengthrE   r   r   r   _validate_label_length     zOption._validate_label_lengthr   c                 C   s(   | j d u p| j jd u pt| j j| jkS rU   )r   r   r   r   rE   r   r   r   _validate_text_length  s
   

zOption._validate_text_lengthzvalue attribute cannot exceed c                 C   s   t | j| jkS rU   )r   r   value_max_lengthrE   r   r   r   _validate_value_length  rq   zOption._validate_value_lengthoptionsrT   c                 C   r   |d u rd S g }|D ],}t |tr!t|}|tdi | q
t |tr,|| q
| jd| d q
|S )Nz,Unknown option object detected and skipped ()r   )r)   r\   r]   appendr   r_   r`   )ra   r   option_objectsorb   r   r   r   	parse_all  s   


zOption.parse_allr   r   c                 C   s   |    |dkr| j| jdS |dkr&| j| jd}| jdur$| j|d< |S | jp.t| j}| | jd}| jr?| j|d< | jrG| j|d< |S )z
        Different parent classes must call this with a valid value from OptionTypes -
        either "dialog", "action", or "block", so that JSON is returned in the
        correct shape.
        dialog)r   r   r   )r   r   Nr   r   )	r   r   r   r   r   rY   rZ   rv   r   )r   r   r   r   r   r   r   rv     s"   



zOption.to_dictvalue_and_labelc                 C   s   t | | dS )z>Creates a simple Option instance with the same value and label)r   r   )r   )r   r   r   r   from_single_value  s   zOption.from_single_valuer   )r   r    r!   __doc__rf   rg   rh   r_   r   r   r"   r   r   r\   rM   r   r
   r   r   r   rk   r   r   rv   ri   r   r   r   r   r   r   B  sL    

7


r   c                   @   s   e Zd ZdZi ZdZdZee Z	ddde
eeeef  deeeef  defd	d
Zede ddd Zede ddd Zede
eeed f   de
ed   fddZddedefddZdS )OptionGroupz
    JSON must be retrieved with an explicit option_type - the Slack API has
    different required formats in different situations
    r   r   N)r   r   r   r   c                K   s@   t j|tjd| _| jr| jjnd| _t|| _	t
| | dS )aj  
        Create a group of Option objects - pass in a label (that will be part of the
        UI) and a list of Option objects.

        Blocks:
        https://api.slack.com/reference/messaging/composition-objects#option-group

        Dialogs:
        https://api.slack.com/dialogs#select_elements

        Legacy interactive attachments:
        https://api.slack.com/docs/interactive-message-field-guide#option_groups_to_place_within_message_menu_actions

        Args:
            label: Text to display at the top of this group of options.
            options: A list of no more than 100 Option objects.
        r   N)rM   rd   rY   rN   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r     s   zOptionGroup.__init__r   r   c                 C   r   rU   )r   r   r   rE   r   r   r   r     r   z"OptionGroup._validate_label_lengthz options attribute cannot exceed z	 elementsc                 C   r   rU   )r   r   options_max_lengthrE   r   r   r   _validate_options_length  r   z$OptionGroup._validate_options_lengthoption_groupsrT   c                 C   r   )Nz2Unknown option group object detected and skipped (r   r   )r)   r\   r]   r   r   r_   r`   )ra   r   option_group_objectsr   rb   r   r   r   r     s   



zOptionGroup.parse_allr   r   c                    sX   |     fdd| jD } dkr| j|dS  dkr"| j|dS | j }||dS )Nc                    s   g | ]}|  qS r   )rv   ).0r   r   r   r   
<listcomp>  s    z'OptionGroup.to_dict.<locals>.<listcomp>r   )r   r   r   )r   r   )r   r   r   r   rv   )r   r   dict_options
dict_labelr   r   r   rv     s   
zOptionGroup.to_dictr   )r   r    r!   r   rf   r   r   rg   rh   r_   r   r   r"   r\   rM   r   r   r   r
   r   r   rk   r   rv   r   r   r   r   r     s2    

 


r   c                   @   sR   e Zd ZdhZeded ef fddZdddee	 fddZ
d	efd
dZdS )DispatchActionConfigtrigger_actions_onconfigc                 C   r   r   )r)   r   r\   )ra   r   r   r   r   rd   $  s   

zDispatchActionConfig.parseN)r   c                C   s   |pg | _ dS )z
        Determines when a plain-text input element will return a block_actions interaction payload.
        https://api.slack.com/reference/block-kit/composition-objects#dispatch_action_config
        N)_trigger_actions_on)r   r   r   r   r   r   0  s   	zDispatchActionConfig.__init__rT   c                 C   s    |    i }| jr| j|d< |S )Nr   )r   r   )r   r   r   r   r   rv   ;  s
   
zDispatchActionConfig.to_dict)r   r    r!   rf   rk   r   r\   rd   r   listr   rv   r   r   r   r   r   !  s    
r   )r]   rg   rP   r   typingr   r   r   r   r   r   r	   r
   r   ButtonStylesDynamicSelectElementTypesr   r#   r1   rA   rI   rK   rM   rY   r[   r   r   r   r   r   r   r   r   <module>   s,    :&f [