#by wiebe @ QuakeNet



#help gunstick pub

bind pubm mn "% ${botnet-nick} help gunstick" c_gunstick:help:pub

proc c_gunstick:help:pub { nick uhost handle chan text } {
  lappend output "Usage: gunstick <ban1> \[<ban2> .. <banN>\]"
  lappend output "Makes the specified sticky global bans normal."
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  putloglev c $chan "[lindex [split $text] 1]: $nick $uhost $handle $chan [join [lrange [split $text] 2 end]]"
}




#help gunstick msg

bind msgm mn "help gunstick" c_gunstick:help:msg

proc c_gunstick:help:msg { nick uhost handle text } {
  lappend output "Usage: gunstick <ban1> \[<ban2> .. <banN>\]"
  lappend output "Makes the specified sticky global bans normal."
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  putcmdlog "($nick!$uhost) !$handle! $text"
}



#gunstick pub
bind pubm mn "% ${botnet-nick} gunstick" c_gunstick:pub
bind pubm mn "% ${botnet-nick} gunstick *" c_gunstick:pub

proc c_gunstick:pub { nick uhost handle chan text } {
  set masks [join [lrange [split $text] 2 end]]
  if { [string equal $masks ""] } {
    lappend output "Usage: gunstick <ban1> \[<ban2> .. <banN>\]"
  } else {
    set noban ""
    set done ""
    set notsticky ""
    foreach mask [split $masks] {
      if { [string match ?*@?* $mask] && ![string match ?*!?*@?* $mask] } {
        set mask *!$mask
      } elseif { [string match *.* $mask] && ![string match ?*!?*@?* $mask] } {
        set mask *!*@$mask
      } elseif { [string match ?*!?* $mask] && ![string match ?*!?*@?* $mask] } {
        set mask $mask@*
      } elseif { ![string match ?*!?*@?* $mask] } {
        set mask $mask!*@*
      }

      if { ![isban $mask] } {
        lappend noban $mask
      } elseif { ![isbansticky $mask] } {
        lappend notsticky $mask
      } else {
        unstick $mask
        lappend done $mask
      }
    }

    if { ![string equal $noban ""] } {
      lappend output "Not on global banlist: $noban"
    }
    if { ![string equal $notsticky ""] } {
      lappend output "Not sticky: $notsticky"
    }
    if { ![string equal $done ""] } {
      lappend output "Unstick global bans: $done"
    }
  }
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  putloglev c $chan "[lindex [split $text] 1]: $nick $uhost $handle $chan [join [lrange [split $text] 2 end]]"
}



#gunstick msg
bind msg mn gunstick c_gunstick:msg

proc c_gunstick:msg { nick uhost handle text } {
  set masks $text
  if { [string equal $masks ""] } {
    lappend output "Usage: gunstick <ban1> \[<ban2> .. <banN>\]"
  } else {
    set noban ""
    set done ""
    set notsticky ""
    foreach mask [split $masks] {
      if { [string match ?*@?* $mask] && ![string match ?*!?*@?* $mask] } {
        set mask *!$mask
      } elseif { [string match *.* $mask] && ![string match ?*!?*@?* $mask] } {
        set mask *!*@$mask
      } elseif { [string match ?*!?* $mask] && ![string match ?*!?*@?* $mask] } {
        set mask $mask@*
      } elseif { ![string match ?*!?*@?* $mask] } {
        set mask $mask!*@*
      }

      if { ![isban $mask] } {
        lappend noban $mask
      } elseif { ![isbansticky $mask] } {
        lappend notsticky $mask
      } else {
        stick $mask
        lappend done $mask
      }
    }

    if { ![string equal $noban ""] } {
      lappend output "Not on global banlist: $noban"
    }
    if { ![string equal $notsticky ""] } {
      lappend output "Not sticky: $notsticky"
    }
    if { ![string equal $done ""] } {
      lappend output "Unstick global bans: $done"
    }
  }
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  return 1
}

