mς
{X&Gc           @   sΉ   d  k  Z  d  k Z d  k Z d  k Z d  k Z d d d d d g Z d e i   Z d  d  d  d  Z	 d   Z
 d	   Z d
   Z d   Z d  d  Z d   Z e d j o e   n d  S(   Nt   helpt   addhelpt   delhelpt   pophelpt   listhelps   %s/helpfile.pckc         C   sα   t  i d  } t  i d |  } t i | | |   } |  d j o t
   } n{ |  d j o t | |  } n[ |  d j o t | |  } n; |  d j o t |  } n |  d j o t |  } n t i | | |  d  S(   Nt   commonR   R   R   R   R    (   t   impt   find_modulet   module_locationt   load_modulet   moduleR   t   NormalizeMessaget   msgt   irct   keywordt   ListHelpt   resultt   AddHelpt   DelHelpt   PopHelpt	   ServeHelpt   DeliverMessaget   channel(   R   R   R   R   R   R
   R   (    (    t>   /home/avleen/devel/python/googlebot2/modules/googlebot_help.pyt   Gather   s    c          C   sα   y t  t d  }  WnT t j
 oH d g } t  t d  }  t i | |   |  i   t  t d  }  n Xy t i |   } |  i   Wn t	 j
 o d g } n Xd t
 |  } | g } x | D] } | i |  qΖ W| S(   sd   List help in the database
  
  Args:
    None
    
  Returns:
    helplist: ('help', 'help', ...)
  t   rs   No help for you!t   ws   %s help in the database:N(   t   opent   HELPFILEt
   helppicklet   IOErrort   helplistt   picklet   dumpt   closet   loadt   EOFErrort   lent   helpcountmsgR   R    t   append(   R   R    R   R&   R   (    (    R   R      s(     	
	 c         C   s  t  |   d j o d } | Sn y t t d  } WnT t j
 oH d g } t t d  } t i	 | |  | i
   t t d  } n Xy t i |  } | i
   Wn t j
 o d g } n X| i |   t t d  } t i	 | |  | i
   d |  } | S(   s   Add help to the database
  
  Args:
    irc: IRCClient object
    msg: string

  Returns:
    str: Success or failure message
  i   s-   Hmmm that help name is rather long, isn't it?R   s   No help for you!R   s   Added "%s" to the databaseN(   R%   t   newhelpR   R   R   R   R   R   R    R!   R"   R#   R$   R'   (   R(   R   R   R   (    (    R   R   9   s.    	 	


c          C   sδ   y t  t d  }  Wn0 t j
 o$ d t } t i | t t  n Xy t	 i
 |   } |  i   Wn! t j
 o d t } | Sn Xy= | i   t  t d  }  t	 i | |   |  i   d } Wn t j
 o d } n X| S(   s   Pop the database, to remove the latest entry
  
  Args:
    irc: IRCClient object
    channel: string
    
  Returns:
    str: Success or failure message
  R   s+   Help file %s does not exist in this realitys   Help file %s is emptyR   s   Popped the databases   Unable to pop empty databaseN(   R   R   R   R   R   R   R   R   R   R    R#   R   R"   R$   R   t   popR!   t
   IndexError(   R   R   R   R   (    (    R   R   [   s*    	 

	


c         C   sΰ   y t  t d  } Wn! t j
 o d t } | Sn Xy t i |  } | i   Wn! t	 j
 o d t } | Sn Xy | i
 t  d t } Wn t j
 o d t } n Xt  t d  } t i | |  | i   | S(   s   Remove help from the database

  Args:
    irc: IRCClient object
    channel: string
    msg: string

  Returns:
    str: Success or failure message
  R   s+   Help file %s does not exist in this realitys   Help file %s is emptys   Removed %s from the databases   %s is not in the databaseR   N(   R   R   R   R   R   R    R#   R   R"   R$   t   removet   oldhelpR    t
   ValueErrorR!   (   R   R   R   R   (    (    R   R   {   s*    
 
	
	
c         C   s   |  p
 d }  n d |  }  yD t t d  } t i |  } | i   d k } | i	 |  } Wn t j
 o d } n Xd |  | f } | S(   sn   Serve the help!

  Args:
    irc: IRCClient object
    channel: string
    msg: string

  Returns:
    None
  t    s   %s: R   NsA   I'm not very helpful :( Show me how to help you: "addhelp <help>"s   %s%s(   R   R   R   R   R    R#   R   R"   t   randomt   choicet   helpfulR   R   (   R   R   R1   R   R/   R   (    (    R   R      s    
 


	c          C   s   y t  i d }  Wn  t j
 o t  i d  n Xy t  i d } Wn t j
 o d  } n X|  t j o t |  |  } n d  S(   Ni   i   (
   t   syst   argvR   R*   t   exitt   argumentt   Nonet   module_triggersR   R   (   R   R5   R   (    (    R   t   main·   s    t   __main__(   R   R   R    t   osR2   R7   t   getcwdR   R6   R   R   R   R   R   R   R8   t   __name__(   R   R   R   R   R    R   R   R2   R   R   R   R8   R:   R7   (    (    R   t   ?   s   							"	 	!	
