menu menubar {
}
dialog aban {
  size 280 180 240 180
  title "SyStem Meneger"
  box "Опции", 1, 10 10 220 130
  check "Вкл", 2, 25 30 70 15
  radio "предупредить, при повторе кик/бан", 3, 15 50 205 15, disable
  radio "анбан и кик", 4, 15 70 140 15, disable 
  radio "анбан и кик/бан", 5, 15 90 120 15, disable 
  text "Сообщение:", 6, 14 110 60 15
  edit "", 7, 75 107 150 20
  button "Применить", 8, 15 150 65 20, disable 
  button "Отмена", 9, 95 150 50 20, cancel 
  button "Выход", 10, 175 150 50 20, ok
  text "", 17, 330 95 80 15

}

alias aban dialog -m aban aban

on *:dialog:aban:*:*:{
  if $devent == sclick {
    if $did == 2 && $did(2).state == 1 { did -e ban 8,3,4,5 | did -n ban 7  }
    elseif $did == 2 && $did(2).state != 1 { did -b ban 3,4,5 | did -e ban 8 | did -m ban 7  }
    if $did == 3 { did -e ban 8 }
    if $did == 4 { did -e ban 8 }
    if $did == 5 { did -e ban 8 }
    if $did == 8 {
      if $did(2).state == 1 { set %antiban on }
      else { set %antiban off }   

      if $did(3).state == 1 { set %modeb 1 }
      if $did(4).state == 1 { set %modeb 2 }
      if $did(5).state == 1 { set %modeb 3 }
      if $did(7).text != $null { set %banpr $did(7).text }
      elseif $did(7).text == $null { set %banpr A N T I (+b) 
      }
      did -b ban 8
    }  
    if $did == 12 { did -e ban 8 }

  }
  if $devent == edit { did -e ban 8 }
  if $devent == init { 
    if %antiban == off { did -m ban 7  }
    else {
      did -e ban 3,4,5
      did -c ban 2
    }
    if %banpr == $null { did -a ban 7 A N T I (+b) 
    }
    else { did -a ban 7 %banpr }
    if %modeb == 1 { did -c ban 3 }
    if %modeb == 2 { did -c ban 4 }
    if %modeb == 3 { did -c ban 5 }
  }
}
on *:ban:#:{
  if %antiban == on {
    if ($nick == $me) && ($banmask !isin %bm) { set %bm %bm $banmask }    
    if ($nick == chanserv) && ($banmask iswm $address($me,5)) { set %akik $banmask }
    if ($nick != $me) && ($banmask iswm $address($me,5)) && ($nick != Chanserv) {
      .raw -q kick # $nick      
      .raw -q mode # -b $banmask
      if (%modeb == 1) && ($nick != Chanserv) { if ($nick != %banner) { .notice $nick Не бань меня парамоша!! | set -u60 %banner $nick } | else { .raw mode # -oeI+b %banner %banner %banner $address(%banner,2)  | .raw kick # %banner %banpr | unset %banner } }
      if (%modeb == 2) && ($nick != Chanserv) { .raw kick # $nick %banpr }
      if (%modeb == 3) && ($nick != Chanserv) { .raw mode # -o+b $nick $nick | .raw kick # $nick %banpr }
    }
    halt
  }
}

on *:UNBAN:#:{
  if ($banmask isin %bm) {
    if ($nick != $me) .raw -q mode # +b $banmask
    else set %bm $remove(%bm,$banmask)
  }
}

raw 474:*: {
  .msg ChanServ unban $2
}
