<s> import time <EOL> import supybot . conf as conf <EOL> import supybot . utils as utils <EOL> import supybot . ircdb as ircdb <EOL> from supybot . commands import * <EOL> import supybot . ircmsgs as ircmsgs <EOL> import supybot . plugins as plugins <EOL> import supybot . ircutils as ircutils <EOL> import supybot . callbacks as callbacks <EOL> from supybot . i18n import PluginInternationalization , internationalizeDocstring <EOL> _ = PluginInternationalization ( '<STR_LIT>' ) <EOL> @ internationalizeDocstring <EOL> class NickAuth ( callbacks . Plugin ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , irc ) : <EOL> super ( NickAuth , self ) . __init__ ( irc ) <EOL> self . _requests = { } <EOL> class nick ( callbacks . Commands ) : <EOL> def _check_auth ( self , irc , msg , user ) : <EOL> if user is None : <EOL> irc . error ( _ ( '<STR_LIT>' ) , Raise = True ) <EOL> if not user . checkHostmask ( msg . prefix ) : <EOL> try : <EOL> u = ircdb . users . getUser ( msg . prefix ) <EOL> except KeyError : <EOL> irc . error ( _ ( '<STR_LIT>' ) , <EOL> Raise = True ) <EOL> if not u . _checkCapability ( '<STR_LIT>' ) : <EOL> irc . error ( _ ( '<STR_LIT>' ) , <EOL> Raise = True ) <EOL> @ internationalizeDocstring <EOL> def add ( self , irc , msg , args , network , user , nick ) : <EOL> """<STR_LIT>""" <EOL> network = network . network or irc . network <EOL> user = user or ircdb . users . getUser ( msg . prefix ) <EOL> self . _check_auth ( irc , msg , user ) <EOL> try : <EOL> user . addNick ( network , nick ) <EOL> except KeyError : <EOL> irc . error ( _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , Raise = True ) <EOL> irc . replySuccess ( ) <EOL> add = wrap ( add , [ optional ( '<STR_LIT>' ) , <EOL> optional ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' ] ) <EOL> @ internationalizeDocstring <EOL> def remove ( self , irc , msg , args , network , user , nick ) : <EOL> """<STR_LIT>""" <EOL> network = network . network or irc . network <EOL> user = user or ircdb . users . getUser ( msg . prefix ) <EOL> self . _check_auth ( irc , msg , user ) <EOL> try : <EOL> user . removeNick ( network , nick ) <EOL> except KeyError : <EOL> irc . error ( _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , Raise = True ) <EOL> irc . replySuccess ( ) <EOL> remove = wrap ( remove , [ optional ( '<STR_LIT>' ) , <EOL> optional ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' ] ) <EOL> @ internationalizeDocstring <EOL> def list ( self , irc , msg , args , network , user ) : <EOL> """<STR_LIT>""" <EOL> network = network . network or irc . network <EOL> try : <EOL> user = user or ircdb . users . getUser ( msg . prefix ) <EOL> except KeyError : <EOL> irc . error ( _ ( '<STR_LIT>' ) , <EOL> Raise = True ) <EOL> self . _check_auth ( irc , msg , user ) <EOL> try : <EOL> list_ = user . nicks [ network ] <EOL> if list_ : <EOL> irc . reply ( format ( '<STR_LIT>' , list_ ) ) <EOL> else : <EOL> raise KeyError <EOL> except KeyError : <EOL> if user == ircdb . users . getUser ( msg . prefix ) : <EOL> irc . error ( _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , Raise = True ) <EOL> else : <EOL> irc . error ( _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % user . name , Raise = True ) <EOL> list = wrap ( list , [ optional ( '<STR_LIT>' ) , <EOL> optional ( '<STR_LIT>' ) ] ) <EOL> @ internationalizeDocstring <EOL> def auth ( self , irc , msg , args ) : <EOL> """<STR_LIT>""" <EOL> nick = ircutils . toLower ( msg . nick ) <EOL> self . _requests [ ( irc . network , msg . nick ) ] = ( time . time ( ) , msg . prefix , irc ) <EOL> irc . queueMsg ( ircmsgs . whois ( nick , nick ) ) <EOL> auth = wrap ( auth , [ ] ) <EOL> def inFilter ( self , irc , msg ) : <EOL> """<STR_LIT>""" <EOL> if msg . server_tags and '<STR_LIT>' in msg . server_tags : <EOL> self . _auth ( irc , msg . prefix , msg . server_tags [ '<STR_LIT>' ] ) <EOL> return msg <EOL> def do330 ( self , irc , msg ) : <EOL> mynick , theirnick , theiraccount , garbage = msg . args <EOL> self . _requests = dict ( [ ( x , y ) for x , y in self . _requests . items ( ) <EOL> if y [ <NUM_LIT:0> ] + <NUM_LIT> > time . time ( ) ] ) <EOL> try : <EOL> ( timestamp , prefix , irc ) = self . _requests . pop ( ( irc . network , theirnick ) ) <EOL> except KeyError : <EOL> return <EOL> user = ircdb . users . getUserFromNick ( irc . network , theiraccount ) <EOL> if not user : <EOL> user = ircdb . users . getUserFromNick ( irc . network , theirnick ) <EOL> if user : <EOL> try : <EOL> user . addAuth ( prefix ) <EOL> except ValueError : <EOL> irc . error ( _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> Raise = True ) <EOL> ircdb . users . setUser ( user , flush = False ) <EOL> irc . reply ( _ ( '<STR_LIT>' ) % user . name ) <EOL> else : <EOL> irc . error ( _ ( '<STR_LIT>' ) ) <EOL> def doAccount ( self , irc , msg ) : <EOL> account = msg . args [ <NUM_LIT:0> ] <EOL> user = ircdb . users . getUserFromNick ( irc . network , account ) <EOL> if account != '<STR_LIT:*>' : <EOL> self . _auth ( irc , msg . prefix , account ) <EOL> def doJoin ( self , irc , msg ) : <EOL> if len ( msg . args ) < <NUM_LIT:2> : <EOL> return <EOL> account = msg . args [ <NUM_LIT:1> ] <EOL> if account != '<STR_LIT:*>' : <EOL> self . _auth ( irc , msg . prefix , account ) <EOL> def do354 ( self , irc , msg ) : <EOL> if len ( msg . args ) != <NUM_LIT:6> or msg . args [ <NUM_LIT:1> ] != '<STR_LIT:1>' : <EOL> return <EOL> ( __ , ___ , ident , host , nick , account ) = msg . args <EOL> prefix = '<STR_LIT>' % ( nick , ident , host ) <EOL> user = ircdb . users . getUserFromNick ( irc . network , account ) <EOL> if account != '<STR_LIT:0>' : <EOL> self . _auth ( irc , prefix , account ) <EOL> def _auth ( self , irc , prefix , account ) : <EOL> user = ircdb . users . getUserFromNick ( irc . network , account ) <EOL> if not user : <EOL> try : <EOL> user = ircdb . users . getUser ( prefix ) <EOL> except KeyError : <EOL> user = None <EOL> if user : <EOL> user . addAuth ( prefix ) <EOL> ircdb . users . setUser ( user , flush = False ) <EOL> Class = NickAuth </s>
