
Tc           @  s  d  d l  m Z d  d l  m Z d GHd GHd  d l Z d  d l Z d  d l Z d  d l m Z d Z d e GHd  d	 l	 m	 Z	 m
 Z
 d  d
 l m Z d  d l m Z m Z d  d l m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d   Z  d   Z! d e" f d     YZ# d   Z$ d   Z% e& e& d  Z' e& d  Z( d   Z) d   Z* d   Z+ d   Z, d   Z- d   Z. e& d d  Z/ e& e& e& d e& e& e& e& e& e& e& e& d  Z0 d   Z1 d    Z2 e& d!  Z3 d" e j4 f d#     YZ5 d$   Z6 d%   Z7 d& e f d'     YZ8 d( e e f d)     YZ9 d* e f d+     YZ: d, f  d-     YZ; e< d. k re    n  d S(/   i(   t   with_statement(   t   divisions   Starting main program.sF   pyWHATauto: johnnyfive + blubba. WHATauto original creator: mlapaglia.N(   t   torrentparsers   v1.74s&   You are running pyWHATauto version %s
(   t   datetimet	   timedelta(   t   Thread(   t   BaseHTTPRequestHandlert
   HTTPServer(   t   ThreadingMixInc          C  sW  t  a t  a t  a t j t j  t   t j	 r{ t j
 j t j
 j t j d   s{ t j t j
 j t j d   q{ n  t  a t j d k r y d d  l }  |  r n  t a Wq t k
 r t d d  t d d  t  a q Xn  t d d  t j t d  t d d
  t d d  t j t j t j  } | j t  | j   t d d  t d d  yd t t j t j d d  t j d d  t j d d   } | j t  | j   t d d  Wn t k
 rt  d  n XyC t! j"   a# t d d  t j$ rt%   n t j t% t&    Wn t k
 rHt  d  n Xt' d  d  S(   Nt   logst   ntit   ERRORsm   The module win32file is not installed. Please download it from http://sourceforge.net/projects/pywin32/files/sP   The program will continue to function normally except where win32file is needed.t   DEBUGs   Starting report thread.i   s   Report thread started.s   Starting DB thread.s   DB thread started.s   Starting web thread.t   setupt   passwordt   portt   webserverips   Web thread started.s3   Exception caught in main(), when starting webservert   INFOs#   Main program loaded. Starting bots.s   General exception in main():g      ?(   i   ((   t   Falset   lastt   lastFSCheckt   logt   ost   chdirt   Gt	   SCRIPTDIRt   loadConfigst   LOGt   patht   isdirt   joint   makedirst
   WIN32FILEEt   namet	   win32filet   Truet   ImportErrort   outt   threadt   start_new_threadt   writeReportt   dbt   sqlDBt   Qt	   setDaemont   startt	   WebServert   SETUPt   gett	   Exceptiont   outexceptiont   irclibt   IRCt   irct   TESTINGt	   startBotst   tuplet   Prompt(   R"   t   DBt   WEB(    (    s   WHATauto.pyt   main   sX    	$%

<
	
c         C  sU   xN t  j |   t j r d GHt j r> t j   t j   n  t j	 d  q q d  S(   Ns   Exiting.i   (
   t   timet   sleepR   t   EXITR   R   t   closet   log2t   syst   exit(   t   n(    (    s   WHATauto.pyR9   T   s    		
t   DuplicateErrorc           B  s   e  Z d    Z d   Z RS(   c         C  s   | |  _  d  S(   N(   t   value(   t   selfRF   (    (    s   WHATauto.pyt   __init__`   s    c         C  s   t  |  j  S(   N(   t   reprRF   (   RG   (    (    s   WHATauto.pyt   __str__b   s    (   t   __name__t
   __module__RH   RJ   (    (    (    s   WHATauto.pyRE   _   s   	c          C  s
  t  j d k rt  j j t  j j t j d   rd GHt j   a	 t	 j
 t t  j j t j d d    t j   }  |  j
 t t  j j t j d d    t j   } | j
 t t  j j t j d d    t j   } | j
 t t  j j t j d d    nt j   a	 t	 j
 t t  j j t j d    t j   }  |  j
 t t  j j t j d    t j   } | j
 t t  j j t j d    t j   } y) | j
 t t  j j t j d    Wn8 t j k
 r} t d d |  t d	  t   n Xt j   } | j
 t t  j j t j d
    t j   } | j
 t t  j j t j d    t	 j d d  rt	 j d d  j   j   d k rt t _ qn  t	 j d d  rt	 j d d  j   j   d k rt t _ qn  xj | j   D]\ } t   t j | <t | j | d   t j | d <t | j | d   t j | d <qWt   t _ t   t _ x=|  j   D]/} y|| j d |  r8| j d |  t j j   k rt d | j d |  t j | j d |  | f   n  | t j | j d |  <| j d |  t j | <n t	 j d |  rt	 j d |  t j j   k rt d t	 j d |  t j t	 j d |  | f   n  | t j t	 j d |  <t	 j d |  t j | <n | t j | <| t j j   k r| t j | <n  WnA t k
 rQ} t r6t d |  n | GHt t _  t! j"   n X| j d |  r| j d |  t j# | <qt	 j d |  rt	 j d |  t j# | <qd t j# | <qWd t _$ d } xD t j j%   D]3 }	 t& |	  t j$ k rt& |	  t _$ |	 } qqWt rBt d d | t j | t j$ f  n d | t j | t j$ f GH| j d d  rt | j d d   t _' n  t   t _( xn|  j   D]`} t j j) |  st   t j | <d t j | d <d t j | d <n  t   t j( | <t   t j( | d <x2 |  j* |  D]! \ }
 } | t j( | d |
 <q(Wt   t j( | d <| j+ |  rx5 | j* |  D]! \ }
 } | t j( | d |
 <qWn  | j+ |  rx5 | j* |  D]! \ }
 } | t j( | d |
 <qWn  t   t j( | d <x2 t	 j* d  D]! \ }
 } | t j( | d |
 <qWt   t j( | d <x2 t	 j* d  D]! \ }
 } | t j( | d |
 <q\Wt   t j( | d  <x2 t j j,   D]! \ }
 } | t j( | d  |
 <qWt   t j( | d! <x2 t j j,   D]! \ }
 } | t j( | d! |
 <qWt   t j( | d" <x | j   D] } | j | d#  | k r4	t   t j( | d" | <x6 | j* |  D]% \ }
 } | t j( | d" | |
 <qz	W| j | d$  t j- | j.   <| j.   t j/ k r
t j/ | j.   t j( | d" | d$ <q
q4	q4	WqWd  S(%   NR
   s   Loading nt settingss
   setup.confs   credentials.confs   custom.confs   filters.confR   s~   There is a problem with your filters.conf. If using newlines, please make sure that each new line is tabbed in once. Error: %ss#   This program will now exit (okay): s   reports.confs
   regex.conft   debugt   testingt   1R   R   t   seent
   downloadedt   aliasess0   The alias %s is defined for two sites, %s and %st   sitest   0i    t    R   s'   Longest alias is %s (%s) with length %dt   versiont   credst   regext   notift   notificationt	   fromaliast   toaliast   filterst   sitet   active(0   R   R!   R   t   existsR   R   R   t   ConfigParsert   RawConfigParserR/   t   readfpt   opent   ParsingErrorR%   t	   raw_inputt   quitt
   has_optionR0   t   rstript   lstripR#   R6   R   t   sectionst   dictt   REPORTSt   intt	   FROMALIASt   TOALIASt   keysRE   R   R?   RB   RC   t   TOSTARTt   ALIASLENGTHt
   itervaluest   lent
   REGVERSIONt   NETWORKSt   has_keyt   itemst   has_sectiont	   iteritemst   FILTERSt   lowert   FILTERS_CHANGED(   t   CREDt   CUSTOMR|   t   et   REPORTt   REGEXR^   t   configst   longestt   valt   keyRF   t   f(    (    s   WHATauto.pyR   e   s    3(((+%%%)
%%$$#'!;!;		'c          C  sf   t  j j   t   x1 t  j j   D]  }  |  j t  j |  j    q$ Wt  j j	   t
 d d  d  S(   NR   s   Configs re-loaded.(   R   t   LOCKt   acquireR   t   RUNNINGRt   t   saveNewConfigsRw   t
   getBotNamet   releaseR%   (   t   bot(    (    s   WHATauto.pyt   reloadConfigs	  s    c         C  sP   t  j   } |  r% t d |  |  n  x$ | j   D] } t d | |  q2 Wd  S(   NR   (   t	   tracebackt
   format_excR%   t
   splitlines(   t   msgR^   t   exct   excline(    (    s   WHATauto.pyR2     s
    c         C  s`  d d d d d d d g } i d d 6d d 6d d 6d d 6d d 6d d 6d d 6} | j  |  j    | j  t j d	 d
  j    k r\| r| t k r t t k r t j r t d  q n  d t	 j
   j d  d |  t j t j | | f } | |  j   | GH| a n3 d t	 j
   j d  d |  t j d | f } | GHt j r\t |  q\n  d  S(   Nt   errort   warningR   t   infot   cmdt   filterRM   s   %sR   t	   verbosityRU   s   %s %-*s %-*s %ss   %m/%d-%H:%M:%Si   (   t   indexR}   R/   R0   R   R   R   R   t   loggingR   t   nowt   strftimeRs   Rp   (   t   levelR   R^   t   levelst   colors(    (    s   WHATauto.pyR%     s    76	5	.	c         C  s'  t  j j t j d  } t sz t j   j d  a	 t
 t  j j | d t	 d  d  a t
 t  j j | d  d  a n  t j   t j t	 d  t d d  k r t j   t j   j d  a	 t
 t  j j | d t	 d  d  a n  t j |  d	  t j   t j |  d	  t j   d  S(
   NR	   s   %m.%d.%Y-%H.%Ms   pyWALog-s   .txtt   ws   pyWALog.txtt   hoursi   s   
(   R   R   R   R   R   R   R   R   R   t   logdateRd   RA   t   strptimeR   R@   t   writet   flush(   R   t   logdir(    (    s   WHATauto.pyR   -  s    &!+
)
c          C  sr   yG x6 t  j j   D]% \ }  } | d k r t |   q q Wt j   Wn$ t k
 rm t d  t t  _	 n Xd  S(   NRO   s%   General exception caught, startBots()(
   R   Rr   Ry   t   establishBotR5   t   process_foreverR1   R2   R#   R?   (   R   RF   (    (    s   WHATauto.pyR7   ?  s    
c         C  s  |  t  j j   k r& t d d  d St  j |  d } d | k o | d d k o d | k o | d d k o d | k o | d d k s t d d d	 |  d
 St  j |  d } d | k o | d d k o d | k o d | k o | d d k st d d d	 |  d St } d | k r-| d } n
 | d } d | k rP| d } n d } xt  j j   D] } t  j | d } t  j | d } | d j   | d j   k rft d d |  | | d f d	 |  d | k r| d }	 n
 | d }	 d | k r| d }
 n d }
 | j   |	 j   k rX| |
 k rXt d d d	 |  | } PqXqfqfWt  j j	   t
 |  t  j |   t  j |  <t  j j   | rt  j |  j t  j |  d |  | f St  j |  j   d |  Sd S(   sS   Does some preliminary checks, creates a new autoBOT instance and connects it to ircR   s,   The autoBOT for this site is already runningRX   t   serverRU   R   t   announcechannels0   This site does not have an irc announce channel.R^   sO   Cannot connect to irc network: this site does not have an irc announce channel.RW   t   botnickt	   nickownert   nickservpassR   sE   The credentials given are not sufficient to connect to the irc serversL   ERROR: The credentials given are not sufficient to connect to the irc servert   tempbotnickt   ircpasswordR   s2   Matching servers found between %s and %s (old), %ss<   servers and nicks are matching the full way! Piggybacking...s3   Connecting to %s by piggybacking on %s's connections   Connecting to %sN(   R   R   Rq   R%   Rw   R   t   NoneR}   R   R   t   autoBOTR   t   setSharedConnectiont   connect(   t   sitenamet   ret   crt   sharedR   t   ircpwR   t   sret   scrt   sbotnickt   sircpw(    (    s   WHATauto.pyR   I  sR    TD
 $
$c         C  sN  d } xAd } t  j j   x+ t  j j   D] } | t | d  7} q, W| | k r-t j   } xf t t  j j	    D]O } | j
 |  | j | d t  j | d  | j | d t  j | d  qx Wt  j j   y/ t d d   } | j |  Wd  QX| } Wq:t k
 r)} t d |  q:Xn t  j j   t j |   q	 d  S(   Ni    RP   RQ   s   reports.conft   wbR   (   R   R   R   Rm   Rt   Rn   Ra   Rb   t   sortedt   iterkeyst   add_sectiont   setR   Rd   R   t   IOErrorR%   R=   R>   (   RD   R   R   R   t   configt   sectiont
   configfileR   (    (    s   WHATauto.pyR(     s*    "
c         C  s  t  j d k rM t rM d  d  } | |   \ } } | t |  t |  f St  j d k rt j d d  rpt j d d  j   j	   d k rpt j d d  j   j	   d k rpd d  l
 } d d  l } | j d	 |   } | j | d
 | j } | j   d } t j d |  }	 t |	 j d   d }
 t t j d d   |
 } | | t t j d d   f St d d  d Sn d Sd  S(   NR
   c         S  sc   |  j  d d  }  d d l } | j |  d  \ } } } } | | | } | | | } | | f S(   sJ   
            returns total_space, free_space and drive letter
            s   :\RU   iN(   t   replaceR"   t   GetDiskFreeSpace(   t   driveR"   t   sectPerClustert   bytesPerSectort   freeClusterst   totalClusterst   total_spacet
   free_space(    (    s   WHATauto.pyt   get_drivestats  s    t   posixR   t   limitRU   RT   is   du -s --bytes %st   stdouti    s   (\d+).*i   i   R   s!   Unknown filesystem as it seems...g      ?i   i   @(   g      ?g      ?(   g      ?g      ?(   R   R!   R    R   t   floatR/   Rh   R0   Rj   Ri   t
   subprocesst   shlext   splitt   Popent   PIPEt   communicateR   t   searcht   groupR%   (   R   R   R   R   R   R   t   argst   dut   dureturnt   mt   usedt   free(    (    s   WHATauto.pyt   getDriveInfo  s"    
Z c          C  s   t  j d d  }  t  j d d  } t t k r? t j   a nc t j   t t d d  k r t |   \ } } t d d t	 |   | | k r t
 St Sn t
 Sd  S(   NR   R   t   freepercentt   secondsi  R   s   Free HD space: %s(   R/   R0   R   R   R   R   R   R   R%   t   strR#   (   R   R   R   t   percent(    (    s   WHATauto.pyt   freeSpaceOK  s    RU   c   
      C  s5  t  j j   d t  j | d k r< t  j | d d } n% t d d | |  t  j j   d S| d k rt j j t j j	 t  j
 d | d   st  j j   d t  j | d k r t  j | d d d	 k r t d d
 |  d St | |  } | sd SqHyC | j t j j	 t  j
 d | d  d t d t t  j j   WqHt j k
 rd t  j | d k rt  j | d d d	 k rt d d | |  t  j j   d St  j j   t | |  } | sd SqHXng t  j j   d t  j | d k s7d t  j | d k rHt  j | d d d k rHt d d  d S| d	 k rpt  j | d d |  } n| d k rt  j | d d d |  d |  d } n | d k rt  j | d d d |  d t  j | d d } n | d k r.t  j | d d |  t  j | d d |  d } nO | d k r}t  j | d d d |  d t  j | d d d | d } n  t j d  d$ } y t | |  } Wn t j k
 r,}	 t |	 j  d% k rd  |	 j |	 j |	 j j |	 j j   f GHd! Sd" |	 j |	 j |	 j j |	 j j   f GHd# Sn X| Sd$ S(&   s  download using login/cookie technique.
    Returns 'preset' if a presetcookie is missing or malformatted,
    Returns 'password' if the password seems to be wrong
    Returns 'moved' if the download of the torrent file retrieves a redirect
    Returns 'httperror' for any httperror encountered
    Returns 'downloadtype' if the downloadtype is not set in regex.conf
    Returns 'passkey' if the passkey is not set in credentials.conf
    Returns an urllib2.urlopen object if a 200/ok was received.
    t   downloadtypeRX   R   s-   Download type is not set in regex.conf for %st   5t   cookiess   .cookiet   presetcookieRO   sS   This tracker requires you to manually create a cookie file before you can download.t   presetR   t   ignore_discardt   ignore_expiress%   The cookie for %s is the wrong formatt   passkeyRW   RU   s<   This site requires the passkey to be set in credentials.conft   downloadurlt   2t   /s   .torrentt   3t	   urlendingt   4i   i-  i.  i/  i3  s<   Caught a redirect. Code: %s, url: %s, headers %s, others: %st   movedsD   Caught another http error. Code: %s, url: %s, headers %s, others: %st	   httperrorN(   i-  i.  i/  i3  (   R   R   R   Rw   R%   R   R   R   t   isfileR   R   t   createCookiet   loadR#   t	   cookielibt	   LoadErrort   sockett   setdefaulttimeoutR   t   getFilet   urllib2t	   HTTPErrorRn   t   codet   urlt   headersRl   t   __dict__Rq   (
   t
   downloadIDR^   t   cjt   targett   networkR!   t   downloadTypet   downloadURLt   handleR   (    (    s   WHATauto.pyt   dlCookie  sh    +222I,77C**i    c          C  s	  t  d d |  | | | | | | | |	 | f
  t } d } t j j   | s t j d d  } d t j | d k r t j | d d d k r t j | d d } q n  dP } | d k r!| r!| r!t j	 d d	  r!t j d d	  j
   j   d k r!t t j d d	   } q!n  d
 t j | d k rt j | d d
 d k rd t j | d k rt j | d d d k r| s|	 rt j t j | d d |	  j d  } qd } qqd } n  t j j   t } d } | s| rt j |  n  | d k rB| r2| r2t j d  qBt j d  n  t j   } t |  | | | | |  } t t |   d k r| j   } qn  t } | r| j d k r&t j j   d t j | d k r t j | d d d k r d |  | f } n d |  | f } t j j   t } q| j d k r| j   } y1 t d t d |  } | j   } | j   } Wn6 t k
 r} t  d d | d | dP } dP } n X| s4| r| } q:d | k rxI t j D]; } | | d k r| d j  | d  j  d  d  } qqWn  | d k r:|  d! } q:n | } d! | k rS| d! 7} n  t! j" |  } t } | r| pw| r| j# d"  } | rt j j   t$ |  d k r| t% | d  k st$ |  d# k r| t% | d  k rt  d$ d% |  | f |  t } ne t$ |  d# k r[| t% | d  k  r[t } t  d$ d& |  | f |  n t  d$ d' |  | f |  t j j   qn= | p| st j j   t  d$ d( |  |  t j j   n  | rt j j   y9 t& t' j( j) | |  d)  } | j* |  | j+   Wn1 t, k
 rDt  d d* |  |  d+ } t } n Xd, t t' j( j- t' j( j) | |    k rd- } t } nD t } | rd. t |   | | | f } n d/ t |   | | f } t j j   qd0 } qt  d d1 | j |  t } n | r| } n | d2 k r&d3 | } n | d4 k r?d5 | } np | d6 k rjd7 t |   | f } t } nE | d8 k rd9 } t } n* | d
 k rd: } n | d; k rd< } n  | r| d k rt j j   d t j | d k sd t j | d k rt j | d d d k rt' j( j. t' j( j) t j/ d= | d>   rlt' j0 t' j( j) t j/ d= | d>   qt  d d? |  n  t  d$ d@ |  | f |  t j j   t1 |  | dA | dB | dC | dD | d dE | dF | dG | dH |	 dI |
 dJ | dK | dL | S| r	t j j   t  d$ dM | | f |  | rH	t2 | |	 | |  n  | rd	t3 | |	 | |  n  | r}	| j4 | |  n  t j j   t | f St j j   t  d dN |  | f |  | r	| j4 dO | |  | f |  n  t j j   t | f SdP S(Q   s   Take an announce download ID and the site to download from, do some magical stuff with cookies, and download the torrent into the watch folder
    Returns a tuplet with (True/False, statusmsg)R   s}   Downloading ID: %s, site: %s, filter: %s, location: %s, network: %s, target: %s, retries: %s, email: %s, announce %s, name %sRU   R   t
   torrentdirt   watchRW   i    t   delayR   RX   R   t
   nameregexpi   s\   The download function for this site can only be used for the button and automatic downloads.sE   This site requires the variable 'nameregexp' to be set in regex.conf.i   g      ?s   <type 'instance'>s	   text/htmlR   RO   sq   There was an error downloading torrent %s from %s. Either it was deleted, or the cookie you entered is incorrect.sw   There was an error downloading torrent %s from %s. Either it was deleted, or the credentials you entered are incorrect.s   application/x-bittorrentRM   t   contentR   sR   The torrentparser was unable to parse the torrent file. Please let blubba know: %sR^   s   Content-Dispositiont   "s   .torrentt   ,i   R   s4   (%s) Torrent is larger than required by filter '%s'.s.   (%s) Torrent is smaller than required by '%s'.s:   (%s) Torrent is within size range required by filter '%s'.s   (%s) No Size check.R   s=   (%s) !! Disk quota exceeded. Not enough room for the torrent!sQ   Can't write the torrent file on the disk, as there is not enough free space left!id   s   The size of the torrent is too small. Maybe try a different torrent of this tracker to see if this is a local or global occurance.sQ   Torrent (id: %s) successfully downloaded! Size %.2f MB, retries: %d, filename: %ssC   Torrent (id: %s) successfully downloaded! Retries: %d, filename: %ss(   The torrent size did not fit the filter.s   unknown filetype received: %sR   s   This site requires a cookie to be preset, called '%s.torrent' in the folder 'cookies'. Either this cookie is missing or malformatted.R   sN   The login credentials set in credentials.conf for %s are incorrect or missing.R   sY   Either the torrent id (%s) does not exist or your credentials for %s are wrong or missingR   sw   An http error occured. Please check if the site is online, and check the log for more details if this problem persists.s9   The key 'downloadType' is not set in regex.conf. AbortingR   sZ   This site requires the passkey to be set in credentials.conf. Please set it and try again.R   s   .cookies=   The cookie file doesn't exist here... this should not happen!sX   (%s) !! Torrent file is not ready to be downloaded. Trying again in a moment. Reason: %st   locationR  R  t   retriest   emailt   notifyt
   filterNamet   announcet	   formLogint
   sizeLimitsR!   t   fromwebs   %s to %ss   Download error (%s): %ss   Download error (%s:%s): %sN(5   R%   R   R   R   R   R/   R0   Rw   R   Rh   Rj   Ri   Rn   R   t   matchR   R   R=   R>   R   t   LWPCookieJarR  R   t   typeR   R#   t   readR   t   mbsizeR!   t   SyntaxErrort   CDR   t   urllibt   unquoteR   Ru   R   Rd   R   R   R   R   R@   R   t   getsizeR   R   t   removet   downloadt	   sendEmailt
   sendNotifyt   sendMsg(    R
  R^   R  R  R  R  R  R  R  R  R  R   R!   R!  t   successR   t   sleepit	   file_infot	   retreivedR  t   retryt	   statusmsgR   t   tpR&  t   tpnameR   t   filenamet   cdt   sizeOKt	   sizeranget
   local_file(    (    s   WHATauto.pyR-  "  s"   /2622-	 2	
	, P	(
-								J+)Y
 c         C  sx   t  j d d  j   d k r3 t | d d } n t |  } t j |  t j |   } | j d d  t j |  S(   NR   R   RM   i   s
   User-Agentt   pywa(	   R/   R0   R}   t   build_openerR  t   install_openert   Requestt
   add_headert   urlopen(   R  R  t   openert   req(    (    s   WHATauto.pyR    s    c         C  s2  t  j } t  j } t j d d  j   d k rE t | d d } n t |  } t  j |  t j	 |  d d t j	 |  d k r t j	 |  d d d k r t j	 |  d d } n d } d	 t j	 |  d k rt j	 |  d d	 d k rt j	 |  d d	 } n d
 } i t j	 |  d d | 6t j	 |  d d
 | 6} d t j	 |  d k rt j	 |  d d d k ry' t
 d t j	 |  d d d  } Wn7 t k
 rt d d t j	 |  d d d |  n X| j |  n  |  d k r
t j	 |  d d | d <n  t j |  }	 | t j	 |  d d |	  }
 |
 j d d  |  d k rf|
 j d d  n  t d d |  d |  d  } y | |
  } Wn t  j k
 r"} d | j | j | j j | j j   f GHt j j   | j t j j t j d |  d  d t  d  t  t j j!   | SX| rd! t j	 |  d k rt j	 |  d d! d" k rt j j   | j t j j t j d |  d  d t  d  t  t j j!   | S| rd# t j	 |  d k rt j	 |  d d# d" k rd$ d  l" } y | j# | j$    } Wn" t% k
 r,t d d% |   d  SXd& | k r| d& d' k rd( | k rzt d d) | d& | d( f |   qt d d* | d& |   q.d& | k r.| d& d+ k r.t j j   | j t j j t j d d, |   d t  d  t  t j j!   | Sn* | rt d d- |   t& St d d. |   d  S(/   NR   R   RM   i   RX   t   loginuserpostRU   t   usernamet   loginpasswordpostR   RW   t   morepostdatat   {t   }R   s.   morepostdata variable raised a syntax error %sR^   t   passthepopcornR   t   loginurls
   User-AgentR>  t   whatcdt   Referers   https://what.cd/login.phpR   sI   Logging into %s because a cookie was not previously saved or is outdated.s<   Caught a redirect. Code: %s, url: %s, headers %s, others: %sR   s   .cookieR   R   t   login200RO   t	   loginjsonis&   Invalid JSON returned on login attemptt   Resultt   Errort   Messages   Result: %s, Message: %ss   Result: %s t   Oks	   %s.cookies   Password seems to be incorrects=   We don't have a redirect but still data? How can that happen?('   R  RC  RA  R/   R0   R}   R?  R@  R   Rw   t   evalR'  R%   t   updateR)  t	   urlencodeRB  R   R  R  R  R  Rl   R	  Rq   R   R   t   saveR   R   R   R   R#   R   t   jsont   loadsR%  t
   ValueErrorR   (   R^   R  RC  RA  RD  t   userpostt   passpostt   httpdictt   newdictt	   http_argsRE  R  R   RZ  t   result(    (    s   WHATauto.pyR     s|    		2222'**2828%2c         C  s[   t  j d |  } t  j d |  } t  j |   } t  j | | | t    } |  | _ | S(   Nt
   debuglevel(   R  t   HTTPHandlert   HTTPSHandlert   HTTPCookieProcessorR?  t   smartredirecthandlert
   cookie_jar(   R  RM   t   http_handlert   https_handlert   cookie_handlerRD  (    (    s   WHATauto.pyR?  F  s    	Rg  c           B  s   e  Z d    Z RS(   c         C  s   t  d d | | | f  d  S(   NR   s$   Redirect received. stuff: %s, %s, %s(   R%   R   (   RG   RE  t   fpR  R   t   hdrst   newurl(    (    s   WHATauto.pyt   redirect_requestT  s    (   RK   RL   Ro  (    (    (    s   WHATauto.pyRg  R  s   c   
      C  s  d d  l  } d d l m } | d i | d 6| d 6|  d 6| d 6 } t j d d	  } d
 |  | d <| j d d  } | j   | j   | j   yT t d d |  | j	 | t j d d   | j
 | | | j    | j   Wn' t k
 r}	 t d d |	 j  n Xd  S(   Ni(   t   MIMETexts   pyWA has detected a new download.

Site: %(site)s
Captured Announce: %(announce)s
Matched Filter: %(filter)s
Saved Torrent: %(filename)sR9  R   R^   R  RZ   t   gmails   pyWA: New %s download!t   Subjects   smtp.gmail.comiK  R   s    Emailing %s with a notification.R   R   s&   Could not send notify email. Error: %s(   t   smtplibt   email.mime.textRp  R/   R0   t   SMTPt   ehlot   starttlsR%   t   logint   sendmailt	   as_stringRg   R1   t
   smtp_error(
   R^   R  R   R9  Rs  Rp  R   Rq  t   sR   (    (    s   WHATauto.pyR.  X  s     ,


c         C  s   t  } x t j j   D] } | j   t j d d  k r t d d t j d d   | j d i |  d 6| d 6| d	 6t j d d   t	 } q q W| s t d
 d t j d d   n  d  S(   NRZ   R   R   s&   Messaging %s with an IRC notification.t   nicks;   New DL! Site: %(site)s, Filter: %(filter)s, File: %(file)s R^   R   t   fileR   sN   Could not send notification via %s, because I am not connected to that network(
   R   R   R   Rt   R   R/   R0   R%   R0  R#   (   R^   R  R   R9  t   sentt   net(    (    s   WHATauto.pyR/  s  s    5R.   c           B  s   e  Z d  d  Z d   Z RS(   RU   c         C  s   t  j |   | |  _ | |  _ y t |  |  _ Wn* t k
 r^ t d d  t d   n X| d k rt | a	 n) t
 t j d
 d   a	 t d d	 t	  d  S(   Nt   WARNINGs-   Bad webserver port, could not start webservers   Could not start webserverRU   i
   i   i	   R   s5   No webserver password set. Assigning a random one: %si i ʚ;(   R   RH   t   loadloct   ipRn   R   R\  R%   R1   t   webpassR   t   randomt   randint(   RG   R  t   pwR   R  (    (    s   WHATauto.pyRH     s    			c         C  sg   t  j t j j |  j d   a t j   a t	 |  j
 t |  j  f t  |  _ d GH|  j j   d  S(   Ns
   example.dbs   started httpserver...(   t   sqlite3R   R   R   R   R  t   CONNt   cursort   Ct   ThreadedHTTPServerR  Rn   R   t	   MyHandlerR   t   serve_forever(   RG   (    (    s   WHATauto.pyt   run  s
    !$(   RK   RL   RH   R  (    (    (    s   WHATauto.pyR.   ~  s   R  c           B  s   e  Z d  Z RS(   s   Handles requests in threads(   RK   RL   t   __doc__(    (    (    s   WHATauto.pyR    s   R  c           B  s   e  Z d    Z RS(   c      	   C  s  t  } yn|  j j d  d j   j d  rf|  j j d  rV|  j j d  } t |  d k r | d j d  } t   } xD | D]< } | j d  } t |  d k r | d | | d <q q W| GHn t } | sd | k r| d t	 k rd	 | k rp| d	 d
 k rp| d	 } d | k r| d j   t
 j k rt
 j | d j   } t d d | d	 |  j d f |  d | k r| d } n d  } y d t
 j | d k rt
 j | d d }	 nE t j d d  rt j d d  d
 k rt j d d  }	 n d  }	 t | | d |	 d | d t }
 Wn6 t k
 rn} t d t |  t |  f |  n X|  j d  |  j d d  |  j   |
 d r|  j j d  |  j j d |
 d  |  j j d  qm|  j j d  |  j j d |
 d  |  j j d  q|  j d  |  j d d  |  j   |  j j d  |  j j d  |  j j d  q|  j d  |  j d d  |  j   |  j j d  |  j j d  |  j j d  qS|  j d  |  j d d  |  j   |  j j d  t d  d! |  j d  qc|  j d  |  j d d  |  j   |  j j d"  qs|  j d#  n |  j d#  Wn t k
 rt d$  n Xd  S(%   Nt   ?i    s   .pywas   /dli   t   &t   =t   passt   idRU   R^   R   s1   WebUI download request for id %s received from %sR!   t   buttonwatchRW   R  R   R  R!  s.   Error while downloading %s from web, error: %si   s   Content-types	   text/htmls}   <html><head><script>t = null;function moveMe(){t = setTimeout("self.close()",10000);}</script></head><body onload="moveMe()">s   %ss   </body></html>s   <html><head></head>s   Incorrect sitename.s   Torrentid missing.s'   Incorrect password supplied. Try again.R  sD   Received a webUI download command with the wrong password from ip %ss'   Incorrect command structure. Try again.i  s   Generic do_GET exception(   R   R   R   R}   t   endswitht
   startswithRu   Rl   R#   R  R   Ro   R%   t   client_addressR   Rw   R/   Rh   R0   R-  R1   R2   R   t   send_responset   send_headert   end_headerst   wfileR   t
   send_error(   RG   R   t   argR   t   at   bR  R^   R!   t   loct   outputR   (    (    s   WHATauto.pyt   do_GET  s    %	
%%*%'





(   RK   RL   R  (    (    (    s   WHATauto.pyR    s   R   c           B  sZ  e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z dA dA d  Z dA dA d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d    Z# d!   Z$ d"   Z% d#   Z& d$   Z' d%   Z( d&   Z) d'   Z* d(   Z+ d)   Z, d*   Z- d+   Z. d,   Z/ d-   Z0 d.   Z1 d/   Z2 d0   Z3 d1   Z4 d2   Z5 d3   Z6 d4   Z7 d5   Z8 d6   Z9 d7   Z: d8   Z; d9   Z< d:   Z= d;   Z> d<   Z? d=   Z@ d>   ZA d?   ZB d@   ZC RS(B   sl   A class for connecting to an IRC network, joining an announce channel, and watching for releases to downloadc         C  sw  t  d d | d d | | |  _ t |  _ d |  _ d |  _ t |  _ t |  _ t |  _	 t |  _
 g  |  _ |  j g |  _ t |  _ t j   |  _ | d |  _ | d |  _ | d	 |  _ | d
 |  _ | d |  _ | d |  _ | d |  _ t   |  _ t   |  _ t |  _ t   |  _ d |  _ t |  _ t   |  _  t |  _! t" j# d t" j$  |  _% x= | d d j& d  D]$ } t" j# | d |  |  j  | <qrW|  j' t  d |  j d k r|  j d |  j d j( d  d |  j d <n  t |  _) d |  j k rt* |  _) n  t+ j, j-   t. j/ d |  j0  t. j/ d |  j1  t. j/ d |  j2  t. j/ d |  j3  t. j/ d |  j4  t. j/ d |  j5  t. j/ d |  j5  t. j/ d |  j5  t. j/ d |  j5  t. j/ d |  j6  t. j/ d  |  j7  t. j/ d! |  j8  t. j/ d" |  j9  t. j/ d# |  j:  t. j/ d$ |  j;  t. j/ d% |  j<  d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d: d; d< d= d> d? d@ dA dB dC dD dE dF dG dH dI dJ dK dL dM dN dO dP dQ dR dS dT dU dV dW dX dY dZ d[ d\ d] d^ d_ d` da db dc dd de df dg dh di dj dk dl dm dn do dp dq dr ds dt du dv dw dx dy dz d{ d| d} d~ d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d g |  _= x$ |  j= D] } t. j/ | |  j>  qW|  j d d k rWt  d d |  j d |  j n  t. j?   |  _ t+ j, j@   d S(   s   init this shit, yoR   s	   autoBOT: s    startedR^   RU   i    RX   RW   R   RY   R]   R\   R[   s   :I leave because I want to!s$   |||(?:[\d]{1,2}(?:,[\d]{1,2})?)?t	   announcess   , t   !R   i   t   advancefilterst   pubmsgt   privmsgt   welcomet   nicknameinuset   invitet	   whoisusert   whoischannelst   whoisservert
   endofwhoist
   privnoticet   namreplyt   actiont   currenttopicR   t   pongt
   nosuchnickt	   pubnoticeRg   t   kickt   modet   whoreplyt   endofwhot
   statsklinet   partR   t	   topicinfot
   statsqlinet
   statsnlinet
   statsilinet   statscommandst
   statsclinet   tracereconnectt   statslinkinfot   notregisteredt   createdt
   endofnamest   statsuptimet   notopict
   statsylinet
   endofstatst   uniqopprivsneededt   cannotsendtochant	   adminloc2t
   adminemailt   luserunknownt   luseropt
   luserconnst   luserclientt   adminmet	   adminloc1t   luserchannelst   toomanytargetst   listendt   toomanychannelst
   statsolinet
   invitelistt   endofinvitelistt   nosuchchannelt   invitingt	   summoningt
   exceptlistt   endofexceptlistt   noorigint   nosuchservert   nochanmodest   endofbanlistt   yourebannedcreept   passwdmismatcht   keysett   needmoreparamst   nopermforhostt   alreadyregisteredt   tryagaint
   endoftracet   tracelogt   notonchannelt   noadmininfot   umodeist
   endoflinkst
   nooperhostt	   fileerrort   wildtoplevelt   usersdisabledt   norecipientt   notexttosendt
   notoplevelR   t	   infostartt   whoisoperatort	   whoisidlet   whoischanopt
   whowasusert   userst
   usersstartR=   t   nouserst
   endofuserst   servlistt   servlistendt   youwillbebannedt   badchannelkeyt   serviceinfot   endofservicest   servicet	   youreopert   usernotinchannelt   listt   nonet	   liststartt   noservicehostt   channelmodeist   awayt   banlistt   linkst   channelcreatet   closingt   closeendt   usersdontmatcht   killdonet   traceconnectingt	   tracelinkt   traceunknownt   tracehandshaket	   traceusert   traceoperatort   traceservicet   traceservert
   traceclasst   tracenewtypet   userhostt   isont   unawayt   nowawayt   nologint   yourhostt	   rehashingt
   statsllinet   summondisabledt   umodeunknownflagt   bannedfromchant   useronchannelt
   restrictedt   cantkillservert   chanoprivsneededt   noprivilegest   badchanmaskt
   statshlinet   unknownmodet   inviteonlychant   channelisfullRV   t   unknowncommandt   nickcollisiont   myportist   banlistfullt   erroneusnicknamet   unavailresourcet   nonicknamegivenR  s#   Nickowner on network '%s' is blank!N(A   R%   R!   R   t   lastannouncet   lastannouncetextt   attemptt   ownernetworkt   ownertargetR   t   havesendwhoist   havesendwhoamit   havesendwhoisallt	   piggybackt   pingsentR   R   t   lastdataRX   RW   R   RY   R]   R\   R[   R  t   announcehistoryt   threadst
   connectiont   whot
   partPhraset   joinedRl   t   regt	   resistantR   t   compilet   UNICODEt   ircregR   t   checkTorrentFoldersR   t   advancedfiltersR#   R   R   R   R5   t   add_global_handlert   handlePubMessaget   handlePrivMessaget   handleWelcomet   handleNickInUset   handleInvitet   handleWhoIst   handlePrivNoticet   handleNameReplyt   handleActiont   handleCurrentTopict   handleErrort
   handlePongt   handlenosuchnickt   what_eventst   handleAllDebugR   R   (   RG   R!   R   R  RF   (    (    s   WHATauto.pyRH     s|    														"/	  c         C  s   | d |  _  | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ x= | d d j d	  D]$ } t j	 | d |  |  j
 | <qs W|  j d   d  S(
   NRX   RW   R   RY   R]   R\   R[   R  s   , (   RX   RW   R   RY   R]   R\   R[   R   R   RS  RQ  RV  R   (   RG   R   R  (    (    s   WHATauto.pyR   A  s    "c         C  s~   | j  |  _  |  j  j |  j  | j |  _ t } x* |  j  D] } t j | j r; t } q; q; W| rz |  j	 |  j d   n  d  S(   N(   RH  t   appendR!   RM  R   R   R   RP  R#   t   logintochannelsR   (   RG   t   othernetworkt
   havejoinedR^   (    (    s   WHATauto.pyR   M  s    c         C  s   |  j  S(   N(   R!   (   RG   (    (    s   WHATauto.pyR   Y  s    c         C  s  x |  j  j   D] } |  j  | d d k r |  j  | j d  r |  j  | d d k r y< t j j |  j  | d  s t j |  j  | d  n  Wq t k
 r } t d |  | r |  j	 d | |  j  | d f |  d |  j  | d <q q Xq q q W|  j
 j d  r|  j
 d d k ry4 t j j |  j
 d  sZt j |  j
 d  n  Wqt k
 r} t d |  | r|  j	 d | |  j
 d f |  d |  j
 d <qqXn  y4 t j j |  j d  st j |  j d  n  Wn t j k
 r?} t d d	 |  j d | f  t d
  t t _ t j   ny t k
 r{} t d d  t d
  t t _ t j   n= t k
 r} t d |  t d
  t t _ t j   n Xd  S(   NR_   RO   R  RU   R   sc   Error: There was a problem with the custom watch folder for filter '%s'. It will be ignored. : '%s'sa   Error: There was a problem with the custom watch folder for site '%s'. It will be ignored. : '%s'R  s   torrentDir: %s caused %ss#   This program will now exit (okay): sX   Setup option 'torrentDir' is missing from setup.conf. So let's put it in there, mmmmkay?(   R]   Rq   Rx   R   R   R   R   R1   R%   R0  RW   R   R   Rf   R#   R   R?   RB   RC   t   KeyError(   RG   R  R   R   (    (    s   WHATauto.pyRV  \  sL    -%"%!
	
	
	c   	   	   C  s  |  j  t j j   k r d St d d |  j d |  j  xM |  j D]B } | t j k rC t t j | _ t d d | d |  j  qC qC W|  j d 7_ t } t |  _	 |  j d k r t d d |  j d |  j  n  yPd	 |  j
 k r|  j
 d	 d
 k rt } n t } d |  j
 k r/t |  j
 d  } n d } t d d |  j
 d | | f d |  j  d |  j k r~|  j d } n |  j d } d |  j k r|  j d } n d } d |  j k r|  j j |  j
 d | | | d |  j d d	 | n0 |  j j |  j
 d | | d |  j d d	 | Wn} t j k
 rd} t d d t |  d |  j  t } nB t j k
 r} t d d t | j    d |  j  t } n X| r|  j d k rt } t d d |  j
 d t |  t |  j  f d |  j  x |  j D] } t d d | d |  j  | t j k rkt j | j   t j j   t j | =t j j   qt d d | d |  j  qWqt d d t t j d |  j   d |  j  |  j j t t j d |  j   |  j  n d |  _ |  j j d |  j  d S(   s<   Connect to the IRC network and join the appropriate channelsNR   s   piggyback is %sR^   s   Reset self.joined for %si   R   s   Connection attempt number %dt   sslRO   R   i  s0   Connecting to the server: %s on port: %s SSL: %sR   R   R   R   t   ircusesignont   ircnameRG  R   s   Server Connection Error: %ss   Server Not Connected Error: %si
   sO   Failed to connect to server %s:%s after retrying %s times, aborting connecting.s%   Removing %s from the running networkss'   Site name %s was not found in G.RUNNINGs   Retrying in %d secondsi   i    (   R!   R   R   Rq   R%   RH  R   RP  RB  RI  RX   R#   Rn   RW   R   RM  R   R3   t   ServerConnectionErrorRI   t   ServerNotConnectedErrort   messageR   t
   disconnectR   R   R   t   matht   powt   execute_delayedt   testtimeout(	   RG   R   t   connerrt   csslt   cportR   R   R   R^   (    (    s   WHATauto.pyR     sf    !	 "	*64 	&
9
!/.	c         C  s  t  |  j  d k r, |  j j d t  n  t j d |  j  t j d |  j  t j d |  j	  t j d |  j
  t j d |  j  t j d |  j  t j d	 |  j  t j d
 |  j  t j d |  j  t j d |  j  t j d |  j  t j d |  j  t j d |  j  t j d |  j  t j d |  j  t j d |  j  x$ |  j D] } t j | |  j  qfWt |  _ d  S(   Ni   s'   pyWHATauto %s - http://bot.whatbarco.deR  R  R  R  R  R  R  R  R  R  R  R  R  R   R  R  (   Ru   RH  RM  Rs  t   VERSIONR5   t   remove_global_handlerRY  RZ  R[  R\  R]  R^  R_  R`  Ra  Rb  Rc  Rd  Re  Rf  Rg  R   RI  (   RG   RF   (    (    s   WHATauto.pyRs    s*    c         C  s  d } t    } x? |  j | d j d  D]# } | j |  | | <| d 7} q* Wd } xE|  j j   D]4} t } t d d | d |  j |  j | d d	 k rd
 |  j | k r |  j | d
 | k s t	 |  j | d j d   d k r^x{ |  j | j
   D]f \ }	 }
 | r|	 |  j d k s@|	 |  j d k rn|  j |	 |
 | |  skt } |	 } PqkqnqqW| rt d d | d |  j |  j d } |  j | j d  r|  j | d d  k	 r|  j | d } n  | | f SyJ| d k rUt d d | | | j |  j | d j d  j d j d d   d  f d |  j n | |  j d k rt d d | | | j |  j | d j d  j | j d d   d  f d |  j no | |  j d k r3t d d | | j |  j | d j d  j | j d d   d  | f d |  j n  Wq~t k
 rZ} t d d |  q~Xqt d d | | f d |  j qg t d d | d |  j qg Wt t f S(   Ni   t   formats   , RU   t   FILTERs   Checking filter section '%s'R^   R_   RO   t
   filtertypet   tagst   not_tagsR   s   Filter %s matchesR  R  t   all_tagssA   Filter '%s' failed because the release did not match %s with '%s't   not_sD   Filter '%s' failed because the release contained '%s' which is in %sR   sD   There was an error trying to output why the filter did not match. %ss   Filter '%s' is not of type: %ss   Filter '%s' is not active(   Rl   RX   R   R   R]   Rq   R#   R%   R!   Ru   Ry   t   isTagOKR   R   Rx   R   R   R   R\  (   RG   R   R  t   iR   R   t   badkeyR   t   filter_section_okR   RF   t   dirR   (    (    s   WHATauto.pyt   shouldDownload  sH    	!P &-
\\`#c      
   C  s  | d k r t  S| | j   k s@ | d k rd | j   k r| d k r | | d  k	 rt d d | | d |  j t  Sq| d k r | | d  k rt d d	 | | d |  j t  Sq| j   j   d
 k r t  S| d k r| | d  k	 ry~x]| j d  D]L} xC| j d  D]2} | j   j   } | d
 k r#| d d k rt j	 d | |  } x | D]I } | j
   | j
   k rtt d d | | | | f d |  j t  SqtWqU| d d k r+t j | d j
   | | j
   j    r+t d d | | | | f d |  j t  St d d | | | | f d |  j q#q#WqWt d d | d |  j Wqt k
 r}	 t d d | | | | | |	 f d |  j qXq| d k r| d d  k	 ry x | j d  D] } xx | j d  D]g } | j   j   } | d
 k r| j
   | d j
   k rjt d d | | f d |  j t SqqWqWt d d d |  j t  SWqt k
 r}	 t d d | | | | | |	 f d |  j qXq| | d  k	 ryXx7| j d  D]&} x| j d  D]} | j   j   } | d
 k r| d d k r| j
   | | j
   k rt d d | | | | f d |  j t  S| d d k rt j | d j
   | | j
   j    rt d d | | | | f d |  j t  St d d | | | | f d |  j qqWqWt d d | d |  j Wqt k
 r}}	 t d d | | | | | |	 f d |  j qXqnRd | k r| j d d
  | j   k r| | j d d
  d  k	 r| j d d
  }
 |
 d k rTy&x| j d  D]} x| j d  D] } | j   j   } | d d k rt j	 d | |
  } x | D]E } | j
   | j
   k rVt d d | |
 | f d |  j t SqVWq| d d k rt j | d j
   | |
 j
   j    rt d d | |
 | f d |  j t SqWqWWqt k
 rP}	 t d d | |
 | | | |	 f d |  j qXqy x | j d  D] } x | j d  D] } | j   j   } | d d k r| j
   | |
 j
   k rt d d | |
 | f d |  j t S| d d k r}t j | d j
   | |
 j
   j    r}t d d | |
 | f d |  j t Sq}WqgWWqt k
 r}	 t d d | |
 | | | |	 f d |  j qXn  t d d | d |  j t  St d d | d |  j t Sd  S(    Nt   sizeR  R  RO   R~  s    Detected '%s', which you wanted.R^   RT   s&   Detected '%s', which you did not want.RU   R  s   
i    t   @s	   [\w\._-]+s"   Detected %s match using '%s' in %si   R   s%   Didn't detect %s match using %s in %ss   Didn't detect match in %sR   s?   Tag Error: str: %s key: %s release[key]: %s Value: %s error: %ss;   Didn't detect match using %s. Announcement is missing '%s'.s   Detected match using all_tags.s'   Didn't detect %s match using '%s' in %sR  s4   Detected %s present in %s, which is disallowed by %ss)   Detected %s present in %s, which is in %ss*   Detected %s present in %s, which is in %s s(   Didn't detect any values present in '%s's/   '%s' was required but not found in this release(   R#   Rq   R   R%   R!   Rj   Ri   R   R   t   findallR}   R   R1   R   R"  R   (   RG   R   RF   R   R  t   commastrR   t   retagst   xtR   t   nkey(    (    s   WHATauto.pyR    s    0'<'2- 4,'<'27:#<#-,#<#-c         C  s  |  j  j |  xit |  j   t |  j d  k r{d } x5 t d t |  j d   D] } | |  j  | 7} qX Wi  } | | d <| j   | d <| j   | d <| j   | d <| | d <t	 j
 r |  j | |  n x< |  j D]1 } | j   t k	 r |  j |  j j |  =q q W|  j j t j d	 |  j d
 | | f d d   |  j d j d  |  j d j   |  j  d =q Wd  S(   Nt   announcelinesRU   i    t   textR$  t   sourcet   channelt   eventR  R   R!   s   pubmsg subthreadii   (   RK  Rh  Ru   Rn   RX   t   ranget	   eventtypeR  R  R   R6   t   processMessagesRL  t   isAliveR#   R   t	   threadingR   R,   R-   (   RG   RM  R   t
   cleanedmsgR   R  R   t   th(    (    s   WHATauto.pyt   handleannounce  s(    %#

	1c         C  sv  | j    | j    j d  d j   |  j d j   k pd t j |  j d j   | j    j    rn|  j d j   d k rk| j   d d d k rht j d d  } | d k r |  j	 d	 | j
    t |  _ n| d
 k r;|  j	 d | j
    |  j | j   d | j
   | j    | j    j d    n*| d k r| j
   d d k r|  j	 d | j
    |  j | j
    t j d  |  j | j
    |  j	 d | j
    |  j | j   d | j
   | j    | j    j d    n  ng |  j r)|  j	 d | j
    t |  _ n  |  j | j   d | j
   | j    | j    j d    n  n  nw |  j d d k p|  j d j   d k rd |  j | j
   | j    d | j    j d  d !| j   d f GHn  t } x, t j D]! } | | j    k rt } n  qW| r
d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d: d; d< d= d> d? d@ dA dB dC dD dE dF dG dH dI dJ dK dL dM dN dO dP dQ dR dS dT dU dV dW dX dY dZ d[ d\ d] d^ d_ d` da db dc dd de df dg dh di dj dk dl dm dn do dp dq dr ds dt du dv dw dx dy dz d{ d| d} d~ d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d g } d j d  } | j |  j d d  j d d  j   j d d  j   j d  }	 | j d  d |  j d d k p| j d  d |  j d k r&|	 | k r#| t j d t |  d  }
 d |
 k r
|  j	 |
 | j    | j    j d   | j
    n |  j	 |
 | j
    n  n | j d  d j   d k pa| j d  d j   d k rt j t j d d   |	 | k r| t j d t |  d  }
 d |
 k r|  j	 |
 | j    | j    j d   | j
    n |  j	 |
 | j
    n  n  n  t j oG| j    d d !j   d k oG| j
   j   d k rr|  j j |  xt |  j  t  |  j! d  k rnd }	 x5 t" d t  |  j! d   D] } |	 |  j | 7}	 qWi  } |	 | d <| j#   | d <| j    | d <| j
   | d <| | d <t j r#|  j$ |	 |  n> t% j& d |  j$ d |	 | f d d  } | j' d  | j(   |  j d =q]Wn  d  S(   NR  i   R   RU   i    t   %i-  i   s   No! And you can't make me!i   sF   You are such a slave driver. Seriously. Can't a bot relax around here?i,  t   #s"   What? I'm sick of you. Screw this!i   s   Hah! Fooled you.s   Alright... Fine....t   chatterRO   t   trues   %s:%s:%s:%ssN   I think so, %s, but where are we going to find a duck and a hose at this hour?sR   I think so %s, but where will we find an open tattoo parlor at this time of night?sH   Wuh, I think so, %s, but if we didn't have ears, we'd look like weasels.sE   Uh... yeah, %s, but where are we going to find rubber pants our size?s6   Sure, %s, but how are we going to find chaps our size?sE   Uh, I think so, %s, but we'll never get a monkey to use dental floss.s4   Uh, I think so %s, but this time, you wear the tutu.s;   I think so, %s, but culottes have a tendency to ride up so.sb   I think so, %s, but if we covered the world in salad dressing wouldn't the aspargus feel left out?sL   I think so, %s, but if they called them 'Sad Meals', kids wouldn't buy them!s[   I think so, %s, but me and Pippi Longstocking -- I mean, what would the children look like?sS   I think so, %s, but what would Pippi Longstocking look like with her hair straight?s@   I think so, %s, but this time you put the trousers on the chimp.sD   Well, I think so, %s, but I can't memorize a whole opera in Yiddish.sE   I think so, %s, but there's still a bug stuck in here from last time.s9   Uh, I think so, %s, but I get all clammy inside the tent.s>   I think so, %s, but I don't think Kaye Ballard's in the union.s
   Yes, I am!sH   I think so, %s, but, the Rockettes? I mean, it's mostly girls, isn't it?sF   I think so, %s, but pants with horizontal stripes make me look chubby.sP   Well, I think so -POIT- but where do you stick the feather and call it macaroni?sK   Well, I think so, %s, but pantyhose are so uncomfortable in the summertime.sA   Well, I think so, %s, but it's a miracle that this one grew back.sY   Well, I think so, %s, but first you'd have to take that whole bridge apart, wouldn't you?s5   Well, I think so, %s, but 'apply North Pole' to what?s+   I think so, %s, but 'Snowball for Windows'?s8   Well, I think so, %s, but snort no, no, it's too stupid!sL   Umm, I think so, Don Cerebro, but, umm, why would Sophia Loren do a musical?sC   Umm, I think so, %s, but what if the chicken won't wear the nylons?s<   I think so, %s, but isn't that why they invented tube socks?s=   Well, I think so %s, but what if we stick to the seat covers?s[   I think so %s, but if you replace the 'P' with an 'O', my name would be Oinky, wouldn't it?s=   Oooh, I think so %s, but I think I'd rather eat the Macarena.sB   Well, I think so hiccup, but Kevin Costner with an English accent?sF   I think so, %s, but don't you need a swimming pool to play Marco Polo?s7   Well, I think so, %s, but do I really need two tongues?s(   I think so, %s, but we're already naked.s\   Well, I think so, %s, but if Jimmy cracks corn, and no one cares, why does he keep doing it?s1   I think so, %s NARF, but don't camels spit a lot?sA   I think so, %s, but how will we get a pair of Abe Vigoda's pants?s8   I think so, %s, but Pete Rose? I mean, can we trust him?s0   I think so, %s, but why would Peter Bogdanovich?sA   I think so, %s, but isn't a cucumber that small called a gherkin?sF   I think so, %s, but if we get Sam Spade, we'll never have any puppies.sT   I think so, Larry, and um, %s, but how can we get seven dwarves to shave their legs?sK   I think so, %s, but calling it pu-pu platter? Huh, what were they thinking?sD   I think so, %s, but how will we get the Spice Girls into the paella?sQ   I think so, %s, but if we give peas a chance, won't the lima beans feel left out?sQ   I think so, %s, but I am running for mayor of Donkeytown and Tuesdays are booked.sK   I think so, %s, but if we had a snowmobile, wouldn't it melt before summer?sA   I think so, %s, but what kind of rides do they have in Fabioland?sY   I think so, %s, but can the Gummi Worms really live in peace with the Marshmallow Chicks?sT   Wuh, I think so, %s, but wouldn't anything lose its flavor on the bedpost overnight?sK   I think so, %s, but three round meals a day wouldn't be as hard to swallow.s[   I think so, %s, but if the plural of mouse is mice, wouldn't the plural of spouse be spice?sD   Umm, I think so, %s, but three men in a tub? Ooh, that's unsanitary!sR   Yes, but why does the chicken cross the road, huh, if not for love? I do not know.s.   Wuh, I think so, %s, but I prefer Space Jelly.sI   Yes %s, but if our knees bent the other way, how would we ride a bicycle?s[   Wuh, I think so, %s, but how will we get three pink flamingos into one pair of Capri pants?s;   I think so, %s, but Tuesday Weld isn't a complete sentence.sR   I think so, %s, but why would anyone want to see Snow White and the Seven Samurai?s1   I think so, %s, but then my name would be Thumby.s:   I think so, %s, but I find scratching just makes it worse.s<   I think so, %s, but shouldn't the bat boy be wearing a cape?s=   I think so, %s, but why would anyone want a depressed tongue?s@   Um, I think so, %s, but why would anyone want to Pierce Brosnan?se   Methinks so, %s, verily, but dost thou think Pete Rose by any other name would still smell as sweaty?sk   I think so, %s, but wouldn't his movies be more suitable for children if he was named Jean-Claude van Darn?sY   Wuh, I think so, %s, but will they let the Cranberry Duchess stay in the Lincoln Bedroom?sW   I think so, %s, but why does a forklift have to be so big if all it does is lift forks?so   I think so, %s, but if it was only supposed to be a three hour tour, why did the Howells bring all their money?sO   I think so, %s, but Zero Mostel times anything will still give you Zero Mostel.sq   I think so, %s, but if we have nothing to fear but fear itself, why does Eleanor Roosevelt wear that spooky mask?sH   I think so, %s, but what if the hippopotamus won't wear the beach thong?s]   Um, I think so, %s-2, but a show about two talking lab mice? Hoo! It'll never get on the air.s6   I think so, %s, but Lederhosen won't stretch that far.s7   Yeah, but I thought Madonna already had a steady bloke!sE   I think so, %s, but what would goats be doing in red leather turbans?sM   I think so, %s... but how would we ever determine Sandra Bullock's shoe size?sM   Yes, %s, I think so. But how do we get Twiggy to pose with an electric goose?sU   I think so, %s. But if I put on two tutu's, would I really be wearing a four-by-four?sC   I dunno, %s. Maybe it's all part of some huge, cosmic plot formula!s3   I think so, %s, but wouldn't mustard make it sting?sE   I think so, %s, but can you use the word 'asphalt' in polite society?s#   I think so, %s! (Sprays his breath)sS   I think so, Mr. %s, but if the sun'll come out tomorrow, what's it doing right now?s3   I think so, %s, but aren't we out of shaving cream?s2   Oh yes, %s! Remind me to tape all our phone calls!s;   Um, I think so, %s, but I hear Hillary is the jealous type.s/   I think so, %s, but Madonna's stock is sinking.sF   I think so, %s. But does 'Chunk o' Cheesy's' deliver packing material?sD   I think so, %s, but if we're Danish, where's the cream cheese? Narf!sG   I think so, Bwain, but I don't think newspaper will fit in my underoos.sY   Uh, I think so, %s--but after eating newspaper all day, do I really need the extra fiber?sG   I think so, %s! But isn't a dreadlock hair extension awfully expensive?sT   I think so, %s. But will anyone other than Eskimos buy blubber-flavored chewing gum?s3   I think so, %s, but the ointment expired weeks ago!sy   I think so, %s. But would the villains really have gotten away with it, if it weren't for those pesky kids and their dog?sO   Uh, I think so %s, but how are we gonna teach a goat to dance with flippers on?s[   Wuhh... I think so, %s! But let's use safflower oil this time! It's ever so much healthier!sm   Wuh... I think so, %s. But Cream of Gorilla Soup-well, we'd have to sell it in awfully big cans, wouldn't we?sc   I think so, %s. But if he left chocolate bullets instead of silver, they'd get all runny and gooey!s1   Yes, %s, I think so, but do nuts go with pudding?sc   I think so, %s, but a codpiece made from a real fish would get smelly after a while, wouldn�t it?sW   I think... so, %s... *gag* ...but I didn't know Annette used peanut butter in that way.s8   I think so, %s, but do those roost in this neighborhood?sy   I think so, %s, but is the world ready for angora bellbottoms? I mean I can see wearing them inside out, but that would--sU   I think so, Commander %s from Outer Space! But do we have time to grease the rockets?sA   I think so, Doctor. But are these really the legs of a show girl?sM   Whuh... I think so, %s. But this time I get to play the dishwasher repairman!sE   I think so, %sius. But what if a sudden wind were to blow up my toga?sN   I think so, %s. But Trojans won�t arrive on the scene for another 300 years.s7   I think so, %s... but where would a yak put PVC tubing?sb   Whuh... I think so, %s, but... but if Charlton Heston doesn't eat Soylent Green, what will he eat?s>   I think so, %s, but Ben Vereen never answered our proposition.st   I think so, %s, but wouldn't an itsy-bitsy, teeny-weenie, yellow polka-dot one-piece be better suited for my figure?s5   I think so, %s, but won't it go straight to my hips?!s6   I think so, Ali-%s! But isn't it cheating to use glue?sd   Whuu... I think so, %sPan! But if running shoes had little feet, wouldn't they need their own shoes?sM   I think so, %s. But what if the Earl of Essex doesn't like burlap pantaloons?sD   I think so, %s, but should we use dishwashing liquid or cooking oil?s"  I think so, %s! We'll dress up like biker dudes and infiltrate the "Hades Ladies." Then we'll convince them to hold a meeting inside the corn palace. Narf! The resulting carbon-monoxide buildup will allow you to complete your energy-making device and shortly after, you will rule the world!s0   I�m honored, %s... er, what was my idea again?sa   (holding one of the pointy pieces from Sorry! and the bottle of Slick 'n Slide) I think so, Br...s9   I think so, %s, but would Danish flies work just as well?s5   We think so, %s! But dressing like twins is so tacky.s_   I think so, %s, but practicing docking procedures with a goat at zero G's-it's never been done!sb   I think so, %s! But shouldn't we let the silk worms finish the boxer shorts before we put them on?sO   I think so, %s! You draw the bath and I'll fetch the alka-seltzers and candles!sV   I think so, %s. But the real trick will be getting Demi Moore out of the creamed corn!sU   Wuhhh... I think so, %s, but if a ham can operate a radio, why can't a pig set a VCR?sa   I think so, %s, you'd think [Lyndon Johnson would] have left room for baby-kissing, wouldn't you?sC   I think so, %s! But won't Mr. Hoover notice a missing evening gown?sg   I think so, %s! But what's the use of having a heart-shaped tattoo if it's going to be covered by hair?sZ   I think so, %s, but couldn't the constant use of a henna rinse lead to premature baldness?sE   I think so, %s. Just make sure we don't swallow each other's bubbles!sW   I think so, %s! But ruby-studded stockings would be mighty uncomfortable wouldn't they?s_   I think so, %s, but if I have my portrait drawn, will we have time to make it to the lifeboats?s@   I think so, %s! But is Chippendale's ready for 'The Full Pinky?'sI   I think so, %s! But do I have what it take to be the 'Lord of the Dance'?sW   I think so, %s! How much deeper would the ocean be if there weren't sponges down there?sW   Oh, I think so, %s! But doing a clog dance in actual clogs will give me awful blisters.s8   I think so, %s, but nose rings are kinda pass� by now.sV   I think so, %s, but where are we going to get a trained octopus at this time of night?sW   I think so, %s! But no more eels in jelly for me, thanks-I like my gelatin after lunch.sR   I think so, %s, but I didn�t know 90210 was a real zip code! Will Tori be there?sD   Narf! I think so, %s, but what if the Telechubbies don't fight fair?sT   I think so, %s. But even if we found a tuxedo to fit a blowfish, who would marry it?s<   Um, no, Cranky Mouseykin, not even in the story you made up.s    I think so, but where is a fish?sb   I think so, %s. But if Pinocchio were carved out of bacon it wouldn't be the same story, would it?sN   Um, I think so, %s, but wasn't Dicky Ducky released on his own recognaissance?s/   I think so, %s, but Pepper Ann makes me sneeze.sp   I think so, %s. But suppose we do the hokey pokey and turn ourselves around, is that what it's really all about?sI   (sung) I think so, %s, but just how will we get the weasel to hold still?sQ   I think so, %s, but how are we going to get the bacon flavoring into the pencils?s4   I think so, %s, but instant karma's always so lumpy.s-   I think so, %s, but she'd never leave Mickey.s%   are you pondering what i'm pondering?t    R   t   whatbotss   , R  s   %ss	   whatbots,i   i
   t
   johnnyfives
   #pywhatbotR  R  R$  R  R  R  R  R   R!   s   pubmsg subthread()   R  R   R}   RW   R   R   t	   argumentsR  t	   randrangeR0  R  R#   RR  t   handleOwnerMessaget   partChannelR=   R>   t   joinChannelR   R   R!   R   t   OWNERR   R   Rj   R  Ru   t   uniformR6   RK  Rh  Rn   RX   R  R  R  R  R   R,   R-   (   RG   RM  R   R  t   rt   braint   jft   quotest   lineR   R%   R  R   t   temp(    (    s   WHATauto.pyt   handlepubMSG  s    g?B	E,K FD 6> 6@%#

	'
c         C  s  | } t  } x|  j j   D]\ } } | j |  } | r t } t j j |  j | | j	 |  j
 | d j d  j d  d  f  d  } t d d | j	 d  d |  j t d	 d
 | d |  j |  j | |  \ } }	 | j	 |  j
 | d j d  j d  d  }
 | rht d d |
 |  j f |  j  t  } d |  j |	 k rs|  j |	 d d k rst } nR |  j d d k rd |  j |	 k r|  j |	 d d k rt } qqt } n  t  } d |  j |	 k r|  j |	 d d k rt } nR |  j d d k rPd |  j |	 k rG|  j |	 d d k rMt } qMqPt } n  t   srt d d d |  j n  |  j t k rn  t  } d |  j |	 k r|  j |	 d j   j   d k r|  j |	 d } n  t |
 |  j d | d | d |	 d | d | d | } t j j   t j |  j d c d 7<| d rXt j |  j d c d 7<n  t j j   qt j j   t j |  j d c d 7<t j j   t d	 d | d |  j q q W| s[ybt  } |  j
 j d  rx |  j
 d j d  D] } x | j d  D] } | j   j   } | d k r| d d k ri| j   j   j | j    rit } q| d d k rt j | d j   | j   j    rt } qqqWqWn t } | r
