; This is the second group which is disabled when join flood is detected
#CPSGROUP2 on

; Channel action event
ON @*:ACTION:*:#: {
  IF ($istok(%controlchan,$chan,44) == $true) { .signal action.channel $chan $nick $1- }
}

; Drone bot kick routine signal
ON @*:JOIN:#:{
  IF (($istok(%controlchan,$chan,44) == $true) && ($nick != $me)) { .signal join.drone $chan $nick }
}

; Channel notice protection
ON *:NOTICE:*:#:{
  IF (($isservice($nick) != $true) && ($istok(%controlchan,$chan,44) == $true)) {
    IF ((@+ !isin $target) || (@ !isin $target) || (+ !isin $target)) {
      .signal channel.notice $chan $nick $1- 
    }
  }
}

; bad|blacklisted|guest nick checker when the nick changes
ON *:NICK: { .signal bad.nick $nick $newnick }

; Spam detector signal
; Query blocker
ON *:OPEN:?: {
  .signal private.spam $nick $wildsite $1-
  .signal query.block $nick $fulladdress $1-
} 
; Channel notice kicker
ON *:SIGNAL:CHANNEL.NOTICE: {
  IF (($cps.rval($1,N3,5) == 1) && ($istok(%controlchan,$1,44) == $true)) {
    var %cnoter = $calc($cps.rvi($1,CNOTE) - 1)
    var %cnotef = $dll($airc,Flood,$+(notc,$chr(44),$2) 1 $cps.rvi($1,CNOTE) $cps.rvi($1,CNOTE.TIME))
    IF (($gettok(%cnotef,2,32) == $calc($cps.rvi($1,CNOTE) - 1)) && (%_cps.warn.channote == ON)) {
      set %_cpsextra $gettok(%cnotef,2,32) notices in $replace($duration($gettok(%cnotef,3,32)),0,1)
      warning $1 $2 cnote
      return
    }
    IF (($gettok(%cnotef,2,32) > $calc($cps.rvi($1,CNOTE) - 1)) && (%_cps.warn.channote == $null)) {
      set %_cpsextra $gettok(%cnotef,2,32) notices in $replace($duration($gettok(%cnotef,3,32)),0,1)
      thrash $1 $2 cnote
      return
    }
    IF ((+Flood* iswm %cnotef) && (%_cps.warn.channote == on)) {
      set %_cpsextra $gettok(%cnotef,2,32) notices in $replace($duration($gettok(%cnotef,3,32)),0,1)
      thrash $1 $2 cnote
      unset %modi
      IF (m !isin $chan($1).mode) { set %modi m }
      IF (i !isin $chan($1).mode) { set %modi $addtok(%modi,i,59) }
      IF (c !isin $chan($1).mode) { set %modi $addtok(%modi,c,59) }
      IF (%modi != $null) { .MODE $1 $+(+,$remove(%modi,;)) }
      IF (k !isin $chan($chan).mode) { .mode $1 +k $rand(1,9999) }
      .timerWHATEVER 1 60 moder $1
      return
    }
  }
}


ON *:SIGNAL:QUERY.BLOCK: {
  IF (($cps.rvi(default,queryb) == ON) && ($away == $false) && ($1 != -psyBNC)) {
    .msg $1 ::[:: Bitte warte. Ich prüfe ob Dein Query angenommen wird. Du wirst darüber dann entsprechend informiert. [Auto/Antwort] %bsver ::]::
    var %x = $2 wünscht ein Query mit Dir. Nachricht -> $3- 
    IF ($istok($cps.rvi(default,pps.ex),$1,59) != $true) {
      var %a = $input(%x,y,Klicke YES wenn Du es erlaubst) 
      IF (%a == $false) { 
        .msg $1 ::[:: Dein Nachricht wurde abgelehnt. Du wurdest nun im Query ignoriert. Spreche mich im Channel an. [Auto/Antwort] %bsver ::]::
        close -m $1
        .ignore -pu60 $1
        .silence $+(+,$1)
        .timerSIL [ $+ [ $1 ] ] 1 60 silence $+(-,$1)
      }
      IF (%a == $true) { .msg $1 ::[:: Dein Query wurde akzeptiert.[Auto/Antwort] %bsver ::]:: }
    }
    ELSE { .msg $1 ::[:: Dein Query wurde akzeptiert. [Auto/Antwort] %bsver ::]:: }
  }
}

