<s> from __future__ import unicode_literals <EOL> from datetime import datetime <EOL> from irc3 . compat import Queue <EOL> from irc3 . compat import QueueFull <EOL> import irc3 <EOL> __doc__ = '''<STR_LIT>''' <EOL> @ irc3 . plugin <EOL> class CTCP ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , bot ) : <EOL> maxsize = int ( bot . config . get ( '<STR_LIT>' , <NUM_LIT:3> ) ) <EOL> self . queue = Queue ( loop = bot . loop , maxsize = maxsize ) <EOL> self . handle = None <EOL> self . event = irc3 . event ( irc3 . rfc . CTCP , self . on_ctcp ) <EOL> bot . attach_events ( self . event ) <EOL> self . bot = bot <EOL> def clear_queue ( self ) : <EOL> self . bot . log . info ( '<STR_LIT>' ) <EOL> while not self . queue . empty ( ) : <EOL> self . queue . get_nowait ( ) <EOL> self . handle = None <EOL> def handle_flood ( self ) : <EOL> self . bot . log . warn ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . bot . detach_events ( self . event ) <EOL> self . bot . loop . call_later ( <NUM_LIT:30> , self . bot . attach_events , self . event ) <EOL> def on_ctcp ( self , mask = None , target = None , ctcp = None , ** kw ) : <EOL> lctcp = ctcp . split ( '<STR_LIT:U+0020>' ) [ <NUM_LIT:0> ] . lower ( ) <EOL> if lctcp in self . bot . config . ctcp : <EOL> try : <EOL> self . queue . put_nowait ( ( mask . nick , lctcp ) ) <EOL> except QueueFull : <EOL> self . handle_flood ( ) <EOL> else : <EOL> if self . handle is None : <EOL> self . handle = self . bot . loop . call_later ( <NUM_LIT:1> , self . clear_queue ) <EOL> data = self . bot . config . ctcp [ lctcp ] . format ( now = datetime . now ( ) , <EOL> ** self . bot . config ) <EOL> self . bot . ctcp_reply ( mask . nick , '<STR_LIT>' % ( lctcp . upper ( ) , data ) ) </s>
