
    Mg                         S SK r S SKJr  S SKrS SKrS SKrS SKrS SKJr  S SK	J	r	  \R                  " S5      rSr  " S S\	\5      rg)	    N)Fore)	print_say)CmdInterpreterzw+tz~>c                      \ rS rSrSr\\R                  S-   \R                  -   -  r\S-  r\\R                  S-   -  r\\R                  \R                  -   S-   \R                  -   -  r\S-  r\\R                  S-   \R                  -   -  r\S-  r\R                  SR                  \
5      -   \R                  -   r\\S	S
S/4S jrS rS rS rS rS rS rS rS rSrg)Jarvis!    z%Jarvis' sound is by default disabled.
z+In order to let Jarvis talk out loud type: zenable soundz,Type 'help' for a list of available actions.z{} Hi, what can I do for you?
Tzjarviscli/pluginscustomc                     U R                  U5      n[        R                  S:X  a  SU l        [        R
                  " S5      U l        [        R                  " XUXC5        g )Nwin32Fz\.(?!\w))	_rel_path_fixsysplatformuse_rawinputrecompile	regex_dotr   __init__)selffirst_reaction_textpromptfirst_reactiondirectoriess        4/Users/admin/workspace/ai/Jarvis/jarviscli/Jarvis.pyr   Jarvis.__init__5   sM     ((5<<7" %DL16 +	=    c                    / n[         R                  R                  [        5      n[         R                  R                  U5      n[        R
                  R                  R                  [         R                  R                  US5      5        U HI  nUR                  U5      (       d  [         R                  R                  X45      nUR                  U5        MK     U$ )Nzjarviscli/data/nltk)	ospathdirname__file__nltkdataappendjoin
startswith)r   dirsdirs_abswork_dir	directorys        r   r   Jarvis._rel_path_fix@   s    77??8,77??8, 			bggll85JKL I''11GGLL=	OOI&  r   c                 :    [        SU [        R                  5        g)z/Jarvis let's you know if an error has occurred.z$I could not identify your command...N)r   r   MAGENTA)r   r$   s     r   defaultJarvis.defaultP   s    8$Mr   c                 h   UR                  5       n[        R                  US-   5        U(       a6  US   R                  5       (       d	  US   S:X  a  SU-   nUR                  5       nUR	                  S5      (       a  U$ UR	                  S5      (       a  U$ U(       d  SnU$ U R                  U5      nU$ )z(Hook that executes before every command.r
   r   -z
calculate helpstatusNone)splitHISTORY_FILENAMEwriteisdigitr'   parse_input)r   linewordss      r   precmdJarvis.precmdT   s    

td{+ eAh&&((DGsN$&DJJLE??6""K??8$$KD  ##D)Dr   c                    U R                   (       aC  [        R                  SR                  [        5      -   [        R
                  -   U l        SU l         U R                  (       a  U R                  R                  S5        gg)z'Hook that executes after every command.z{} What can I do for you?
FzWhat can I do for you?
N)
r   r   r.   formatPROMPT_CHARRESETr   enable_voicespeechtext_to_speech)r   stopr;   s      r   postcmdJarvis.postcmdi   sd    /66{CD** K #(DKK&&'AB r   c                 ^    U R                   (       a  U R                  R                  U5        g g N)rC   rD   rE   )r   texts     r   speakJarvis.speakt   s"    KK&&t, r   c                    UR                  5       nSU;  aR  UR                  SS5      nUR                  SS5      nUR                  SS5      nU R                  R                  SU5      nXR                  ;   a  U R                  U   nU$ U R                  XR                  R                  5       R                  5       5      nU$ )z5This method gets the data and assigns it to an actionsay?r	   !,)	lowerreplacer   subfixed_responsesfind_action_plugin_managerget_pluginskeys)r   r$   outputs      r   r:   Jarvis.parse_inputx   s    zz|<<R(D<<R(D<<R(D >>%%b$/D '''))$/F  %%**668==?AFr   c                    SnU(       d  U$ SnUR                  5       n[        U5      nUR                  S SS9  U H  nUR                  5       nU Hn  nUR                  U5        US:X  a4  USUR	                  S5       n	US-   SR                  U	S	/-   U-   5      -   nMN  X:X  d  MU  SnUS-   SR                  U5      -   n  O   U(       d  M    U$    U$ )
z@Checks if input is a defined action.
:return: returns the actionr5   Fc                     [        U 5      $ rJ   )len)ls    r   <lambda>$Jarvis.find_action.<locals>.<lambda>   s    3q6r   T)keyreversenearN |)r6   listsortremoveindexr&   )
r   r$   actionsr[   action_foundr<   actionwords_remainingwordinitial_wordss
             r   rW   Jarvis.find_action   s     M

w-
 	)48 F"jjlO&&t,6>$)*>5;;v+>$?M!CZ#!6!HIJF^#'L!CZ#((?*CCF  |  r   c                 V    U(       a  U R                  U5        gU R                  5         g)aX  
If command is not empty, we execute it and terminate.
Else, this method opens a terminal session with the user.
We can say that it is the core function of this whole class
and it joins all the function above to work together like a
clockwork. (Terminates when the user send the "exit", "quit"
or "goodbye command")
:return: Nothing to return.
N)execute_oncecmdloop)r   commands     r   executorJarvis.executor   s     g&LLNr   )r   r   r   r   N)__name__
__module____qualname____firstlineno__r   r   CYANrB   r.   r@   rA   r   r   r   r/   r=   rG   rL   r:   rW   rw   __static_attributes__ r   r   r   r   !   s     4990137::> >4499'TTT4::4~E

RR4499679=D D4
+
2
2;
?	@
**	  ,?t18<	= N*	C-, Dr   r   )r   coloramar   r#   r   r   tempfileutilities.GeneralUtilitiesr   r   TemporaryFiler7   rA   objectr   r   r   r   <module>r      sN    
   	 
  0 ) ))%0  \^V \r   