#by wiebe @ QuakeNet



#help gstick pub

bind pubm mn "% ${botnet-nick} help gstick" c_gstick:help:pub

proc c_gstick:help:pub { nick uhost handle chan text } {
  lappend output "Usage: gstick <ban1> \[<ban2> .. <banN>\]"
  lappend output "Makes the specified global bans 'sticky', meaning the bans will always be active on the channel, until they expire or set back to normal with gunstick."
  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 gstick msg

bind msgm mn "help gstick" c_gstick:help:msg

proc c_gstick:help:msg { nick uhost handle text } {
  lappend output "Usage: gstick <ban1> \[<ban2> .. <banN>\]"
  lappend output "Makes the specified global bans 'sticky', meaning the bans will always be active on the channel, until they expire or set back to normal with gunstick."
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  putcmdlog "($nick!$uhost) !$handle! $text"
}



#gstick pub
bind pubm mn "% ${botnet-nick} gstick" c_gstick:pub
bind pubm mn "% ${botnet-nick} gstick *" c_gstick:pub

proc c_gstick:pub { nick uhost handle chan text } {
  set masks [join [lrange [split $text] 2 end]]
  if { [string equal $masks ""] } {
    lappend output "Usage: gstick <ban1> \[<ban2> .. <banN>\]"
  } else {
    set noban ""
    set done ""
    set already ""
    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 already $mask
      } else {
        stick $mask
        lappend done $mask
      }
    }

    if { ![string equal $noban ""] } {
      lappend output "Not on global banlist: $noban"
    }
    if { ![string equal $already ""] } {
      lappend output "Already sticky: $already"
    }
    if { ![string equal $done ""] } {
      lappend output "Stick 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]]"
}



#gstick msg
bind msg mn gstick c_gstick:msg

proc c_gstick:msg { nick uhost handle text } {
  set masks $text
  if { [string equal $masks ""] } {
    lappend output "Usage: gstick <ban1> \[<ban2> .. <banN>\]"
  } else {
    set noban ""
    set done ""
    set already ""
    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 already $mask
      } else {
        stick $mask
        lappend done $mask
      }
    }

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

