<s> import inspect , sys , os , types , time , string <EOL> bad_word_dict = { } <EOL> bad_site_list = [ ] <EOL> chars = string . ascii_letters + string . digits <EOL> def _update_lists ( ) : <EOL> try : <EOL> global bad_word_dict <EOL> bad_word_dict = { } <EOL> f = open ( '<STR_LIT>' , '<STR_LIT:r>' ) <EOL> for line in f . readlines ( ) : <EOL> line = line . strip ( ) <EOL> if not line : continue <EOL> if line . count ( '<STR_LIT:U+0020>' ) < <NUM_LIT:1> : <EOL> bad_word_dict [ line ] = '<STR_LIT>' <EOL> else : <EOL> sline = line . split ( '<STR_LIT:U+0020>' , <NUM_LIT:1> ) <EOL> bad_word_dict [ sline [ <NUM_LIT:0> ] ] = '<STR_LIT:U+0020>' . join ( sline [ <NUM_LIT:1> : ] ) <EOL> f . close ( ) <EOL> except Exception as e : <EOL> print ( '<STR_LIT>' % ( e ) ) <EOL> try : <EOL> global bad_site_list <EOL> bad_site_list = [ ] <EOL> f = open ( '<STR_LIT>' , '<STR_LIT:r>' ) <EOL> for line in f . readlines ( ) : <EOL> line = line . strip ( ) <EOL> if not line : continue <EOL> if line in bad_site_list : <EOL> print ( "<STR_LIT>" % ( line ) ) <EOL> else : <EOL> bad_site_list . append ( line ) <EOL> f . close ( ) <EOL> except Exception as e : <EOL> print ( '<STR_LIT>' % ( e ) ) <EOL> _update_lists ( ) <EOL> def _process_word ( word ) : <EOL> if word == word . upper ( ) : uppercase = True <EOL> else : uppercase = False <EOL> lword = word . lower ( ) <EOL> if lword in bad_word_dict : <EOL> word = bad_word_dict [ lword ] <EOL> if uppercase : word = word . upper ( ) <EOL> return word <EOL> def _nasty_word_censor ( msg ) : <EOL> msg = msg . lower ( ) <EOL> for word in bad_word_dict . keys ( ) : <EOL> if word . lower ( ) in msg : return False <EOL> return True <EOL> def _word_censor ( msg ) : <EOL> words = [ ] <EOL> word = '<STR_LIT>' <EOL> letters = True <EOL> for letter in msg : <EOL> if bool ( letter in chars ) == bool ( letters ) : word += letter <EOL> else : <EOL> letters = not bool ( letters ) <EOL> words . append ( word ) <EOL> word = letter <EOL> words . append ( word ) <EOL> newmsg = [ ] <EOL> for word in words : <EOL> newmsg . append ( _process_word ( word ) ) <EOL> return '<STR_LIT>' . join ( newmsg ) <EOL> def _site_censor ( msg ) : <EOL> testmsg1 = '<STR_LIT>' <EOL> testmsg2 = '<STR_LIT>' <EOL> for letter in msg : <EOL> if not letter : continue <EOL> if letter . isalnum ( ) : <EOL> testmsg1 += letter <EOL> testmsg2 += letter <EOL> elif letter in '<STR_LIT>' : <EOL> testmsg2 += letter <EOL> for site in bad_site_list : <EOL> if site in msg or site in testmsg1 or site in testmsg2 : <EOL> return <EOL> return msg <EOL> def _spam_enum ( client , chan ) : <EOL> now = time . time ( ) <EOL> bonus = <NUM_LIT:0> <EOL> already = [ ] <EOL> times = [ now ] <EOL> for when in dict ( client . lastsaid [ chan ] ) : <EOL> t = float ( when ) <EOL> if t > now - <NUM_LIT:5> : <EOL> for message in client . lastsaid [ chan ] [ when ] : <EOL> times . append ( t ) <EOL> if message in already : <EOL> bonus += <NUM_LIT:2> * already . count ( message ) <EOL> if len ( message ) > <NUM_LIT:50> : <EOL> bonus += min ( len ( message ) , <NUM_LIT:200> ) * <NUM_LIT> <EOL> bonus += <NUM_LIT:1> <EOL> already . append ( message ) <EOL> else : del client . lastsaid [ chan ] [ when ] <EOL> times . sort ( ) <EOL> last_time = None <EOL> for t in times : <EOL> if last_time : <EOL> diff = t - last_time <EOL> if diff < <NUM_LIT:1> : <EOL> bonus += ( <NUM_LIT:1> - diff ) * <NUM_LIT> <EOL> last_time = t <EOL> if bonus > <NUM_LIT:7> : return True <EOL> else : return False <EOL> def _spam_rec ( client , chan , msg ) : <EOL> now = str ( time . time ( ) ) <EOL> if not chan in client . lastsaid : client . lastsaid [ chan ] = { } <EOL> if not now in client . lastsaid [ chan ] : <EOL> client . lastsaid [ chan ] [ now ] = [ msg ] <EOL> else : <EOL> client . lastsaid [ chan ] [ now ] . append ( msg ) <EOL> def hook_SAY ( self , client , channel , msg ) : <EOL> username = client . username <EOL> if channel . isMuted ( client ) : return msg <EOL> if channel . antispam and not channel . isOp ( client ) : <EOL> _spam_rec ( client , channel . name , msg ) <EOL> if _spam_enum ( client , channel . name ) : <EOL> channel . muteUser ( self . _root . chanserv , client , <NUM_LIT:15> ) <EOL> if channel . isMuted ( client ) : <EOL> channel . channelMessage ( '<STR_LIT>' % username ) <EOL> return '<STR_LIT>' <EOL> return msg <EOL> def hook_OPENBATTLE ( self , client , title ) : <EOL> title = _word_censor ( title ) <EOL> title = _site_censor ( title ) <EOL> return title </s>