d  t j  k r
t d! d" | d |  j t j  d  j! | |  j  n t d! d# | d |  j Wqt" k
 rW} t d d$ | t# |  f  qXnD t$ j%   |  _& |
 r||
 |  _' n# d |  _' t d d% | d |  j d  S(&   NR}  s   , R
  i   R   s   **** Announce found: i    R^   R~  s   This is a(n) %s releases!   (%s) >> Download starting from %sR  RO   RT   R  Rr  R   s^   You have reached your free space limit. Torrent is being placed in an overflow folder. TO COMER  RU   R  R  R  R   RP   RQ   s&   There was no match with any %s filterst   introR  s   
R  RN  R   s   Naughty announce: s   NOT naughty: s@   Exception raised when proccessing naughty announce %s, error: %ss:   Did not find the download ID in the following announce: %s((   R   RQ  Ry   R   R#   R   R+   t   putR!   R   RX   R   R   R   R%   R  R]   RY   R   RW  Ri   Rj   R-  R   R   Rm   R   Rx   R}   R  R   R"  R   t   naughtyAnnounceR1   RI   R   R   R@  RA  (   RG   R   R   R  t   matchedR  RQ  R   R  R   R
  Rq  t   notifit   sLt   rett   naughtyR  R   R   (    (    s   WHATauto.pyR    s    F#0 *		*			66
 !1	8	c         C  s   |  j  j d |  } | S(   NRU   (   RU  t   sub(   RG   R   (    (    s   WHATauto.pyt   stripIRCColorsJ  s    c         C  s   |  j  d | d |  d  S(   Ns   #whatbot-debugt   :(   R0  (   RG   R  R  (    (    s   WHATauto.pyR  N  s    c         C  s]   y |  j  j | |  Wn? t j k
 rX } t d d | | t |  f d |  j n Xd  S(   NR   s$   Could not send '%s' to %s. Error: %sR^   (   RM  R  R3   Rq  R%   RI   R!   (   RG   R   R  R   (    (    s   WHATauto.pyR0  Q  s    c         C  s   | |  _  | |  _ t |  _ |  j j   r y |  j j | f  Wq t j k
 ry } t	 d d t
 |  d |  j q t j k
 r } t	 d d t
 | j    d |  j q Xn t j | j d |  j  d  S(   NR   s   Server connection error: %sR^   s   Server not Connected Error: %ssX   Cannot send whois as the bot is currently not connected to the network, try again later.(   RC  RD  R#   RE  RM  t   is_connectedt   whoisR3   Rp  R%   RI   R!   Rq  Rr  R   R   R0  (   RG   t   whonickRC  RD  R   (    (    s   WHATauto.pyt	   sendWhoIsW  s    			#-c         C  s   | |  _  | |  _ |  j j | j    |  j j   r y |  j j | f  Wq t j	 k
 r } t
 d d t |  d |  j q t j k
 r } t
 d d t | j    d |  j q Xn  d  S(   NR   s   Server connection error: %sR^   s   Server not Connected Error: %s(   RC  RD  RG  Rh  R}   RM  R  R  R3   Rp  R%   RI   R!   Rq  Rr  (   RG   R  RC  RD  R   (    (    s   WHATauto.pyt   sendWhoIsalle  s    		#c         C  s   | |  _  | |  _ t |  _ |  j |  j d k r |  j j   r y |  j j |  j j	 f  Wq t
 j k
 r } t d d t |  d |  j q t
 j k
 r } t d d t | j    d |  j q Xq n  d  S(   Ni    R   s   Server connection error: %sR^   s   Server not Connected Error: %s(   RC  RD  R#   RF  R!   RH  RM  R  R  t   real_nicknameR3   Rp  R%   RI   Rq  Rr  (   RG   RC  RD  R   (    (    s   WHATauto.pyt
   sendWhoAmIq  s    			#c         C  s1  y | d  k	 rU | d d k r8 |  j j | |  j  q |  j j d | |  j  nc | d  k	 r xT | D]I } | d d k r |  j j | |  j  qh |  j j d | |  j  qh Wn  Wnq t j k
 r } t d d t |  d |  j n< t j	 k
 r,} t d d t | j
    d |  j n Xd  S(   Ni    R  R   s   Server connection error: %sR^   s   Server not Connected Error: %s(   R   RM  R  RO  R3   Rp  R%   RI   R!   Rq  Rr  (   RG   R  t   channelsR   (    (    s   WHATauto.pyR    s    %#c         C  s  y | d  k	 rI | d d k r2 |  j j |  q |  j j d |  nW | d  k	 r xH | D]= } | d d k r |  j j |  q\ |  j j d |  q\ Wn  Wnq t j k
 r } t d d t |  d |  j n< t j k
 r} t d d t | j	    d |  j n Xd  S(   Ni    R  R   s   Server connection error: %sR^   s   Server not Connected Error: %s(
   R   RM  R   R3   Rp  R%   RI   R!   Rq  Rr  (   RG   R  R  R   (    (    s   WHATauto.pyR    s    #c         C  s   |  j  d k r" |  j j d  n  d |  j k r x |  j d j d  D]q } xh | j d  D]W } | j   } | j   } | d k r^ t d d | d	 |  j  |  j j |  q^ q^ WqH Wn  d  S(
   NRN  s   #whatbot-debugt
   chanfilterR  s   
RU   R   s   Joining channel: %sR^   (   R!   RM  R   RW   R   Ri   Rj   R%   (   RG   t   xchannelR  (    (    s   WHATauto.pyt   joinOtherChannels  s    c         C  s  | |  j  k r|  j d |  j k rt j   |  _ |  j  j   r d |  j k r |  j  j d d |  j d |  j d f  |  j  j	 |  j d  |  j d =n  t
 d d |  j d	 |  j  j   f d
 |  j n  t
 d d d
 |  j |  j   t
 d d d
 |  j n  d  S(   Ni    R   t   nickservs   GHOST %s %sR   R   R   s(   Connected to %s, server calls itself %s.R   R^   R   s:   Connection was lost. Maybe you were g-lined? Trying again.s_   Your bots nickname MUST be registered with nickserv, otherwise it will sit here and do nothing!(   RM  RH  R!   R   R   RJ  R  RW   R  R}  R%   RX   t   get_server_nameR   (   RG   RM  R   (    (    s   WHATauto.pyR[    s    %+3
c      	   C  sR  | |  j  k rNt j   |  _ t d d t | j    | j   | j   j d  d j   |  j	 d j   t | j
    |  j	 d f d |  j | j   | j   j d  d j   |  j	 d j   k rN| j
   d j   |  j	 d j   k rNt d d	 t | j
   d  d |  j |  j  j | j
   d  t |  _ qNn  d  S(
   NR   s9   Invited by %s (%s, %s) to join %s (announcechannel is %s)R  i   t   botwhoR   R^   i    s   Joining %s after invite.(   RM  R   R   RJ  R%   R   R  R   R}   RX   R  R!   R   R#   RP  (   RG   RM  R   (    (    s   WHATauto.pyR]    s    xe*c         C  s   | |  j  k r t j   |  _ |  j | j   d  } d |  j k r\ |  j d j   } n |  j d j   } | j   | j   j	 d  d j   | k r | j
   j   |  j d j   k r |  j | | |  q |  j | | |  n  d S(   s   Handles the messages received by the IRCLIB and figures out WTF to do with them. Probably throws most of them away, cause IRC is full of trash.i    t   announcebotwhoR  R  i   R   N(   RM  R   R   RJ  R  R  RX   R}   R  R   R  R  R  (   RG   RM  R   R  RN  (    (    s   WHATauto.pyRY    s    Tc         C  sJ  | |  j  k rF|  j d |  j k rFt j   |  _ | j   | j   j d  d |  j d k s t	 j
 |  j d j   | j   j    r |  j d j d k r |  j | j   d | j   | j   j d   | j   | j   j d    qFt d d |  j | j   d | j   j d  !| j   d f d |  j n  d	 S(
   s    Handle messages sent through PM.i    R  i   R   RU   R   s   %s:PM:%s:%sR^   N(   RM  RH  R!   R   R   RJ  R  R   RW   R   R   R}   R  R  R%   (   RG   RM  R   (    (    s   WHATauto.pyRZ    s
    %qRc         C  s   | |  j  k r t j   |  _ |  j | j   d  } d |  j k r\ |  j d j   } n |  j d j   } | j   | j   j	 d  d j   | k r | j
   j   |  j d j   k r |  j | | |  q |  j | | |  n  d S(   s    Handle messages sent as actions.i    R  R  R  i   R   N(   RM  R   R   RJ  R  R  RX   R}   R  R   R  R  R  (   RG   RM  R   R  RN  (    (    s   WHATauto.pyRa    s    Tc         C  s  | |  j  k r|  j s@ | j   d j   |  j k s@ |  j rt j   |  _ t	 d d | j   d t
 | j    f d |  j | j   d k r1|  j rt |  _ |  j d  k r.|  j d  k r.t j |  j j |  j |  j  d  |  _ d  |  _ t   |  _ q.q|  j rWy$ |  j j | j   d j    Wn* t	 d d t
 |  j  d |  j n X|  j d  k r.|  j d  k r.d  } |  j g  k ry t d |  j d d	  } Wn- t k
 r} t	 d d
 | j  d  } n X| r| d } d j | d d d ! } qn  | s,d } d } n  |  j d j   | j   k r[|  j d } nS d |  j k rd |  j k r|  j d j   | j   k r|  j d } n d } | j   | j   k r| rd } n | sd } n d | | f } d |  j | | f } t j |  j j | |  j  |  j sEd  |  _ d  |  _ n  t   |  _ q.q|  j rt |  _ |  j d  k r.|  j d  k r.|  j g  k ry t d |  j d d	  } WnY t k
 r} t	 d d | j  d  } n- t k
 r} d  } t	 d d | j  n X| rd | k r| d d j   j d  }	 t }
 xK |	 D]C } | j d  } |  j d j   j d d  | k rMt }
 qMqMW|
 rd } qd  | d d } qd! } qd! } n d } d" |  j |  j d | f } t j |  j j | |  j  d  |  _ d  |  _ t   |  _ q.qq| j   d# k rt|  j j d$ | j   d | j   d f  q| j   d% k r|  j j d& | j   d  q| j   d' k r|  j j d( | j   d  q|  j j | j    n  d  S()   Ni    R   s$   Whois e.arguments()[0]: %s, full: %sR^   R  R   s3   Could not remove from havesendwhoisall, its now: %sRJ  RK  s   Whoisall parsing error: %st   UserR  t   Infoi   RU   t   botnameR  t   announcebotnameR  t   OKs   Bot is not onlines   %s (whois) != %s (regex.conf)s   %-16s %-15s %-si   s   WhoAmI parsing error: %ss#   WhoAmI IndexError parsing error: %st   ChannelsR  R  R   RU  s)   NOT in announce channel, channels are: %ss   NOT in announce channels   %-16s %-20s %-sR  s   'User': '%s', 'Info': %sR  s   'Channels': %sR  s   'Server info': %s(    RM  RE  R  R}   RG  RF  R   R   RJ  R%   RI   R!   R  R   RC  R   RD  R   R   R0  RN  R  R,  RV  R'  R   RX   t
   IndexErrorR   R   R#   Rh  (   RG   RM  R   R   R   t   botidentR  t   statusR   t   channellistt   isint   litat   litb(    (    s   WHATauto.pyR^    s    @6		 			$'
 	=						%					1!!c         C  sQ   |  j  | k rM t j   |  _ t d d | j   | j   f d |  j n  d  S(   NR   s   namereply received, %s:%sR^   (   RM  R   R   RJ  R%   R  R  R!   (   RG   RM  R   (    (    s   WHATauto.pyR`  U  s    c         C  s  | |  j  k rt j   |  _ t d d | j   | j   f d |  j d | j   d j   k ru |  j	 t
 k s d | j   d j   k r |  j	 t
 k r |  j d |  j k r t d d d |  j n  |  j | |  q|  j d |  j k rUd | j   d j   k s0d	 | j   d j   k r|  j	 t
 k rt d d
 d |  j |  j d rR|  j  j d d |  j d  qRqd | j   d j   k r|  j	 t
 k rt d d
 d |  j |  j d rR|  j  j d d |  j d  qRqd | j   d k r| j   d | j   d j d  } t d d | d |  j qqt d d | j   | j   | j   f d |  j n  d  S(   NR   s   %s:%sR^   s   password acceptedi    s   you are now identified fors/   You have identified with nickserv successfully.s   please choose a different nicksF   You need to be identified to a registered account to join this channels)   Ident request received. Sending identify.R   R  s	   identify s"   this nick is owned by someone elses   You were forced to joinR  s   You were forced to join %sR   s	   (%s)%s:%s(   RM  R   R   RJ  R%   R  R  R!   R}   RP  R   RH  Ri  RW   R  R   R  (   RG   RM  R   R  (    (    s   WHATauto.pyR_  `  s(    ,VG$+$' c         C  s  yd |  j  k r|  j  d d k r|  j  d j   j   } y d | k ri | j d |  j d  } n  d | k r | j d |  j d  } n  d | k r | j d |  j d	  } n  d
 | k r | j d
 |  j  d  } n  d | k r	| j d |  j  d  } n  Wn6 t k
 rB} t d d t | j  d |  j	 n Xd |  j  k rt d d |  j  d |  j  d f d |  j	 n. t d d |  j  d |  j  d f d |  j	 |  j
 j |  j  d d |  n d |  j  k rz|  j  d d k rzd |  j k ra|  j d d k ra|  j d } t d d |  j  d d |  j	 |  j
 j |  j  d |  qt d d d |  j	 n8 t d d |  j  d d |  j	 |  j
 j |  j  d  d |  j k r|  j d d k r|  j
 j |  j d  n  t |  _ |  j
 j d |  j  Wnq t j k
 rF} t d d t |  d |  j	 n< t j k
 r} t d d t | j    d |  j	 n Xd  S(   Nt   requiresauthRO   t
   authstrings	   $usernameRG  s   $irckeyt   irckeys	   $passwordR   s	   $authchant   authchans   $announcechanR   R   s"   authstring is incomplete: Error %sR^   R   s)   Joining channel: %s by logging in with %sR  s   %sR   t   channelpasswordRU   s   Joining channel %ss_   Cannot join announce channel, this site requires to have the channelpassword set in creds.conf.s   Joining channel: %sR   i   s   Server Connection Error: %ss   Server Not Connected Error: %s(   RX   t   stripRi   R   RW   Rl  R%   R   Rr  R!   RM  R  R   t   send_rawR#   RP  Rv  R  R3   Rp  RI   Rq  (   RG   RM  R   R  R  (    (    s   WHATauto.pyRi  w  sJ    " #1.!""!!"	#c         C  sn   | |  j  k rj t j   |  _ | j   d } |  j | j   d  } t d d | | f d |  j n  d  S(   Ni    i   R   s   handleCurrentTopic: %s: %sR^   (   RM  R   R   RJ  R  R  R%   R!   (   RG   RM  R   R  t   topic(    (    s   WHATauto.pyRb    s
    c         C  s   | |  j  k r |  j d |  j k r t j   |  _ d |  j k r |  j t k r t	 d d |  j d d |  j |  j
   q |  j d d t t j d d	   } t	 d d
 |  j d | f d |  j |  j  j |  | |  j d <n  d  S(   Ni    t   ircallowednickR   si   The nickname %s was already in use. I cannot join the announce channel without it, so I am disconnecting.R^   R   t   |i  i  s@   The nickname %s was already in use. You have been renamed as %s.R   (   RM  RH  R!   R   R   RJ  RW   RP  R   R%   Rs  R   R  R  R}  (   RG   RM  R   t   newnick(    (    s   WHATauto.pyR\    s    %!''c         C  s   | |  j  k r |  j d |  j k r t j   |  _ t d d | j   | j   t	 |  f d |  j |  j  j
   } | r n  d | j   j   k r |  j  j d  t d d d |  j |  j  j d	 |  j  q n  d  S(
   Ni    R   s   %s:%s:%sR^   s   closing links   Cause it brokeR   s'   Waiting a few seconds before reconnect.i   (   RM  RH  R!   R   R   RJ  R%   R  R  RI   R  R}   Rs  Rv  R   (   RG   RM  R   t   con(    (    s   WHATauto.pyRc    s    %5c         C  s   | |  j  k r |  j d |  j k r t j   |  _ |  j r t j   |  j } t |  _ t d d | j	   d | j
 | j | j d d d
 d f d |  j q t d d	 | j	   d d |  j n  d  S(   Ni    R   s,   Pong received from %s, roundtrip time %.2f si   i  i
   i   R^   s$   Pong received from %s, NOT ASKED FORi@B i@B (   RM  RH  R!   R   R   RJ  RI  R   R%   R  t   microsecondsR   t   days(   RG   RM  R   t   timediff(    (    s   WHATauto.pyRd    s    %		Nc         C  s6   | |  j  k r2 t d d | j   d |  j n  d  S(   NR   s%   nosuchnick received, arguments are %sR^   (   RM  R%   R  R!   (   RG   RM  R   (    (    s   WHATauto.pyRe    s    c         C  s+  | |  j  k r'|  j d |  j k r't j   |  _ i  } | j   | d <| j   | d <| j   | d <| | d <| j   d k r t	 d d | j
   | j   f d	 |  j q'| j   d
 k r | j
   d j   d k r q't	 d d | j   | j   | j
   | j   f d	 |  j n  d  S(   Ni    R$  R  R  R  R   R   s   %s:%sR^   R  t	   pywhatbotR   s   (%s)%s:%s:%s(   RM  RH  R!   R   R   RJ  R  R  R  R%   R  R}   (   RG   RM  R   R   (    (    s   WHATauto.pyRg    s    %
/.c         C  s  |  j  t j j   k s' |  j j   r|  j d |  j  k r|  j r t |  _ t	 d d d |  j  |  j j
 d  |  j j d |  j  qt j   |  j } | j | j | j d d d d } t } | d k rt	 d d d |  j  y |  j j |  j j  Wn6 t j k
 rB} t	 d d | d |  j  t } n X| rr|  j j
 d  |  j j d |  j  qt j   |  _ n  | s|  j j d	 |  j  qqt	 d d t |  j  |  j d f d |  j  t j |  j d j   n t	 d d d |  j  t |  _ d  S(   Ni    R   s^   Connection timed out, PONG was not received within 30s. Disconnecting, wait(15), and reconnectR^   s   Cause it brokei   i   i  i
   i   ix   R   s3   ping server as 120 seconds without data have passedsE   Lost connection to server, %s. Disconnecting, wait(15), and reconnects:   Piggybacks have shifted: %s - moving execute_delayed to %ss<   Can't ping, as we are currently not connected to the networki@B i@B (   R!   R   R   Rq   RM  R  RH  RI  R   R%   Rs  Rv  R   R   R   RJ  R  R   R  t   pingR   R3   Rq  R#   Rw  RI   (   RG   t   tdt   tdst   errR   (    (    s   WHATauto.pyRw    s6    '		'
 0c   &      C  s  |  j  d |  j k ri d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d	 d 6|  j d 6}	 i d
 d 6|  j d 6}
 i d d 6|  j	 d 6} i d d 6|  j	 d 6} i d d 6|  j
 d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i d d 6|  j d 6} i | d 6| d  6| d! 6| d" 6| d# 6| d$ 6| d% 6| d& 6| d' 6| d( 6| d) 6|	 d 6| d* 6| d+ 6| d, 6| d- 6| d. 6|
 d/ 6| d0 6| d1 6| d2 6| d 6| d3 6| d4 6| d5 6| d6 6| d7 6| d8 6| d9 6} | j   j d:  }  |  d d; k r|  d d d< k r|  d d= }! |! | k rst |   d= k rA|  d= d k r|  j | |! d |  qpt    }" x |  d= D] }# |" j! |#  qW| |" | | g }$ | |! }% |% j" d  |$  q| d? | | g }$ | |! }% |% j" d  |$  q|  j d> |  qn  d? S(@   s8   Take commands from the operator. That's right, bow down.i    sD   Disconnects from all NETWORKS and closes all threads.   [pyWHATauto]t   helpR   sg   Returns a whois on the target name and network. Format %whois <network/alias> <nickname>   [pyWHATauto]s^   Returns a whois on the announcebots in all networks. Careful, its quite spammy.   [pyWHATauto]sV   Returns a whois of all bots in all networks. Careful, its quite spammy.   [pyWHATauto]s=   Updates your regex.conf to the newest version.   [pyWHATauto]s"  Sends a raw IRC command through the bot. Format %cmd <network/alias> <IRCCOMMAND> <values>. Please use the pyWHATauto commands if available, otherwise use this. For a list of IRC Commands and how to use them: http://en.wikipedia.org/wiki/List_of_Internet_Relay_Chat_commands.   [pyWHATauto]s0   You're angry, and you're gonna let them know it!s   Allows you to control filter states, as well as list enabled/disabled filters. Type %filter <enable/disable> <filtername> to toggle a filter.    [pyWHATauto]s]   Allows you to control filter states, as well as list enabled/disabled filters.   [pyWHATauto]sO   Connects to a network. Format %connect <network> <network2> ....   [pyWHATauto]sU   Outputs the amount of free space on the drive specified in setup.conf.   [pyWHATauto]s#   Reloads all configs.   [pyWHATauto]s   Changes the bots nickname to whatever you pass it. Does not change what the bot thinks it calls itself, so a %ghost command will ignore your changes.   [pyWHATauto]s   Joins the specified channel(s). You can join local channels as well as cross-network. Format %join <network/alias> #<channel> #<channel> ...   [pyWHATauto]s   Parts the specified channel(s). You can part local channels as well as cross-network. Format %part <network/alias> #<channel> #<channel> ...   [pyWHATauto]sJ   Gives seen and download statistics on each enabled network.   [pyWHATauto]sH   Outputs the local system time from where the bot resides.   [pyWHATauto]s   Rejoins a channel. Syntax: '%cycle' rejoins the current channel, '%cycle <channel>' rejoins <channel>, '%cycle <network/alias> <channel>' rejoins <channel> on <network/alias>.   [pyWHATauto]sS   Lists the currently enabled NETWORKS/sites and their WHATauto names.   [pyWHATauto]sj   Disconnects from the specified network. Format: %disconnect <site>. Ex: %disconnect whatcd.   [pyWHATauto]s   Downloads torrents manually from a network. Format: %download <site/alias> <torrentID> (<torrentID>) ..... For a list of site names try %sites.   [pyWHATauto]sB   Outputs the current running version to the channel.   [pyWHATauto]s1   Ghosts the nickname set in config.   [pyWHATauto]sK   Sends you a private message outputting your current filters.   [pyWHATauto]s3   Resets the stats on seen/downloaded.   [pyWHATauto]s9   Outputs how long the bot has been running.   [pyWHATauto]s%   You sir, are an idiot.   [pyWHATauto]Rg   R   R   R   R  t   statsRW  t   cycleR-  Rs  R=   R  t   whoisallt   whoamit
   statsresett   ghostt   ragequitR   R]   R  R   t   uptimet   reloadt   currentR}  RS   RV   R  RU   R  i   sJ   That is not a valid command. Try %help for the list of available commands.N($   RH  R!   t   fquitt   fwhoist	   fwhoisallt   fwhoamit   fupdatet   fcmdt
   fragequitet   ffiltert   fconnectt   ffreet   freloadt   fnickt   fjoint   fpartt   fstatst   ftimet   fcyclet   fsitest   fdisconnectt	   fdownloadt   fversiont   fghostt   fcurrentt   fstatsresett   fuptimet   fhelpRi   R   Ru   R0  R  Rh  R0   R   (&   RG   R   R  t	   ownernickRg   R  R  R  RW  R   R  R   R]   R   R   R  R}  R   R  R  R=   R  RS   Rs  R-  RV   R  R  R  R  R  t   commandst   cmdst   rootcmdt   switchest   itemt   vart   stupid(    (    s   WHATauto.pyR    s   
$	

c         C  s   t  d d d |  j t  d d d |  j x! t j j   D] } | j   q< Wt j j   t t _	 t j j
   t j   d  S(   Nt   CMDRg   R^   R   s!   I have received the quit command!(   R%   R!   R   R   Rt   Rs  R   R   R#   R?   R   RB   RC   (   RG   t   varsR   (    (    s   WHATauto.pyR    s    	c         C  s   d |  _  t d d d |  j t d d d |  j | d } d d	 d
 d d d d d d d d g } d d l m } |  j | |  |  |  j d |  |  j |  x! t j j	   D] } | j
   q Wt j j   t t _ t j j   t j   d  S(   Ns   :AND I'M NEVER COMING BACK!R  Rg   R^   R   s!   I have received the quit command!i    s   RRRRrrraaaaggggeee.s3   I'm backtracing your IPs right now. You're so dead.s;   I'm calling the FBI on you. What's the number, do you know?sR   I'm going to tell my daddy on you. He's real big where he works. Like an elephant.s,   I'm so hacking through your ports right nao!t   FFFFFFFUUUUUUUUUUUUUUUs   You guys are fucking assholes!s   I'M SO ANG0RZ RIGHT NAO!s   STOP TOUCHING ME!s)   Fuck this place. I'm way cooler than you.s   Who you gonna call?i(   t   choices6   BTW, here's a link to my blog: http://perezhilton.com/(   RO  R%   R!   R  R  R0  R  R   R   Rt   Rs  R   R   R#   R?   R   RB   RC   (   RG   R  R  t   angorzR  R   (    (    s   WHATauto.pyR    s    	
'	c         C  sp  | d } | d d  k rF| d d j   d k rt j j   t t j  d k r |  j d |  x: t j j   D]& \ } } |  j d | | f |  qv Wn  |  j d |  xI t j	 j   D]8 \ } } | t j k r |  j d | | f |  q q Wt j j
   ql| d d j   d k r!t | d  d k r!t j j   | d d j   t j	 k rd	 t j | d d j   <t j | d d j   t j	 | d d j   k rt j | d d j   =n  t   |  j d
 | d d j   |  n |  j d |  t j j
   ql| d d j   d k r3t | d  d k r3t j j   | d d j   t j	 k rd t j | d d j   <t j | d d j   t j	 | d d j   k rt j | d d j   =n  t   |  j d | d d j   |  n |  j d |  t j j
   ql|  j d |  n& t d d d |  j |  j d |  d  S(   Ni    i   R  s   Manually toggled filters:s   %s: %ss   Unchanged filters:t   enablei   RO   s-   Filter %s has been toggled on.   [pyWHATauto]s%   That filter doesn't exist. Try again!t   disableRT   s.   Filter %s has been toggled off.   [pyWHATauto]s4   That filter doesn't exist. Try again!   [pyWHATauto]sE   Incorrect command structure. What does that even mean?   [pyWHATauto]R  s   filter, incompleteR^   su   Filters. Like on cigarettes, except a lot healthier. Try typing %help filter to see how they are used.   [pyWHATauto](   R   R}   R   R   R   Ru   R~   R0  Ry   R|   R   R   R%   R!   (   RG   R  R  R   RF   (    (    s   WHATauto.pyR     sH    
!!06%06%c         C  s
  | d } | d d  k	 r| d d } t d d | d |  j | j   |  j j   k r|  j | j   } | t j k rt j | j   t d d t	 t j | j
  |  j  t t j | j
  d k r`t j | j
 j |  t j | j t j | j d  |  j d	 | t	 t j | j
  f |  t d d
 t	 t j | j
  |  j  nA |  j d | |  t d d t	 t j | j
  | f |  j  t j j   t j | =t j j   q|  j d | |  q|  j d | |  n |  j d |  d  S(   Ni    i   R  s   disconnect %sR^   R   s   piggyback before: %sR   sw   I have disconnected from %s. However %s use the same connection, so only the announce channel was parted.  [pyWHATauto]s   piggyback after: %ss+   I have disconnected from %s.   [pyWHATauto]s'   piggyback after: %s, %s will be removedsL   I cannot disconnect from %s since the network is not running.   [pyWHATauto]sQ   I do not know the network/alias %s. Format: %%disconnect <network>   [pyWHATauto]sH   That is not a full command. Format: %disconnect <network>   [pyWHATauto](   R   R%   R!   R}   R[   Rq   R   R   Rs  RI   RH  Ru   R,  R  RX   R0  R   R   R   (   RG   R  R  R  (    (    s   WHATauto.pyR  	  s,    
'"**-
c         C  s[   | d d  k rW | d d } t d d |  j j | f d |  j |  j j |  n  d  S(   Ni   i    R  s   nick change from %s to %sR^   (   R   R%   RM  t   nicknameR!   R}  (   RG   R  R!   (    (    s   WHATauto.pyR  %	  s    &c         C  sK  | d d  k rGt d d t |  t | d  t | d  f d |  j | d } t | d  d k  r |  j d |  qG| d d } | d d } | j   |  j j   k r0|  j | j   } t d d	 | | f d |  j | t	 j
 k rt	 j
 | j | |  j |  qD|  j d
 | |  qG|  j d | |  n  d  S(   Ni   R   s2   whois send, number of vars: %d, vars 0, 1: %s, %s i    R^   i   sI   Incorrect command structure. It should be %whois site nick   [pyWHATauto]R  s   Whois sent for %s on %ssY   You are currently not connected to %s, so I cannot send the whois request.   [pyWHATauto]sQ   I do not know the network/alias %s. Format: %%disconnect <network>   [pyWHATauto](   R   R%   Ru   RI   R!   R0  R}   R[   Rq   R   R   R  (   RG   R  R  R!   R  (    (    s   WHATauto.pyR  +	  s    =
  c         C  s   t  d d d |  j | d } |  j d d |  x t j j   D] \ } } t  d	 d
 | j d | f d |  j | j | j d |  j |  d | j k rD t  d	 d
 | j d | f d |  j | j | j d |  j |  qD qD Wd  S(   NR   s   Whoisall was sent.R^   i    s   %-16s %-15s %-st   Networkt   Botnickt   StatusR  s   Whois sent for %s on %sR  R  (   R#  R$  R%  (   R%   R!   R0  R   R   Ry   RX   R  (   RG   R  R  R   R  (    (    s   WHATauto.pyR  @	  s    
''c         C  s   t  d d d |  j | d } |  j d d |  xJ t j j   D]9 \ } } t  d	 d
 | d |  j | j |  j |  qD Wd  S(   NR   s   whoami was sent.R^   i    s   %-16s %-20s %-sR#  s   Announce ChannelR%  R  s   Whois whoami on %s(   s   Networks   Announce Channels   Status(   R%   R!   R0  R   R   Ry   R  (   RG   R  R  R   R  (    (    s   WHATauto.pyR  K	  s    
c         C  sj  | d } | d } t  d d d |  j t j d k r t r t |  j d  \ } } d |  j d t | d	 d	 d	 d
  t t | d  d
  f } qGd } n t j d k rGyS t |  j d  \ } } d |  j d t | d
  t t | d  d
  f } WqGt k
 rC} t  d d t	 |  d |  j d } qGXn  | d  k rf|  j | |  n  d  S(   Ni    i   R  R   R^   R
   R   s/   **Free Space on %s: %s GB (%s%%)   [pyWHATauto]i   i   id   s3   Uhh.. I need to install win32file for this to work.R   R   sA   There was an error. Double check 'drive' in setup.conf. Error: %ss7   There was an error. Double check 'drive' in setup.conf.(   R%   R!   R   R    R   R   t   roundR   t	   TypeErrorRI   R   R0  (   RG   R  R  R   R   R   R   (    (    s   WHATauto.pyR  S	  s"    

E	: c         C  s;   | d } t  d d d |  j t   |  j d |  d  S(   Ni    R  R  R^   sD   All configs (filters, setup, etc) have been reloaded.   [pyWHATauto](   R%   R!   R   R0  (   RG   R  R  (    (    s   WHATauto.pyR  g	  s    
c   
      C  s{  | d } t  d d d |  j y't j d  } | j   j d  } | j   | d } | d } t |  t t j	 d d	   k r"t
 |  t j k rt j d
  } t t j j t j d  d  } | j | j    | j   | j   t   |  j d |  qF|  j d |  n$ |  j d t d t |  f |  Wn- t k
 rv}	 t  d d |	 d |  j n Xd  S(   Ni    R  RW  R^   s&   http://bot.whatbarco.de/update/versions   
i   t   vRU   s)   http://bot.whatbarco.de/update/regex.confs
   regex.confR   sK   Your regex.conf file has been updated to the latest version.   [pyWHATauto]sD   You are currently running the latest regex.conf file.   [pyWHATauto]sn   You need to update pyWA before you can use the new regex. You are using %s, but %s is required.   [pyWHATauto]R   s,   Something happened when trying to update. %s(   R%   R!   R)  RC  R%  R   R@   R   R{  R   Rn   R   Rv   Rd   R   R   R   R   R   R   R0  R   R1   (
   RG   R  R  t   webFilet   xt
   minversiont
   regversiont	   regUpdatet	   localFileR   (    (    s   WHATauto.pyR  m	  s*    



$!

(c         C  sJ  | d } | d } t  d d | d |  j | r6t |  d k r6| d j   |  j j   k r#|  j | d j   } | t j k r t j | j d | d  |  j	 d | d | f |  t  d d	 | d | f d |  j q3t  d d
 | |  j  |  j	 d | d | f |  qF|  j	 d |  n |  j	 d |  d  S(   Ni    i   R  s   join %sR^   R  s    I am attempting to join %s on %sR   s   Joining channels %s on %ssK   You tried to join a channel on a network (%s) that is not currently runningsI   I cannot join %s on %s since it is not currently connected   [pyWHATauto]sZ   I do not recognise the network/alias. Try %sites for all available networks   [pyWHATauto]sn   Incorrect format for %join. The format should be %join <network/alias> #<channel> #<channel> ...  [pyWHATauto](
   R%   R!   Ru   R}   R[   Rq   R   R   R  R0  (   RG   R  R  R  R  (    (    s   WHATauto.pyR  	  s    

'!c         C  s   | d } | d } t  d d | d |  j | d  k	 r x | D]{ } | j   |  j j   k r t |  j | j    } |  j | |  qA |  j d | |  t  d d | d |  j qA Wn |  j d	 |  d  S(
   Ni    i   R  s
   connect %sR^   s'   I do not recognise the network/alias %sR   s   Unknown network/alias: %ssh   Incorrect command structure for %connect, it should be %connect <network> <network2> ....   [pyWHATauto](   R%   R!   R   R}   R[   Rq   R   R0  (   RG   R  R  R  R  R   (    (    s   WHATauto.pyR  	  s    

!c         C  sM  | d } | d } t  d d | d |  j | d  k r9t |  d k r9| d j   |  j j   k r&|  j | d j   } | t j k r t j | j	 d | d  |  j
 d | d | f |  t  d d	 | d | f |  j  q6t  d d
 | |  j  |  j
 d | d | f |  qI|  j
 d |  n |  j
 d |  d  S(   Ni    i   R  s   part %sR^   R  s    I am attempting to part %s on %sR   s   Parting channels %s on %ssK   You tried to part a channel on a network (%s) that is not currently runningsI   I cannot part %s on %s since it is not currently connected   [pyWHATauto]sZ   I do not recognise the network/alias. Try %sites for all available networks   [pyWHATauto]so   Incorrect format for %part. The format should be %part <network/alias> #<channel> #<channel> ...   [pyWHATauto](   R%   R!   R   Ru   R}   R[   Rq   R   R   R  R0  (   RG   R  R  R  R  (    (    s   WHATauto.pyR  	  s    

$!c         C  s  | d } t  d d | d |  j t j j   d } d } d } t d  } t d  } xt j j   D]\ } }	 y t j | d }
 t j | d	 } t t	 |
   | k r t t	 |
   } n  t t	 |   | k r t t	 |   } n  t |  | k rt |  } n  t |	 j
  | k r>t |	 j
  } n  Wqk t k
 rn} t  d
 d | d |  j qk Xqk W|  j d | d d | d d | d d | d d | d d f
 |  xt t j j    D]} yt j | j rt j   t j | j } | j | j | j d d d d } t | d  } t | | d d d  } t t j | | d d | d   } d } | d k r| d | d 7} n  | d k s| d k r| d | d 7} n  | d | d 7} n d } |  j d | d | | d t	 t j | d  | d t	 t j | d	  | d | | d t j | j
 f
 |  Wqt k
 r} t  d
 d | d |  j qXqWt j j   d  S(   Ni    R  s   stats to %sR^   i   s   Last Announcet
   DownloadIDRP   RQ   R   s   No reports yet for %ss   %-*s %*s %*s %*s %*si   t   Sitei   t   Seent   Downi   i  i
   i   i<   RU   s    %dt   hR   R|  i@B i@B i  (   R%   R!   R   R   R   Ru   R   R{   Rm   R   RA  Rl  R0  R   R   R@  R   R   R  R   R  Rn   Rt  t   floorR   (   RG   R  R  t   seenlent   downlent   sitelent   lastlent   idlenR^   t   linkRP   RQ   R   t   diffR   R   t   minutest   string(    (    s   WHATauto.pyR  	  sT    
"F')  v"c         C  sC   | d } t  d d d |  j |  j t j   j d  |  d  S(   Ni    R  R=   R^   s@   The date is %A %d/%m/%Y and the time is %H:%M:%S.   [pyWHATauto](   R%   R!   R0  R   R   R   (   RG   R  R  (    (    s   WHATauto.pyR  	  s    
c         C  s  | d } | d sQ t  d d | d |  j |  j j |  |  j j |  nft | d  d k r t  d d | d d d |  j |  j d | d d |  |  j j | d d  |  j j | d d  n | d d j   |  j j	   k r|  j | d d j   } | t
 j k r|  j d | d d | f |  t
 j | j | d d  t
 j | j | d d  q|  j d | d d | f |  n |  j d	 |  d  S(
   Ni    i   R  s   cycle R^   s!   Cycling channel %s   [pyWHATauto]s'   Cycling channel %s on %s   [pyWHATauto]sK   I cannot cycle %s on %s since it is not currently connected.   [pyWHATauto]s   Incorrect command structure. Syntax: '%cycle' rejoins the current channel, '%cycle <channel>' rejoins <channel>, '%cycle <network/alias> <channel>' rejoins <channel> on <network/alias>.    [pyWHATauto](   R%   R!   RM  R  R   Ru   R0  R}   R[   Rq   R   R   (   RG   R  R  R  (    (    s   WHATauto.pyR	  	  s$    

"#"%c         C  s  | d } t  d d d |  j t j j   |  j d |  d } x t j j   D] } | } |  j | | k r | d | 7} n | d | |  j | f 7} t	 |  d	 k rS |  j | d d
 !|  | t	 |  } qS qS W|  j | d d
 !|  d } x t j
 j   D] } | t j k rh| } | |  j | k rJ| d | 7} qh| d | |  j | f 7} n  t	 |  d	 k r|  j | d d
 !|  | t	 |  } qqW| d d
 !d } t j j   |  j | |  d  S(   Ni    R  RS   R^   s   Site Names: s
   [RUNNING] s   %s, s   %s=%s, i^  is   [AVAILABLE] s      [pyWHATauto](   R%   R!   R   R   R   R0  R   R   R\   Ru   Rw   R   (   RG   R  R  R  R^   t   runot   availt   ava(    (    s   WHATauto.pyR
  	
  s6    
c         C  s  | d } | d r t  | d  d k r | d d } d j | d d  } t d d | d |  j | j   |  j k r |  j | j   } | t j j   k r t j | j	 j
 |  q |  j d | | f |  q|  j d	 | |  n |  j d
 |  d  S(   Ni    i   i   R  R  s   cmd: %sR^   s\   I cannot send the raw command '%s' on %s since it is not currently connected.   [pyWHATauto]s2   I do not know the network/alias %s.   [pyWHATauto]s   That is not a full command. Syntax: '%cmd <network> <cmd>' Example: '%cmd whatcd privmsg :johnnyfive Are you alive?' Will send a private message to johnnyfive on whatcd.(   Ru   R   R%   R!   R}   R[   R   R   Rq   RM  R  R0  (   RG   R  R  R  R   (    (    s   WHATauto.pyR  (
  s    
 c         C  s  | d } | d r	t  | d  d k r	| d d j   |  j j   k r |  j | d d j   } | d d } x | D]r } |  j d | | f |  t j r t | | d |  d | q} i |  d 6| d 6} t j	 t | | f |  q} Wq|  j d |  n |  j d |  d  S(	   Ni    i   i   s'   Downloading %s from %s.    [pyWHATauto]R  R  sR   That site name does not seem valid. Type %sites to see a full list.   [pyWHATauto]si   That is not a full command. Format: %download <site/alias> <torrentID> (<torrentID>) ....    [pyWHATauto](
   Ru   R}   R[   Rq   R0  R   R6   R-  R&   R'   (   RG   R  R  R^   t   idsR  t   kwargs(    (    s   WHATauto.pyR  9
  s    
 #	 c         C  s   | d } | d } | d } t  d d | d |  j | d  k rW |  j d |  nD y  |  j | | d d |  Wn! t k
 r |  j d	 |  n Xd  S(
   Ni    i   i   R  s   help %sR^   s	  Commands: %help <topic>, %current, %update, %filter, %quit, %connect, %disconnect, %time, %uptime, %stats, %statsreset, %version, %sites, %free/%drive, %join, %whois, %part, %download, %reload, %whoisall, %whoami, %update, %cycle, %ghost, %nick, %cmd   [pyWHATauto]R  sP   That command does not exist. Try %help to see a list of commands.   [pyWHATauto](   R%   R!   R   R0  Rl  (   RG   R  R  t   switchR  (    (    s   WHATauto.pyR  K
  s    


 c         C  sA   | d } t  d d d |  j |  j d t t j f |  d  S(   Ni    R  RV   R^   s^   I am currently running pyWA version %s and regex.conf version %s by johnnyfi·ve and blub·ba.(   R%   R!   R0  R{  R   Rv   (   RG   R  R  (    (    s   WHATauto.pyR  X
  s    
c         C  s   | d } t  d d d |  j |  j j d d |  j d |  j d f  |  j j |  j d  |  j j d d	 |  j d  |  j d
 |  d  S(   Ni    R  R  R^   R  s   GHOST %s %sR   R   s	   identify s"   Ghost command sent.   [pyWHATauto](   R%   R!   RM  R  RW   R}  R0  (   RG   R  R  (    (    s   WHATauto.pyR  ]
  s    
+c   	      C  s^  t  d d d |  j | d } t j   t j } | j | j | j d d d d } t	 | d  } t	 | d  } t	 | | d	 d	 d	  } t	 t
 j | | d	 d	 | d	   } d
 } | d k r | d | d 7} n  | d k r| d | d 7} n  | d k s| d k r4| d | d 7} n  | d | d 7} |  j d | |  d  S(   NR  R  R^   i    i   i  i
   i   i<   RU   s    %ds    daysR3  R   s   s   [pyWHATauto]s   I have been running for%s.i@B i@B i  iQ i  (   R%   R!   R   R   R   t	   STARTTIMER  R   R  Rn   Rt  R4  R0  (	   RG   R  R  R;  R   R  R   R<  R=  (    (    s   WHATauto.pyR  e
  s"    
')   c         C  s   | d } t  d d d |  j t j j   x9 t j j   D]( } d t j | d <d t j | d <q= Wt j j   |  j d |  d  S(   Ni    R  R  R^   RP   RQ   s7   The stats reset command has been issued.   [pyWHATauto](	   R%   R!   R   R   R   Rm   Rq   R   R0  (   RG   R  R  R   (    (    s   WHATauto.pyR  u
  s    
c      	     s  | d } t  d d | d |  j d } t j j   t   } x t j j   D] } x t j | d j   D]n } t   | | <xX t j | d | j	   D]; \ } } | | | | <t
 |  | k r t
 |  } q q Wqn WqP Wt j j   i
 d d 6d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6    f d   }	 d t
 |  | d }
 xEt | j    D]1} |  j d | |  xt | | j   d |	 D]} | | | j d  } d | d	 | d | j d  f } t
 |  |
 k r|  j | d |
 d !|  d | d	 d  | |
 d f } xS t
 |  |
 k r|  j | d |
 d !|  d | d	 d  | |
 d f } q>Wn  x | D] } | } | d! | 7} t
 |  |
 k r|  j | |  d | d	 d  | f } t
 |  |
 k r|  j | d |
 d !|  d | d	 d  | |
 d f } xS t
 |  |
 k r|  j | d |
 d !|  d | d	 d  | |
 d f } q:WqqqW|  j | |  qWqwWd  S("   Ni   R  s   current to %sR^   i    R]   i   R_   i   R  R  i   t
   resolutioni   R  i   t   seasoni   t   episdei   t   artisti	   t   albumc           sP   |    k r( |   k r(   |    | S|    k r8 d S|   k rH d Sd Sd  S(   Nii   i    (    (   R*  t   y(   t   order(    s   WHATauto.pyt   compare
  s    i  i   s   ***Section: t   cmps   
s      %-*s  %-sR  RU   s   , (   R%   R!   R   R   R   Rl   Rw   R   Rq   R{   Ru   R   R   R0  R   t   pop(   RG   R  R}  t	   keylengtht   filsR^   R   R   R   RL  t   lenbndt   splitsR   R   t   oldmsg(    (   RK  s   WHATauto.pyR  
  sP    
	( L
#$&-N(D   RK   RL   R  RH   R   R   R   RV  R   Rs  R  R  R  R  R  R  R  R0  R  R  R  R   R  R  R  R[  R]  RY  RZ  Ra  R^  R`  R_  Ri  Rb  R\  Rc  Rd  Re  Rg  Rw  R  R  R  R   R  R  R  R  R  R  R  R  R  R  R  R  R  R	  R
  R  R  R  R  R  R  R  R  (    (    (    s   WHATauto.pyR     s   	I				)	L		*	o		H	d															d			.							%				6												.										
t   __main__(=   t
   __future__R    R   RB   t   globalsR   R3   R   R{  R   R   R  R   t   BaseHTTPServerR   R   t   SocketServerR   R)   R=   R   R   Ra   R&   R)  R  R  R   R  Rt  R   R  R<   R9   R1   RE   R   R   R   R2   R%   R   R7   R   R(   R   R   R  R-  R  R   R?  t   HTTPRedirectHandlerRg  R.  R/  R.   R  R  R   RK   (    (    (    s   WHATauto.pyt   <module>   s^   		6					
	:		#	P-		W		X      