
    hk'                         d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ ddlmZ dedefd	Zdded
ede	e   fdZd Zedk(  r	  ej&                   e              yy# e$ r  ed       Y yw xY w)z Entry point for the Discord bot.    N)Path)Optional)Bot)sanitize_filenametokenreturnc                   K   | j                  d      }t        |      dk(  r	 ddl}|j                  j	                         }d|_        d|_        d|_        |j                  |      }	 t        j                  |j                  |       d       d{    t        |j                  d	      r|j                  j                  nd}|j                          d{    |rd	S d
S 	 ddl}|j                         }	 t        j                  |j                  |       d       d{    |j                          d{    y
7 7 i# t        j                   $ r7 t#        d       |j%                         s|j                          d{  7   Y nbt&        $ rW}t#        dt)        |      j*                   d|        |j%                         s|j                          d{  7   Y d}~nd}~ww xY w# t,        $ r t#        d       Y %w xY w7 7 # t        j                   $ r7 t#        d       |j%                         s|j                          d{  7   Y yt&        $ rW}t#        dt)        |      j*                   d|        |j%                         s|j                          d{  7   Y d}~yd}~ww xY w# t,        $ r t#        d       Y yw xY ww)z0Detects if a token is a bot token or user token..   r   NTintents
   timeoutbotuserz"Timeout during bot token detectionzBot login attempt failed: : z6discord.py not installed, skipping bot token detectionz#Timeout during user token detectionzUser login attempt failed: z8selfcord.py not installed, skipping user token detectionunknown)splitlendiscordIntentsdefaultmessage_contentmembers	presencesClientasynciowait_forloginhasattrr   r   closeTimeoutErrorprint	is_closed	Exceptiontype__name__ImportErrorselfcord)r   partsr   r   temp_clientis_boter*   s           S/home/liforra/rclone/mounts/hetzner/services/copyparty/copyparty/LiforraBot/main.pydetect_token_typer0      s     KKE
5zQ	Loo--/G&*G#"GO $G!...9K.&&{'8'8'?LLL189I9I51Q))--W[!''))) &u2F2Joo'	*"";#4#4U#;RHHH##%%%- M)'' .:<",,.%++--- .2473C3C2DBqcJK",,.%++---.  	LJK	L I%## 	*79((*!'')))   	*/Q0@0@/AA3GH((*!''))) 	*  JHIJsH   KAG1 ))E E AE EE  K!E "K$J; 9)H "H#H :H;H ?K E E AG,FG,G1 G,AG'GG'"G1 'G,,G1 /K1H	KH		KH H AJ8IJ8J; KJ8!AJ3(J+)J3.J; 2K3J88J; ;KKKK
token_typec                 |  K   |t        |        d{   }|dk(  rG	 ddl}|j                  j                         }d|_        d|_        d|_        |j                  |      }n	 ddl
}|j                         }	 t        j                  |j                  |       d	       d{    t        |j                        }|j!                          d{    ||j#                         s	 |j!                          d{    S S 7 # t        $ r t        d       Y yw xY w# t        $ r t        d       Y yw xY w7 7 h7 @#  Y S xY w# t        j$                  $ rD t        d
| d       Y |j#                         s"	 |j!                          d{  7   y#  Y yxY wyt&        $ r`}t        dt)        |      j*                   d|        Y d}~|j#                         s"	 |j!                          d{  7   y#  Y yxY wyd}~ww xY w# |j#                         s"	 |j!                          d{  7   w #  Y w xY ww xY ww)z#Gets username from a Discord token.Nr   r   Tr   zdiscord.py not installedzselfcord.py not installedr   r   zTimeout getting username for z tokenzError getting username: r   )r0   r   r   r   r   r   r   r   r)   r$   r*   r   r   r    strr   r"   r%   r#   r&   r'   r(   )r   r1   r   r   r,   r*   usernamer.   s           r/   get_username_from_tokenr5   F   s8    ,U33
U		oo--/G&*G#"GO $G!...9K
	"//+K
{007DDD{''(!!! $$&!''))) 'C 4  	,-	  	-.	
 	E! *  -j\@A
 $$&!'')))	 '	  (a)9)9(:"QC@A$$&!'')))	 '	 $$&!'')))	 'sY  H<D	H<AD #H<%D :)E #D7$,E D9E H<'D=:D;;D=?H<DH<DH<D41H<3D44H<7E 9E ;D==E?H<"H&H 'H<8F FF H<FH<H"$G=H 
H<G5 .G1/G5 4H<5G97H<=HH H9H1*H-+H10H91H53H99H<c            
        K   t        d      } | j                         st        d      S t        j                  |       j                  di       }|j                  dd      }g }|dk(  rt        d       |j                  dd      }|j                  d	d      }|j                  d
