# Protection, NoAds
# Edited by nukie - http://nukie.front.ru/

set noads(reason) "\[4x]: advertisement detected"
set noads(scriptad) "\[4x]: script advertisement detected"
set noads(invitemass) "\[4x]: inviter/mass msg script detected"
set noads(bantime) "14400"

set noads(list) {
 {copy at http}
 {come to http}
 {please join #}
 {venez su #}
 {tous pour*#}
 {intrati pe #}
 {entrem no #}
 {join #}
 { come to #}
 {cojan pa #}
 {elate #}
 {goto #}
 {go to #}
 {elate #}
 {visit #}
 {visit www.}
 {gelrimisin #}
 {vener #}
 { pe #}
 { kom til #}
 { eller #}
 { sur #}
 { come 2 #}
 { på #}
 { stous #}
 { venez a #}
 {elate #}
 { in til #}
 { come on #}
 { entren a #}
 { INN PÅ #}
 { click #}
 {nueva web}
 {Get it at http}
 {#* are trivia}
 {tambien en #}
 {#* svp}
 {vener*#}
 {follow me to*#}
 {follow me to*http}
 {follow me to*www.}
}

set noads(scripts) {
 {is using}
 {this is* by}
 {i'm using}
 {i`m using}
 {get it at}
 {v*. * for * * by}
 {get the script}
 {www.scoopsite.com}
 {http://ztolerance.cjb.net}
}

bind pubm - "% % *#*" pub_noads
bind pubm - "% % *www*" pub_noads
bind pubm - "% % *http*" pub_noads

bind notc - "*#*" notice_noads
bind notc - "*www*" notice_noads
bind notc - "*httpd*" notice_noads

proc notice_noads {nick uhost hand text dest} {
 pub_noads $nick $uhost $hand $dest $text
}

bind ctcp - ACTION action_noads
proc action_noads {nick uhost hand chan key text} {
 global noads
 set text2 [strip:all [string tolower $text]]

 if {[regexp "#" " $text2 "]} {pub_noads $nick $uhost $hand $chan $text}
 if {[regexp "www" " $text2 "]} {pub_noads $nick $uhost $hand $chan $text}
 if {[regexp "http" " $text2 "]} {pub_noads $nick $uhost $hand $chan $text}

 set anum 0
 set noadl 0
 foreach aline $noads(scripts) {
  set anum [expr $anum + 1]
  if {[string match -nocase "*$aline*" "$text2"] > 0 } {set noadl $anum}
                            }
 if {$noadl > 0} {auto_noadsban $chan $nick $uhost $hand $noads(scriptad)}

 return 0
}

bind pubm - "*SkyVodka*" auto_noadsbanM
bind notc - "*SkyVodka*" auto_noadsbanN
bind pubm - "*INVITER by SoulNet*" auto_noadsbanM
bind notc - "*INVITER by SoulNet*" auto_noadsbanN
bind pubm - "*Kreshna*" auto_noadsbanM
bind notc - "*Kreshna*" auto_noadsbanN
bind pubm - "*Mass Message*" auto_noadsbanM
bind notc - "*Mass Message*" auto_noadsbanN

proc auto_noadsbanN {nick uhost hand text dest} {global noads
                                                 auto_noadsban $chan $nick $uhost $hand $noads(invitemass)}
proc auto_noadsbanM {nick uhost hand chan rest} {global noads
                                                 auto_noadsban $chan $nick $uhost $hand $noads(invitemass)}

proc auto_noadsban {$chan nick uhost hand reason} {
 global noads
 if {([matchattr $hand b])} {return 0}
 if {([matchattr $hand o]) || ([matchchanattr $hand o $chan])} {return 0}
 if {([matchattr $hand f]) || ([matchchanattr $hand f $chan])} {return 0}
 if {[isop $nick $chan]} {return 0}
 set sitemask "*!*[string trimleft [strictmaskhost $nick $chan] *!]"
 newban $sitemask NoAdsAuto $reason $noads(bantime)
}

proc pub_noads {nick uhost hand chan rest} {
 global noads
 if {([matchattr $hand b])} {return 0}
 if {([matchattr $hand o]) || ([matchchanattr $hand o $chan])} {return 0}
 if {([matchattr $hand f]) || ([matchchanattr $hand f $chan])} {return 0}
 if {[isop $nick $chan]} {return 0}

set noadl 0
set rest [strip:all $rest]
if {([string index [lindex $rest 3] 0] == "#") &&
    ([lindex $rest 4] == [lindex $rest 3]) &&
    ([lindex $rest 5] == [lindex $rest 4])} {set noadl 100}

set lastword [llength $rest]
if {([string index [lindex $rest $lastword] 0] == "#") &&
    ([lindex $rest $lastword] == [lindex $rest [expr $lastword - 1]]) &&
    ([lindex $rest [expr $lastword - 1]] == [lindex $rest [expr $lastword - 2]])} {set noadl 100}

if {([llength $rest] == 1) && ([string index [lindex $rest 0] 0] == "#") && ($rest != [string tolower $chan])} {set noadl 101}

 set anum 0
 foreach aline $noads(list) {
  set anum [expr $anum + 1]
  if {[regexp "$aline" " $rest "]} {set noadl $anum}
                            }

if {$noadl > 0} {
 set sitemask "*!*[string trimleft [strictmaskhost $nick $chan] *!]"
putserv "privmsg #nukie :\[4x]: banned $sitemask"
 newban $sitemask NoAds $noads(reason) $noads(bantime)
                }

}

proc strip:color {ar} {
 set argument ""
 if {![string match *^C* $ar]} {return $ar} ; set i -1 ; set length [string length $ar]
 while {$i < $length} {
  if {[string index $ar $i] == "^C"} {
   set wind 1 ; set pos [expr $i+1]
   while {$wind < 3} {
    if {[string index $ar $pos] <= 9 && [string index $ar $pos] >= 0} {
     incr wind 1 ; incr pos 1} {set wind 3
    }
   }
   if {[string index $ar $pos] == "," && [string index $ar [expr $pos + 1]] <= 9 &&
       [string index $ar [expr $pos + 1]] >= 0} {
    set wind 1 ; incr pos 1
    while {$wind < 3} {
     if {[string index $ar $pos] <= 9 && [string index $ar $pos] >= 0} {
      incr wind 1 ; incr pos 1} {set wind 3
     }
    }
   }
   if {$i == 0} {
    set ar [string range $ar $pos end]
    set length [string length $ar]
   } {
    set ar "[string range $ar 0 [expr $i - 1]][string range $ar $pos end]"
    set length [string length $ar]
   }
   set argument "$argument[string index $ar $i]"
  } {incr i 1}
 }
 set argument $ar
 return $argument
}
proc strip:bold {ar} {
 set argument ""
 if {[string match *^B* $ar]} {
  set i 0
  while {$i <= [string length $ar]} {
   if {![string match ^B [string index $ar $i]]} {
    set argument "$argument[string index $ar $i]"
   }
   incr i 1
  }
 } { set argument $ar }
 return $argument
}
proc strip:uline {ar} {
 set argument ""
 if {[string match *^_* $ar]} {
  set i 0
  while {$i <= [string length $ar]} {
   if {![string match ^_ [string index $ar $i]]} {
    set argument "$argument[string index $ar $i]"
   }
   incr i 1
  }
 } { set argument $ar }
 return $argument
}
proc strip:reverse {ar} {
 set argument ""
 if {[string match *^V* $ar]} {
  set i 0
  while {$i <= [string length $ar]} {
   if {![string match ^V [string index $ar $i]]} {
    set argument "$argument[string index $ar $i]"
   }
   incr i 1
  }
 } { set argument $ar }
 return $argument
}

proc strip:all {ar} {
 return [strip:reverse [strip:uline [strip:bold [strip:color $ar]]]]
}

putlog "\[4x]: Protection, Advertisement Kick. Loaded."
return "\[4x]: Protection, Advertisement Kick. Loaded."