; Channel action event this is almost the same as that of channel text event only it includes trout slap in it
ON *:SIGNAL:ACTION.CHANNEL: {
  IF ($owner($2) != $true) {
    ;repeat kicker
    IF ($cps.rval($1,N1,2) == 1) {
      var %_reps = $dll($airc,Flood,$+(rep,$2,$remove($strip($3-),$chr(32)),$1,$chr(44),$2) 1 $cps.rvi($1,REPEAT) $cps.rvi($1,REPEAT.TIME))
      IF (($gettok(%_reps,2,32) == $calc($cps.rvi($1,REPEAT) - 1)) && (%_cps.warn.repeat == ON)) {
        set %_cpsextra Du hast Dich $gettok(%_reps,2,32) wiederholt innerhalb $duration($gettok(%_reps,3,32))
        warning $1 $2 repeat
        return
      }
      IF (($gettok(%_reps,2,32) > $calc($cps.rvi($1,REPEAT) - 1)) && (%_cps.warn.repeat == $null)) {
        set %_cpsextra Du hast Dich $gettok(%_reps,2,32) wiederholt innerhalb $duration($gettok(%_reps,3,32))
        thrash $1 $2 repeat
        return
      }
      IF ((+flood* iswm %_reps) && (%_cps.warn.repeat == ON)) {
        set %_cpsextra Du hast Dich $gettok(%_reps,2,32) wiederholt innerhalb $duration($gettok(%_reps,3,32))
        thrash $1 $2 repeat
        return
      }
    }
    ; Swear kicker
    IF ($cps.rval($1,N1,1) == 1) {
      ; Striping colors
      var %ss = $strip($replace($3-,?,$chr(32),!,$chr(32),.,$chr(32)))
      ; Removing space
      var %ss = $remove(%ss,$chr(32))
      ; Changing ASCII letters to untreatable chars
      var %ss = $replace(%ss,$,s,0,o,1,i,3,e,4,a,@,a,¡,i,¢,c,£,l,¥,y,¦,l,§,s,©,c,ª,a,|,l,®,r,µ,u,À,a,Á,a,Â,a,Ã,a,Ä,a,Å,a,Æ,a,Ç,c,È,e,É,e,Ê,e,Ë,e,Ì,i,Í,i,Î,i,Ï,i,Ð,d,Ñ,n,Ò,o,Ó,o,Ô,o,Õ,o,Ö,o,×,x,Ø,o,Ù,u,Ú,u,Û,u,Ü,u,Ý,y,Þ,p,ß,b,à,a,á,a,â,a,ã,a,ä,a,å,a,æ,a,ç,c,è,e,é,e,ê,e,ë,e,ì,i,í,i,î,i,ï,i,ð,o,ñ,n,ò,o,ó,o,ô,o,õ,o,ö,o,ø,o,ù,u,ú,u,û,u,ü,u,ý,y,þ,p,ÿ,y)
      ; Filling up the dll
      var %_ss = $dll($airc, MatchTokString, $cps.rvi($1,SWEAR)) 
      ; Comparing strings
      var %_ss1 = $dll($airc, MatchTok, +r 59 %ss)
      ; +OK means a positive match 
      IF (+ok* iswm %_ss1) {
        set -u180 %rl.swear. [ $+ [ $address($2,2) ] ] $calc(%rl.swear. [ $+ [ $address($2,2) ] ] + 1)
        IF ((%rl.swear. [ $+ [ $address($2,2) ] ] == 1) && (%_cps.warn.swear == ON)) {
          set %_cpsextra Du hast folgendes geschrieben -> $gettok(%_ss1,2,32)
          warning $1 $2 swear
          return
        }
        IF ((%rl.swear. [ $+ [ $address($2,2) ] ] >= 1) && (%_cps.warn.swear == $null)) {
          set %_cpsextra Du hast folgendes geschrieben -> $gettok(%_ss1,2,32)
          thrash $1 $2 swear
          return
        }
        IF ((%rl.swear. [ $+ [ $address($2,2) ] ] >= 2) && (%_cps.warn.swear == ON)) {
          set %_cpsextra Du hast folgendes geschrieben -> $gettok(%_ss1,2,32)
          thrash $1 $2 swear
          return
        }
      }
    }
    ; Non letters kick
    IF ($cps.rval($1,N3,1) == 1) { nonlet $1 $2 $strip($3-) }
    ; Caps kicks
    IF ($cps.rval($1,N2,1) == 1) { caps $1 $2 $strip($3-) }
    ; Non-english or Arabic text kick
    IF ($cps.rval($1,N2,3) == 1) { noneng $1 $2 $strip($3-) }
    ; Long text kick
    IF ($cps.rval($1,N1,4) == 1) {
      IF ($len($3-) >= $cps.rvi($1,LONGTXT)) {
        set -u180 %rl.lt. [ $+ [ $address($2,2) ] ] $calc(%rl.lt. [ $+ [ $address($2,2) ] ] + 1)
        IF ((%rl.lt. [ $+ [ $address($2,2) ] ] == 1) && (%_cps.warn.long == ON)) {
          set %_cpsextra Du hast $len($3-) Buchstaben geschrieben, erlaubt sind $cps.rvi($1,LONGTXT)
          warning $1 $2 longtxt
          return
        }
        IF ((%rl.lt. [ $+ [ $address($2,2) ] ] >= 1) && (%_cps.warn.long == $null)) {
          set %_cpsextra Du hast $len($3-) Buchstaben geschrieben, erlaubt sind $cps.rvi($1,LONGTXT)
          thrash $1 $2 longtxt
          return
        }
        IF ((%rl.lt. [ $+ [ $address($2,2) ] ] >= 2) && (%_cps.warn.long == ON)) {
          set %_cpsextra Du hast $len($3-) Buchstaben geschrieben, erlaubt sind $cps.rvi($1,LONGTXT)
          thrash $1 $2 longtxt
        }
      }
    }
    ; Ctrl - codes or colors kick
    IF ($cps.rval($1,N2,2) == 1) {
      ; Counting the various ctrl codes one by one
      var %count = $count($3-,$chr(3))
      inc %count $count($3-,$chr(2))
      inc %count $count($3-,$chr(22))
      inc %count $count($3-,$chr(31))
      inc %count $count($3-,$chr(15))
      IF (%count >= $cps.rvi($1,COLORS)) {
        set -u180 %rl.col. [ $+ [ $address($2,2) ] ] $calc(%rl.col. [ $+ [ $address($2,2) ] ] + 1)
        IF ((%rl.col. [ $+ [ $address($2,2) ] ] == 1) && (%_cps.warn.colors == ON)) {
          set %_cpsextra Du hast %count Farben verwendet; erlaubt sind $cps.rvi($1,COLORS)
          warning $1 $2 colors
          return
        }
        IF ((%rl.col. [ $+ [ $address($2,2) ] ] >= 1) && (%_cps.warn.colors == $null)) {
          set %_cpsextra Du hast %count Farben verwendet; erlaubt sind $cps.rvi($1,COLORS)
          thrash $1 $2 colors
          return
        }
        IF ((%rl.col. [ $+ [ $address($2,2) ] ] >= 2) && (%_cps.warn.colors == ON)) {
          set %_cpsextra Du hast %count Farben verwendet; erlaubt sind $cps.rvi($1,COLORS)
          thrash $1 $2 colors
          return
        }
      }
    }
    ; Too many punctuations kick
    IF ($cps.rval($1,N1,5) == 1) {
      IF ($calc($count($3-,?) + $count($3-,!)) > $cps.rvi($1,Umwandlung)) {
        set -u180 %rl.pun. [ $+ [ $address($2,2) ] ] $calc(%rl.pun. [ $+ [ $address($2,2) ] ] + 1)
        IF ((%rl.pun. [ $+ [ $address($2,2) ] ] == 1) && (%_cps.warn.punctuation == ON)) {
          set %_cpsextra Du hast $calc($count($3-,?) + $count($3-,!)) Umwandlungen verwendet, erlaubt sind $cps.rvi($1,Umwandlungen)
          warning $1 $2 punctuation
          return
        }
        IF ((%rl.pun. [ $+ [ $address($2,2) ] ] >= 1) && (%_cps.warn.punctuation == $null)) {
          set %_cpsextra Du hast $calc($count($3-,?) + $count($3-,!)) Umwandlungen verwendet, erlaubt sind $cps.rvi($1,Umwandlungen)
          thrash $1 $2 punctuation
          return
        }
        IF ((%rl.pun. [ $+ [ $address($2,2) ] ] >= 2) && (%_cps.warn.punctuation == ON)) {
          set %_cpsextra Du hast $calc($count($3-,?) + $count($3-,!)) Umwandlungen verwendet, erlaubt sind $cps.rvi($1,Umwandlungen)
          thrash $1 $2 punctuation
          return
        }
      }
    }
    ; User exploiting kick
    IF ($cps.rval($1,N3,4) == 1) {
      var %_exp = $dll($airc, MatchTokString, */con/con*;*alt*f4*;*type*/exit*;*remove*.ini*;*join*0*0*;*type*/quit*;*type*/disconnect*;*hit*x*button*;*click*x*button*)
      var %_exp1 = $dll($airc, MatchTok, +r 59 $strip($3-))
      IF (+OK* iswm %_exp1) {
        set -u180 %rl.exp. [ $+ [ $address($2,2) ] ] $calc(%rl.exp. [ $+ [ $address($2,2) ] ] + 1)
        IF ((%rl.exp. [ $+ [ $address($2,2) ] ] == 1) && (%_cps.warn.user == ON)) {
          set %_cpsextra Du hast folgendes geschrieben -> $gettok(%_exp1,2,32)
          warning $1 $2 euser
          return
        }
        IF ((%rl.exp. [ $+ [ $address($2,2) ] ] >= 1) && (%_cps.warn.user == $null)) {
          set %_cpsextra Du hast folgendes geschrieben -> $gettok(%_exp1,2,32)
          thrash $1 $2 euser
          return
        }
        IF ((%rl.exp. [ $+ [ $address($2,2) ] ] >= 2) && (%_cps.warn.user == ON)) {
          set %_cpsextra Du hast folgendes geschrieben -> $gettok(%_exp1,2,32)
          thrash $1 $2 euser
          return
        }
      }
    }
    ; Sound play kick
    IF ($cps.rval($1,N3,2) == 1) {
      IF ((.MP3 isin $strip($3-)) || (.WAV isin $strip($3-)) || (BITRATE isin $strip($3-)) || (.WMA isin $strip($3-)) || (.MIDI isin $strip($3-))) {
        var %spll = $calc($cps.rvi($1,SOUND) + 1)
        set $+(-u,$cps.rvi($1,SOUND.TIME)) %fl.sound. [ $+ [ $1 ] $+ [ $2 ] ] $calc(%fl.sound. [ $+ [ $1 ] $+ [ $2 ] ] + 1)
        IF ((%fl.sound. [ $+ [ $1 ] $+ [ $2 ] ] == $cps.rvi($1,SOUND)) && (%_cps.warn.sound == ON)) {
          set %_cpsextra $1 Soundanzeige ist hier nicht erlaubt
          warning $1 $2 sounds
          return
        }
        IF ((%fl.sound. [ $+ [ $1 ] $+ [ $2 ] ] >= $cps.rvi($1,SOUND)) && (%_cps.warn.sound == $null)) {
          set %_cpsextra $1 Soundanzeige ist hier nicht erlaubt
          thrash $1 $2 sound
          return
        }
        IF ((%fl.sound. [ $+ [ $1 ] $+ [ $2 ] ] > $cps.rvi($1,SOUND)) && (%_cps.warn.sound == ON)) {
          set %_cpsextra $1 Soundanzeige ist hier nicht erlaubt
          thrash $1 $2 sound
          return
        }
      }
    }
    ; Away kicker
    IF ($cps.rval($1,N6,5) == 1) {
      var %_awad = $dll($airc, MatchTokString, *is*away*;*set*away*;*auto*away*;*i*m*away*;*is*back*time*;*log*ble*page*ble*;*page*ble*log*ble*;*log*o*page*o*;*page*o*log*o*)
      var %_awad1 = $dll($airc, MatchTok, +r 59 $strip($3-))
      IF (+OK* iswm %_awad1) {
        var %aw = $dll($airc,Flood,$+(AWAY,$chr(44),$2) 1 $cps.rvi($1,AWAY) $cps.rvi($1,AWAY.TIME))
        IF (($gettok(%aw,2,32) == $calc($cps.rvi($1,AWAY) - 1)) && (%_cps.warn.away == ON)) {
          set %_cpsextra $1 AWAY Nachricht Anzeige ist hier nicht erlaubt
          warning $1 $2 away
          return
        }
        IF (($gettok(%aw,2,32) => $cps.rvi($1,AWAY)) && (%_cps.warn.away == $null)) {
          set %_cpsextra $1 AWAY Nachricht Anzeige ist hier nicht erlaubt

          thrash $1 $2 away
          return
        }
        IF ((+Flood* iswm %aw) && (%_cps.warn.away == ON)) {
          set %_cpsextra $1 AWAY Nachricht Anzeige ist hier nicht erlaubt
          thrash $1 $2 away
          return
        }
      }
    }
    ; Text flood kicker
    IF ($cps.rval($1,N1,3) == 1) {
      var %_flood = $dll($airc, Flood, $+(textFloodl, $chr(44), $address($2,2)) 1 $cps.rvi($1,TXTFLOOD) $cps.rvi($1,TXTFLOOD.TIME))
      IF (($gettok(%_Flood,2,32) == $calc($cps.rvi($1,TXTFLOOD) - 1)) && (%_cps.warn.text == ON)) {
        set %_cpsextra Du schriebst $gettok(%_flood,2,32) Zeilen innerhalb $duration($gettok(%_flood,3,32))
        warning $1 $2 txtflood
        return
      }
      IF (($gettok(%_Flood,2,32) > $calc($cps.rvi($1,TXTFLOOD) - 1)) && (%_cps.warn.text == $null)) {
        set %_cpsextra Du schriebst $gettok(%_flood,2,32) Zeilen innerhalb $duration($gettok(%_flood,3,32))
        thrash $1 $2 txtflood
        return
      }
      IF ((+Flood* iswm %_Flood) && (%_cps.warn.text == ON)) {
        set %_cpsextra Du schriebst $gettok(%_flood,2,32) Zeilen innerhalb $duration($gettok(%_flood,3,32))
        thrash $1 $2 txtflood
        return
      }
    }
    ; URL advertising kick in a channel
    IF ($cps.rval($1,N2,4) == 1) { IF ((www. isin $strip($3-)) || (http:// isin $strip($3-))) { check.urls $1 $2 $strip($3-) } }
    ; Other channels advertising kick in a channel
    IF ($cps.rval($1,N2,5) == 1) { IF ($chr(35) isin $strip($3-)) { check.chans $1 $2 $strip($3-) } }
    ; Trout slap kicker
    IF ($cps.rval($1,n3,3) == 1) {
      IF (*SLAP* iswm $strip($3-)) {
        var %spll = $calc($cps.rvi($1,SLAP) + 1)
        set $+(-u,$cps.rvi($1,SLAP.TIME)) %fl.slap. [ $+ [ $1 ] $+ [ $2 ] ] $calc(%fl.slap. [ $+ [ $1 ] $+ [ $2 ] ] + 1)
        IF ((%fl.slap. [ $+ [ $1 ] $+ [ $2 ] ] == $cps.rvi($1,SLAP)) && (%_cps.warn.slap == ON)) {
          set %_cpsextra Du benutztest ein Slap Wort.
          warning $1 $2 slaps
          return
        }
        IF ((%fl.slap. [ $+ [ $1 ] $+ [ $2 ] ] >= $cps.rvi($1,SLAP)) && (%_cps.warn.slap == $null)) {
          set %_cpsextra Du benutztest ein Slap Wort.
          thrash $1 $2 slap
          return
        }
        IF ((%fl.slap. [ $+ [ $1 ] $+ [ $2 ] ] > $cps.rvi($1,SLAP)) && (%_cps.warn.slap == ON)) {
          set %_cpsextra Du benutztest ein Slap Wort.

          thrash $1 $2 slap
          return
        }
      }
    }
  }
}

; Drone bot kicker
ON *:SIGNAL:JOIN.DRONE: {
  IF (($cps.rval($1,N5,1) == 1) && ($istok(%controlchan,$1,44) == $true)) {
    ; I haven't seen a person having the word guest in his/her nick and be a drone bot
    IF (guest isin $2) { return }
    IF (~ !isin $address($2,5)) { return }
    IF ($istok(%drone.exp,$2,44) == $true) {
      ; If the length of nick is more that 15 nicks delte the oldest one
      IF ($numtok(%drone.exp,44) >= 15) { SET %drone.exp $deltok(%drone.exp,1,44) }
      return
    }
    ; Check if joining nick is in exception list
    IF ($istok(%drone.exp,$2,44) == $true) { return }
    ; A done nick is generally greater that 4 letters
    IF ($len($2) >= 5) {
      ; Some common words that not in drone bot
      IF ((*xtr* iswm $2) || (*cks* iswm $2) || (*ri* iswm $2) || (*sp* iswm $2) || (*sh* iswm $2) || (*blac* iswm $2) || (*trri* iswm $2) || (*shr* iswm $2) || (*rld* iswm $2) || (*nts* iswm $2) || (*pl* iswm $2) || (*chd* iswm $2) || (*psy* iswm $2) || (*hyd* iswm $2) || (*hts* iswm $2) || (*mr* iswm $2) || (*ngs* iswm $2)) { return }
      IF ((*www* iswm $2) || (*away* iswm $2) || (*str* iswm $2) || (*[a]* iswm $2) || (*abc* iswm $2) || (*guy* iswm $2) || (*gal* iswm $1) || (*boy* iswm $2) || (*blr* iswm $2) || (*ly* iswm $2) || (*ngh* iswm $2) || (*cklen* iswm $2)) { return }
      ;my eleet drone bot check routine =P~
      var %dr = $mid($2,2,$calc($len($2) - 2))
      IF ((a isin %dr) || (e isin %dr) || (i isin %dr) || (o isin %dr) || (u isin %dr)) { return }
      IF ($2 ison $1) { 
        while ($numtok(%droned,44) >= 15) { set %droned $deltok(%droned,1,44) }
        set %droned $addtok(%droned,$2,44)
        thrash $1 $2 drone
      }
    }
  }
}


; bad|blacklisted|guest nick checker when the nick changes
ON *:SIGNAL:BAD.NICK: {
  ; Guest nick checker
  IF (($1 != $me) && ($2 != $me)) {
    IF (Guest????? iswm $2) {
      var %bp9 = $comchan($2,0)
      var %bp8 = 0
      while (%bp8 < %bp9) {
        INC %bp8 1
        IF (($me isop $comchan($2,%bp8)) && ($istok(%controlchan,$comchan($2,%bp8),44) == $true) && ($cps.rval($comchan($2,%bp8),n5,4) == 1)) {
          set %_cpsextra Guest Nicks sind hier nicht erlaubt!
          thrash $comchan($2,%bp8) $2 guest
        }
      }
    }
    ; Bad nick checker
    var %bk9 = $comchan($2,0)
    var %bk8 = 0
    while (%bk8 < %bk9) {
      inc %bk8 1
      var %_tnic = $dll($airc, MatchTokString, $cps.rvi($comchan($2,%bk8),nick))
      var %_tnic1 = $dll($airc, MatchTok, +r 59 $2)
      IF (+OK* iswm %_tnic1) {
        IF (($me isop $comchan($2,%bk8)) && ($istok(%controlchan,$comchan($2,%bk8),44) == $true) && ($cps.rval($comchan($2,%bk8),n4,1) == 1)) {
          set %_cpsextra Badword -> $gettok(%_tnic1,2,32)
          thrash $comchan($2,%bk8) $2 nick
        }
      }
    }
    ; Black listed nick checker
    var %bc9 = $comchan($2,0)
    var %bc8 = 0
    while (%bc8 < %bc9) {
      inc %bc8 1
      var %_tbn = $dll($airc, MatchTokString, $cps.rvi($comchan($2,%bc8),blnic))
      var %_tbn1 = $dll($airc, MatchTok, +r 59 $2)
      IF (+OK* iswm %_tbn1) {
        IF (($me isop $comchan($2,%bc8)) && ($istok(%controlchan,$comchan($2,%bc8),44) == $true) && ($cps.rval($comchan($2,%bc8),n6,4) == 1)) {
          set %_cpsextra Badword -> $gettok(%_tbn1,2,32)
          thrash $comchan($2,%bc8) $2 blnic
        }
      }
    }
  }
}

; Spam detector
ON *:SIGNAL:PRIVATE.SPAM: {
  ; If nick is owner he won't spam
  IF ($owner($1) != $true) {
    ; Spam checker is on?
    IF (%_mspam == on) {
      ; Spam words are not zero?
      IF (%spam.words != $null) {
        ; Find total spam words
        var %var = $numtok(%spam.words,59)
        ; Loop every word to find out if anyone is in line
        while (%var > 0) {
          IF (($gettok(%spam.words,%var,59) iswm $strip($3-)) || ($gettok(%spam.words,%var,59) isin $strip($3-))) { var %_spamd1 = +OK $gettok(%spam.words,%var,59) }
          dec %var 1
        }
        ; If so do the actions which have been setup by user
        IF (+OK* iswm %_spamd1) {
          ; Close query
          .timer 1 1 close -m $1 
          ; If auto ignore is on ignore user
          IF (%_mspam.istatus == on) {
            .ignore -u30 $1
            .silence $+(+,$1)
            .timerSIL [ $+ [ $1 ] ] 1 30 silence $+(-,$1)
            echo $color(info2) $_place $_time ***4 %bsver $+  $1 wurde ignoriert wegen Spamming im Query; Spam Wort $gettok(%_spamd1,2,32)
          }
          ; If auto message user is on message him
          IF (%_mspam.mstatus == on) {
            .msg $1 Spam nicht rum, Deine Nachricht wurde ignoriert -=[ Spam gefunden ]=-
            echo $color(info) $_place $_time 4 $+ %bsver Spam gefunden von $1 $+ ; Wort wurde geblockt " $+ $gettok(%_spamd1,2,32) $+ "
            echo $color(other) $_place $_time $+(<,$1,>) $3-
          }
          ; If auto kick is on
          IF (%_mspam.kstatus == on) { 
            ; Find common channels
            var %t = $chan(0)
            ; Loop from each channel
            while (%t > 0) {
              ; If channel is protected kick the nick
              IF (($istok(%controlchan,$chan(%t),44) == $true) && ($me isop $chan(%t))) {
                IF ($isprot($chan(%t),$1) == $false) {
                  IF ($1 isvo $chan(%t)) { IF ($cps.rvi($chan(%t),KICKVOS) != ON) { return } }
                  IF ($1 isop $chan(%t)) { IF ($cps.rvi($chan(%t),KICKOPS) != ON) { return } }
                  IF ($ialchan($2,$chan(%t),0) > 0) {
                    ban -u300 $chan(%t) $2
                    var %dicy = $ialchan($2,$chan(%t),0)
                    WHILE (%dicy > 0) {
                      set %_cpsextra SpamWort: $gettok(%_spamd1,2,32)
                      set %kicktype [Auto]
                      kickc $chan(%t) $ialchan($2,$chan(%t),%dicy).nick Spam gefunden
                      dec %dicy 1
                    }
                  }
                }
              }
              dec %t 1              
            }
          }
        }
      }
    }
  }
}
ON *:SIGNAL:REV.DOOR: {
  IF (($istok(%controlchan,$1,44) == $true) && ($cps.rval($1,n5,5) == 1)) {
    IF (($2 != $me) && ($2 != %done.nick.part)) {
      var %parts = $dll($airc, Flood, $+(partf,$chr(44),$1,$chr(44),*!*@*) 1 $cps.rvi($1,door) $cps.rvi($1,door.TIME))
      var %total.nick = $cps.rvi($1,door)
      set $+(-u,$cps.rvi($1,door.TIME)) %nick.part [ $+ [ $1 ] ] $addtok(%nick.part [ $+ [ $1 ] ],$2,44) 
      if ($numtok(%nick.part [ $+ [ $1 ] ],44) > $cps.rvi($1,door)) { 
        set $+(-u,$cps.rvi($1,door.TIME)) %nick.part [ $+ [ $1 ] ] $deltok(%nick.part [ $+ [ $1 ] ],1,44) 
      }
      IF (+Flood* iswm %parts) {
        if (%channel.flooded.p. [ $+ [ $1 ] ] != YES) {
          .raw -q MODE $1 +miRMck Locked
          .timerraw $+ $1 1 60 .mode $1 -miRMck UnLocked
          set -u30 %channel.flooded.p. [ $+ [ $1 ] ] YES
        }
        if ($cps.rvi($1,door) > 6) {
          var %vareds1 = 1
          while (%vareds1 < 7) {
            if (%vareds1 == 1) { set %varanned1 [ $+ [ $1 ] ] $address($gettok(%nick.part [ $+ [ $1 ] ],%vareds1,44),$left($cps.rvi($1,door.ktype),1)) }
            set %varanned1 [ $+ [ $1 ] ] $addtok(%varanned1 [ $+ [ $1 ] ],$address($gettok(%nick.part [ $+ [ $1 ] ],%vareds1,44),$left($cps.rvi($1,door.ktype),1)),32)
            inc %vareds1
          }
          while (%vareds1 < 13) {
            if (%vareds1 == 7) { set %varanned2 [ $+ [ $1 ] ] $address($gettok(%nick.part [ $+ [ $1 ] ],%vareds1,44),$left($cps.rvi($1,door.ktype),1)) }
            set %varanned2 [ $+ [ $1 ] ] $addtok(%varanned2 [ $+ [ $1 ] ],$address($gettok(%nick.part [ $+ [ $1 ] ],%vareds1,44),$left($cps.rvi($1,door.ktype),1)),32)
            inc %vareds1
          }
          while (%vareds1 < 19) {
            if (%vareds1 == 13) { set %varanned3 [ $+ [ $1 ] ] $address($gettok(%nick.part [ $+ [ $1 ] ],%vareds1,44),$left($cps.rvi($1,part.ktype),1)) }
            set %varanned3 [ $+ [ $1 ] ] $addtok(%varanned3 [ $+ [ $1 ] ],$address($gettok(%nick.part [ $+ [ $1 ] ],%vareds1,44),$left($cps.rvi($1,door.ktype),1)),32)
            inc %vareds1
          }
          if ($cps.rvi($1,door) <= 12) {
            .mode $1 $+(+,$str(b,$iif($cps.rvi($1,door) > 6,6,$cps.rvi($1,door)))) %varanned1 [ $+ [ $1 ] ]
            .timerdoor $+ $1 $+ 1 1 $cps.rvi($1,door.ktime) .mode $1 $+(-,$str(b,$iif($cps.rvi($1,door) > 6,6,$cps.rvi($1,door)))) %varanned1 [ $+ [ $1 ] ]
            .mode $1 $+(+,$str(b,$calc($iif($cps.rvi($1,door) > 6,$cps.rvi($1,door),6)-6))) %varanned2 [ $+ [ $1 ] ]
            .timerdoor $+ $1 $+ 2 1 $cps.rvi($1,door.ktime) .mode $1 $+(-,$str(b,$calc($iif($cps.rvi($1,door) > 6,$cps.rvi($1,door),6)-6))) %varanned2 [ $+ [ $1 ] ]
            unset %var*
            unset %nick.part [ $+ [ $1 ] ]
          }
          else {

            .mode $1 $+(+,$str(b,$iif($cps.rvi($1,door) > 6,6,$cps.rvi($1,door)))) %varanned1 [ $+ [ $1 ] ]
            .timerdoor $+ $1 $+ 3 1 $cps.rvi($1,door.ktime) .mode $1 $+(-,$str(b,$iif($cps.rvi($1,door) > 6,6,$cps.rvi($1,door)))) %varanned1 [ $+ [ $1 ] ]
            .mode $1 $+(+,$str(b,$calc($iif($cps.rvi($1,door) > 6,6,$cps.rvi($1,door)))) %varanned2 [ $+ [ $1 ] ]
            .timerdoor $+ $1 $+ 4 1 $cps.rvi($1,door.ktime) .mode $1 $+(-,$str(b,$calc($iif($cps.rvi($1,door) > 6,6,$cps.rvi($1,door)))) %varanned2 [ $+ [ $1 ] ]
            .mode $1 $+(+,$str(b,$calc($iif($cps.rvi($1,door) > 6,6,$cps.rvi($1,door))-12))) %varanned3 [ $+ [ $1 ] ]
            .timerdoor $+ $1 $+ 5 1 $cps.rvi($1,door.ktime) .mode $1 $+(-,$str(b,$calc($iif($cps.rvi($1,door) > 6,6,$cps.rvi($1,door))-12))) %varanned3 [ $+ [ $1 ] ]
            unset %var*
            unset %nick.part [ $+ [ $1 ] ]
          }
        }
        else {
          var %vared = $cps.rvi($1,door)
          while (%vared >= 0) {
            set %varban6 [ $+ [ $1 ] ] $addtok(%varban6 [ $+ [ $1 ] ],$address($gettok(%nick.part [ $+ [ $1 ] ],%vared,44),$left($cps.rvi($1,door.ktype),1)),32)
            dec %vared
          }
          var %ti = $ran(1,9999)
          .mode $1 $+(+,$str(b,$cps.rvi($1,door))) %varban6 [ $+ [ $1 ] ]
          .timerdoor $+ $1 $+ %ti 1 $cps.rvi($1,door.ktime) .mode $1 $+(-,$str(b,$cps.rvi($1,door))) %varban6 [ $+ [ $1 ] ]
          unset %var*
          unset %nick.part [ $+ [ $1 ] ]
        }
      }
    }
  }
}

#cpsgroup2 end

; Events for handling the timers of idle kicker and channel limiter 
; Switch timers on when you get op in a protected channel [the idle kicker|channel limiter] should be on
ON *:OP:#:{
  IF (($opnick == $me) && ($cps.rvi($chan,LIMITER) == ON) && ($timer($+(LIMIT,$chan)) == $null)) { _ULIMIT ON $chan }
  IF (($opnick == $me) && ($cps.rval($chan,n8,1) == 1) && ($timer($+(IDLE,$chan)) == $null)) { .timerIDLE $+ $chan -i 0 120 idlekick $chan }
}

; On deop if timers were on switch them off
ON *:DEOP:#:{ 
  IF (($opnick == $me) && ($cps.rvi($chan,LIMITER) == ON) && ($timer($+(LIMIT,$chan)) != $null)) { _ULIMIT OFF $chan } 
  IF (($opnick == $me) && ($cps.rval($chan,n8,1) == 1) && ($timer($+(IDLE,$chan)) != $null)) { .timerIDLE $+ $chan off } 
}

; If you are kicked switch timers off... The remote also handles ban evaders
ON *:KICK:#: {
  IF (($knick == $me) && ($cps.rval($chan,LIMITER) == ON) && ($timer($+(LIMIT,$chan)) != $null)) { _ULIMIT OFF $chan }
  IF (($istok(%controlchan,$chan,44) == $true) && ($nick == $me) && ($knick != $me)) { SET -u8 %kicked. [ $+ [ $knick ] ] $knick }
  IF (($knick == $me) && ($cps.rval($chan,n8,1) == 1) && ($timer($+(IDLE,$chan)) != $null)) { .timerIDLE $+ $chan off }
}

#CPSGROUP5 on
; This is misc remote it signals as well as process inside its own body
ON *:PART:#:{
  IF (($istok(%controlchan,$chan,44) == $true) && ($nick == $me) && ($cps.rvi($chan,limiter) == on)) { _ulimit off $chan }
  IF (($istok(%controlchan,$chan,44) == $true) && ($nick == $me) && ($cps.rval($chan,n8,1) == 1)) { .timerIDLE $+ $chan off }
  ; This is the signal for revolving doors flood
  IF (($nick != $me) && ($me isop $chan)) { .signal rev.door $chan $nick $1- }
}
#CPSGROUP4 END
