#by wiebe @ QuakeNet
#die restart jump -chan -user -bot commands require a md5 hash as confirmation

#add /msg die jump commands



#die
bind dcc n|- die confirm:dcc:die

proc confirm:dcc:die { handle idx text } {
  set last [lindex [split $text] end]
  set text2 [join [lrange [split $text] 0 end-1]]
  set md5 [string range [md5 "$handle $idx $::botnick $text2"] 0 9]
  if { ![string equal $md5 $last] } {
    putidx $idx "WARNING! This kills the bot."
    set md5 [string range [md5 "$handle $idx $::botnick $text"] 0 9]
    if { [string equal $text ""] } {
      putidx $idx "To confirm this command use: die $md5"
    } else { putidx $idx "To confirm this command use: die $text $md5" }
  } else { *dcc:die $handle $idx $text2 }
}



#restart
bind dcc n|- restart confirm:dcc:restart

proc confirm:dcc:restart { handle idx text } {
  set md5 [string range [md5 "$handle $idx $::botnick"] 0 9]
  if { ![string equal $md5 $text] } {
    putidx $idx "WARNING! This restarts the bot."
    putidx $idx "To confirm this command use: restart $md5"
  } else { *dcc:restart $handle $idx $text }
}



#jump
bind dcc m|- jump confirm:dcc:jump

proc confirm:dcc:jump { handle idx text } {
  set last [lindex [split $text] end]
  set text2 [join [lrange [split $text] 0 end-1]]
  set md5 [string range [md5 "$handle $idx $::botnick $text2"] 0 9]
  if { ![string equal $md5 $last] } {
    putidx $idx "WARNING! This will reconnect the bot."
    set md5 [string range [md5 "$handle $idx $::botnick $text"] 0 9]
    if { [string equal $text ""] } {
      putidx $idx "To confirm this command use: jump $md5"
    } else { putidx $idx "To confirm this command use: jump $text $md5" }
  } else { *dcc:jump $handle $idx $text2 }
}



#-chan
bind dcc n|- -chan confirm:dcc:-chan

proc confirm:dcc:-chan { handle idx text } {
  set chan [lindex [split $text] 0]
  set last [lindex [split $text] 1]
  set md5 [string range [md5 "$handle $idx $::botnick $chan"] 0 9]
  if { ![validchan $chan] } {
    *dcc:-chan $handle $idx $text
  } elseif { ![string equal $md5 $last ] } {
    putidx $idx "WARNING! This will remove $chan from the bot."
    putidx $idx "To confirm this command use: -chan $text $md5"
  } else { *dcc:-chan $handle $idx $chan }
}



#-user
bind dcc m|- -user confirm:dcc:-user

proc confirm:dcc:-user { handle idx text } {
  set user [lindex [split $text] 0]
  set last [lindex [split $text] 1]
  set md5 [string range [md5 "$handle $idx $::botnick $user"] 0 9]
  if { ![validuser $user] } {
    *dcc:-user $handle $idx $text
  } elseif { ![string equal $md5 $last ] } {
    putidx $idx "WARNING! This will remove user $user from the bot."
    putidx $idx "To confirm this command use: -user $text $md5"
  } else { *dcc:-user $handle $idx $user }
}



#-bot
bind dcc m|- -bot confirm:dcc:-bot

proc confirm:dcc:-bot { handle idx text } {
  set user [lindex [split $text] 0]
  set last [lindex [split $text] 1]
  set md5 [string range [md5 "$handle $idx $::botnick $user"] 0 9]
  if { ![validuser $user] } {
    *dcc:-bot $handle $idx $text
  } elseif { ![string equal $md5 $last ] } {
    putidx $idx "WARNING! This will remove user $user from the bot."
    putidx $idx "To confirm this command use: -bot $text $md5"
  } else { *dcc:-bot $handle $idx $user }
}

