
äūTē  c               @   sq   d  Z  d d l Z d d l Z d d l Z d d l Z e j Z Gd d   d e  Z d d   Z	 d d   Z
 d S(	   up   
command class definition - do not confuse this with
the individual plugins in plugins/
by Sam van Kampen, 2013
i    Nc             B   s   |  Ee  Z d  Z d Z d d d d  Z d d   Z d d   Z d d	   Z d
 d   Z	 d d   Z
 d d   Z d d d  Z d S(   u   CommanduE   Command(Object function, List<str> hooks=[], List<str> shorthooks=[])c             C   s   | |  _  d  |  _ | s! g  } n  | s0 g  } n  t |  |  _ t |  |  _ | rd | d |  _ n	 d  |  _ t | d  r | j |  _ n  d  S(   Ni    u   _regex(	   u   functionu   Noneu   regexu   setu   hooksu   short_hooksu	   main_hooku   hasattru   _regex(   u   selfu   functionu   hooksu
   shorthooks(    (    u'   /home/sam/Code/Infobot/utils/command.pyu   __init__   s    					u   Command.__init__c             C   s=   |  j  d  k r# d |  j |  j  f Sd |  j |  j |  j f S(   Nu   Command(%r, regex=%r)u$   Command(%r, hooks=%r, shorthooks=%r)(   u   regexu   Noneu   functionu   hooksu   short_hooks(   u   self(    (    u'   /home/sam/Code/Infobot/utils/command.pyu   __repr__    s    u   Command.__repr__c             G   s   |  j  |   S(   u+    Call the function embedded in the command (   u   function(   u   selfu   args(    (    u'   /home/sam/Code/Infobot/utils/command.pyu   __call__%   s    u   Command.__call__c             C   s   |  j  S(   u-   Get the function associated with this command(   u   function(   u   self(    (    u'   /home/sam/Code/Infobot/utils/command.pyu   get_function)   s    u   Command.get_functionc             C   s   | |  _  d S(   u    Set the hooks. N(   u   hooks(   u   selfu   hooks(    (    u'   /home/sam/Code/Infobot/utils/command.pyu	   set_hooks-   s    u   Command.set_hooksc             C   s   | |  _  d S(   u    Set the shorthook(s) N(   u   short_hooks(   u   selfu   hooks(    (    u'   /home/sam/Code/Infobot/utils/command.pyu   set_shorthooks1   s    u   Command.set_shorthooksc             C   s   t  j |  j | d t  j S(   Nu   flags(   u   reu   matchu   regexu   I(   u   selfu   msg(    (    u'   /home/sam/Code/Infobot/utils/command.pyu   is_re_triggered_by5   s    u   Command.is_re_triggered_byc             C   sV   |  j  r |  j |  j Br d S| r; | |  j k r7 d Sd S| |  j k rN d Sd Sd S(   u4   Check whether this command is triggered by <trigger>NFT(   u   regexu   hooksu   short_hooksu   Falseu   True(   u   selfu   triggeru   short(    (    u'   /home/sam/Code/Infobot/utils/command.pyu   is_triggered_by8   s
    u   Command.is_triggered_byNF(   u   __name__u
   __module__u   __qualname__u   __doc__u   Noneu   __init__u   __repr__u   __call__u   get_functionu	   set_hooksu   set_shorthooksu   is_re_triggered_byu   Falseu   is_triggered_by(   u
   __locals__(    (    u'   /home/sam/Code/Infobot/utils/command.pyu   Command   s   u   Commandc             C   s  g  } d } t |   t t j t  k r7 |  g }  n  yŠ xĢ |  D] } x d d   | j j   D D]t } t | d  r d } t	 | | j
  } n  t | d  rž | rž | j | j  n  | rd | j |  d } qd qd WqA WWn t k
 rĸ t j   Yn X| S(   u.   Turn a list of plugins into a list of commandsc             S   s(   g  |  ] } t  |  t k r |  q S(    (   u   typeu   ftype(   u   .0u   func(    (    u'   /home/sam/Code/Infobot/utils/command.pyu
   <listcomp>J   s   	 u'   plugins_to_commands.<locals>.<listcomp>u   hooku	   shorthookFT(   u   Falseu   typeu   sysu   modulesu   __name__u   __dict__u   valuesu   hasattru   Trueu   Commandu   hooku   set_shorthooksu	   shorthooku   appendu   BaseExceptionu	   tracebacku	   print_exc(   u   pluginsu   commandsu   has_hooku   pluginu   functionu   new_command(    (    u'   /home/sam/Code/Infobot/utils/command.pyu   plugins_to_commandsB   s$    #u   plugins_to_commandsc             C   sŦ   g  } t  |   t  t j t  k r1 |  g }  n  yW xP |  D]H } x? t t | j j    D]% } t | d  rZ | j	 |  qZ qZ Wq; WWn t
 k
 rĶ t j   Yn X| S(   u2   Turn a list of plugins into a list of initializersu   _is_plugin_initializer(   u   typeu   sysu   modulesu   __name__u   filteru   callableu   __dict__u   valuesu   hasattru   appendu   BaseExceptionu	   tracebacku	   print_exc(   u   pluginsu   initializersu   pluginu   function(    (    u'   /home/sam/Code/Infobot/utils/command.pyu   plugins_to_initializersY   s    u   plugins_to_initializers(   u   __doc__u   sysu	   tracebacku   reu   typesu   FunctionTypeu   ftypeu   objectu   Commandu   plugins_to_commandsu   plugins_to_initializers(    (    (    u'   /home/sam/Code/Infobot/utils/command.pyu   <module>   s   	4