<s> import time <EOL> import supybot . conf as conf <EOL> import supybot . utils as utils <EOL> from supybot . commands import * <EOL> import supybot . ircmsgs as ircmsgs <EOL> import supybot . ircutils as ircutils <EOL> import supybot . schedule as schedule <EOL> import supybot . callbacks as callbacks <EOL> from supybot . i18n import PluginInternationalization , internationalizeDocstring <EOL> _ = PluginInternationalization ( '<STR_LIT>' ) <EOL> class Ctcp ( callbacks . PluginRegexp ) : <EOL> """<STR_LIT>""" <EOL> public = False <EOL> regexps = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , irc ) : <EOL> self . __parent = super ( Ctcp , self ) <EOL> self . __parent . __init__ ( irc ) <EOL> self . ignores = ircutils . IrcDict ( ) <EOL> self . floods = ircutils . FloodQueue ( conf . supybot . abuse . flood . interval ( ) ) <EOL> conf . supybot . abuse . flood . interval . addCallback ( self . setFloodQueueTimeout ) <EOL> def setFloodQueueTimeout ( self , * args , ** kwargs ) : <EOL> self . floods . timeout = conf . supybot . abuse . flood . interval ( ) <EOL> def callCommand ( self , command , irc , msg , * args , ** kwargs ) : <EOL> if conf . supybot . abuse . flood . ctcp ( ) : <EOL> now = time . time ( ) <EOL> for ( ignore , expiration ) in self . ignores . items ( ) : <EOL> if expiration < now : <EOL> del self . ignores [ ignore ] <EOL> elif ircutils . hostmaskPatternEqual ( ignore , msg . prefix ) : <EOL> return <EOL> self . floods . enqueue ( msg ) <EOL> max = conf . supybot . abuse . flood . ctcp . maximum ( ) <EOL> if self . floods . len ( msg ) > max : <EOL> expires = conf . supybot . abuse . flood . ctcp . punishment ( ) <EOL> self . log . warning ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> msg . prefix , expires ) <EOL> ignoreMask = '<STR_LIT>' % ( msg . user , msg . host ) <EOL> self . ignores [ ignoreMask ] = now + expires <EOL> return <EOL> self . __parent . callCommand ( command , irc , msg , * args , ** kwargs ) <EOL> def _reply ( self , irc , msg , s ) : <EOL> s = '<STR_LIT>' % s <EOL> irc . reply ( s , notice = True , private = True , to = msg . nick ) <EOL> def ctcpPing ( self , irc , msg , match ) : <EOL> "<STR_LIT>" <EOL> self . log . info ( '<STR_LIT>' , msg . prefix ) <EOL> payload = match . group ( <NUM_LIT:1> ) <EOL> if payload : <EOL> self . _reply ( irc , msg , '<STR_LIT>' % match . group ( <NUM_LIT:1> ) ) <EOL> else : <EOL> self . _reply ( irc , msg , '<STR_LIT>' ) <EOL> def ctcpVersion ( self , irc , msg , match ) : <EOL> "<STR_LIT>" <EOL> self . log . info ( '<STR_LIT>' , msg . prefix ) <EOL> self . _reply ( irc , msg , '<STR_LIT>' % conf . version ) <EOL> def ctcpUserinfo ( self , irc , msg , match ) : <EOL> "<STR_LIT>" <EOL> self . log . info ( '<STR_LIT>' , msg . prefix ) <EOL> self . _reply ( irc , msg , '<STR_LIT>' % self . registryValue ( '<STR_LIT>' ) ) <EOL> def ctcpTime ( self , irc , msg , match ) : <EOL> "<STR_LIT>" <EOL> self . log . info ( '<STR_LIT>' , msg . prefix ) <EOL> self . _reply ( irc , msg , '<STR_LIT>' % time . ctime ( ) ) <EOL> def ctcpFinger ( self , irc , msg , match ) : <EOL> "<STR_LIT>" <EOL> self . log . info ( '<STR_LIT>' , msg . prefix ) <EOL> self . _reply ( irc , msg , '<STR_LIT>' + <EOL> _ ( '<STR_LIT>' ) ) <EOL> def ctcpSource ( self , irc , msg , match ) : <EOL> "<STR_LIT>" <EOL> self . log . info ( '<STR_LIT>' , msg . prefix ) <EOL> self . _reply ( irc , msg , <EOL> '<STR_LIT>' ) <EOL> def doNotice ( self , irc , msg ) : <EOL> if ircmsgs . isCtcp ( msg ) : <EOL> try : <EOL> ( version , payload ) = msg . args [ <NUM_LIT:1> ] [ <NUM_LIT:1> : - <NUM_LIT:1> ] . split ( None , <NUM_LIT:1> ) <EOL> except ValueError : <EOL> return <EOL> if version == '<STR_LIT>' : <EOL> self . versions . setdefault ( payload , [ ] ) . append ( msg . nick ) <EOL> @ internationalizeDocstring <EOL> def version ( self , irc , msg , args , channel , optlist ) : <EOL> """<STR_LIT>""" <EOL> self . versions = ircutils . IrcDict ( ) <EOL> nicks = False <EOL> for ( option , arg ) in optlist : <EOL> if option == '<STR_LIT>' : <EOL> nicks = True <EOL> irc . queueMsg ( ircmsgs . privmsg ( channel , '<STR_LIT>' ) ) <EOL> def doReply ( ) : <EOL> if self . versions : <EOL> L = [ ] <EOL> for ( reply , nickslist ) in self . versions . items ( ) : <EOL> if nicks : <EOL> L . append ( format ( '<STR_LIT>' , nickslist , reply ) ) <EOL> else : <EOL> L . append ( reply ) <EOL> irc . reply ( format ( '<STR_LIT>' , L ) ) <EOL> else : <EOL> irc . reply ( '<STR_LIT>' ) <EOL> wait = self . registryValue ( '<STR_LIT>' ) <EOL> schedule . addEvent ( doReply , time . time ( ) + wait ) <EOL> version = wrap ( version , [ '<STR_LIT>' , getopts ( { '<STR_LIT>' : '<STR_LIT>' } ) ] ) <EOL> Class = Ctcp </s>
