
    yit
              	       r    d dl Z d dlZd dlmZ d dlmZ  ee          ZdededefdZ	dded	ed
e
defdZdS )    N)	WebClient)setup_logger	file_path
channel_idreturnc                    	 t           j                            |           sd|  S t           j                            d          pt           j                            d          }t          |          }t           j                            |           }t           j                            |           }|dk    rd|dz  dz  dd	S t          	                    d
|  d|            |
                    || |d| d           d|  dS # t          $ r,}t                              d|            d| cY d}~S d}~ww xY w)z
    Uploads a file from the server to Slack.
    
    Args:
        file_path: Absolute path to the file on the server.
        channel_id: Slack channel to upload to.
        
    Returns:
        String message indicating success or failure.
    u   ❌ File not found: SHELL_SLACK_BOT_TOKENSLACK_BOT_TOKEN)tokeni   u   ❌ File too large (i   z.1fzMB). Limit is 50MB.z
Uploading z to u   📂 Here is `z` from the server.)channelfiletitleinitial_commentu   ✅ Successfully uploaded `z` to Slack.zDownload file failed: u   ❌ Error uploading file: N)ospathexistsenvirongetr   getsizebasenameloggerinfofiles_upload_v2	Exceptionerror)r   r   r   client	file_size	file_namees          1/root/projects/butler/slack_bot/tools/file_ops.pydownload_filer!      sz   0w~~i(( 	65)555
677\2:>>J[;\;\'''GOOI..	G$$Y//	 '''V)D.*=VVVVV<<<
<<=== 	JYJJJ	 	 	
 	
 	
 DYCCCC 0 0 01a11222/A////////0s*   #D BD AD 
D>!D93D>9D>Fcontent	overwritec                    	 t           j                            |           r|sd|  dS t          j        t           j                            |           d           t          | dd          5 }|                    |           ddd           n# 1 swxY w Y   d	|  d
t          |           dS # t          $ r,}t          
                    d|            d| cY d}~S d}~ww xY w)a  
    Saves text content to a file on the server (Upload to Server).
    
    Args:
        file_path: Target absolute path.
        content: Text content to write.
        overwrite: Whether to overwrite existing files.
        
    Returns:
        Status message.
    u   ⚠️ File `z5` already exists. Use `overwrite=True` to replace it.T)exist_okwzutf-8)encodingNu    ✅ Successfully saved file to `z` (z chars).zSave file failed: u   ❌ Error saving file: )r   r   r   makedirsdirnameopenwritelenr   r   r   )r   r"   r#   fr   s        r    	save_filer.   1   sP   - 7>>)$$ 	dY 	dc9cccc 	BGOOI..>>>>)S7333 	qGGG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 W)VVGVVVV - - --!--...,,,,,,,,,-sG   &B1 AB1 .BB1 BB1 BB1 1
C';!C"C'"C')F)r   requests	slack_sdkr   health.utils.logging_configr   __name__r   strr!   boolr.        r    <module>r7      s    				        4 4 4 4 4 4	h		'0S '0c '0c '0 '0 '0 '0R- - -s -t - - - - - - -r6   