d      j                         }|sB|r@t        |      j                         r't        |      j                         j                         }|r{|dv rt        d|        |}nt        d       t        |       d{   }|dk(  rt        d       nt        d|        |j                  t        |t        d      |             nt        d       n}|dk(  rwt        d       t        |j                  dd            }t        |j                  dd            }	|	dz  }
|	dz  }|j                         s#t        d| d       |j                  dd        y	 |
j                         r#t        j                  |
j                               ni }	 |j                         r#t        j                  |j                               ni }d!}t#        |j%                               D ])  }|j'                         s|j                         j                         }|s6t        d"|j(                   d#       t+        j,                  |j/                               j1                         dd$ }||v r||   dv r||   }t        d%|        nt        |       d{   }|dk(  r;t        d&|j(                   d'       t        d(| d)       t        d*| d+| d,       t        d|        |	|z  }|j                         r|}t        d-|        nt        d.       t3        ||       d{   }|st        d/|j(                   d'       et5        |      }t        d0|        |j                  |      }|rX||k7  rS|	|z  }|	|z  }|j                         r/t        d1| d2| d3| d4       	 t7        j8                  ||       |}n|}|||<   d}n |	|z  }|st        d8| d9| d:       |||<   d}|s|j                  t        |||             , |rCt        d;       |	j                  d<       |
j=                  t        j>                  |d=>             |st        d?      S t        d@tA        |       dA       tC        jD                  |D cg c]  }|jG                          c}dBdi d{    y7 6# t        j                   $ r i }Y =w xY w# t        j                   $ r i }Y #w xY w7 \7 # t:        $ r}t        d5| d6| d7       |}Y d}~Td}~ww xY wc c}w 7 vw)CzMain entry point.zconfig.tomlz$FATAL: Main 'config.toml' not found.generalmodesinglezOperating in SINGLE mode.r    z
token-filez
token-type)r   r   z#Using config-specified token type: zDetecting token type...Nr   z:FATAL: Could not determine token type or token is invalid.zToken type: r
   )r   data_dirr1   z0FATAL: No token found for single mode operation.multizOperating in MULTI mode.token_directoryz./tokensdata_directoryz
./bot_datazuser_map.jsonztoken_types.jsonzFATAL: Token directory 'z' not found. Creating.T)parentsexist_okFz
Processing token from z...   z!Using saved token type override: z'!!! Could not determine token type for z, skipping. !!!zTip: Add to :z  "z": "bot"  or  "z	": "user"zUsing existing data directory: zGetting username for token...z!!! Could not get username for z
Username: zUsername changed for z: 'z' -> 'z'. Renaming.z!!! Could not rename dir for r   z. !!!z
New user 'z' for hash z. Creating mapping.z
Saving updated user map...)r@      )indentz(
No valid bot instances to run. Exiting.z

Starting z bot instance(s)...
return_exceptions)$r   existsr$   tomlloadgetlower	read_textstripr0   appendr   is_dirmkdirjsonloadsJSONDecodeErrorsortediterdiris_filenamehashlibsha1encode	hexdigestr5   r   osrenameOSError
write_textdumpsr   r   gatherrun)main_config_pathmain_configr8   bots_to_runr   
token_filetoken_type_overrider1   	token_dirr;   user_map_pathtoken_types_fileuser_maptoken_typesmap_updated
token_hash
hashed_dirbot_data_dircurrent_usernamesanitized_current_userstored_usernameold_dirnew_dirr.   r   s                            r/   mainru   q   s    M*""$;<<)),-11)R@K??68,DKx)*, __\26
)oolB?EEGZ(8(?(?(A$..0668E"o5;<O;PQR0
/0#4U#;;
Y&RSZL12""3UT#YS]#^_DE	()):JGH	(8,GH ?2#&88!,YK7MNOOOD4O8	9F9M9M9O

=2245UW 	<L<S<S<U

+5578[]   !2!2!45 J	cJ%%'((*002E,Z__,=SAB elln5??A#2FJ [([-D-W(4
9*FG#4U#;;
Y&?
?PP_`a%5$6a89J<zl)LML-.!J.J  ")7
|DE57)@
)S#S ';JOO;LO\]):;K)L&
#3"456"*,,z":":P'P&8G&)??G~~'3J<s?BSSYZpYqq}~3IIgw7+2L (/+AHZ("&K#+.D#DL*()?(@J<Wjk 0F,&*""3U\V`#abUJ	cX 01NNDN)$$TZZ%CD@AA	KK())>
?@
..<3779<
UPT
UUUy <4 ## 	H	 ## 	K	, <" $T(  ' 3!"?
|2aSPU V ,3L	3> =Us   D)W+U!,CW
5U$  5V  5CW VBWVBWV".-WBW:W
WWW$U=9W<U==W VWVWW"	W
+W?WW

	W__main__z
Shutting down.)N)__doc__r   rW   rP   r[   rG   pathlibr   typingr   r   r   utils.helpersr   r3   r0   r5   ru   r(   ra   KeyboardInterruptr$        r/   <module>r~      s    &    	     +43 43 4n( (# (RU (VUVp z"DF   " !"s   A' 'A76A7