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

# add ircconsole

####################################################
# die
####################################################
bind dcc n|- die confirm:die
proc confirm:die { h i t } {
  set l [lindex [split $t] end]; set u [join [lrange [split $t] 0 end-1]]
  set m [string range [md5 "$h $i $::botnick $u"] 0 4]
  if {![string equal $m $l]} {
    putidx $i "WARNING! This kills the bot."
    set m [string range [md5 "$h $i $::botnick $t"] 0 4]
    if {[string equal $t ""]} {
      putidx $i "To confirm this command use: die $m"
    } else { putidx $i "To confirm this command use: die $t $m" }
  } else { *dcc:die $h $i $u }
}


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

####################################################
# jump
####################################################
bind dcc m|- jump confirm:jump
proc confirm:jump { h i t } {
  set l [lindex [split $t] end]; set u [join [lrange [split $t] 0 end-1]]
  set m [string range [md5 "$h $i $::botnick $u"] 0 4]
  if {![string equal $m $l]} {
    putidx $i "WARNING! This will reconnect the bot."
    set md5 [string range [md5 "$h $i $::botnick $t"] 0 4]
    if {[string equal $t ""]} {
      putidx $i "To confirm this command use: jump $m"
    } else { putidx $i "To confirm this command use: jump $t $m" }
  } else { *dcc:jump $h $i $u }
}


####################################################
# -chan
####################################################
bind dcc n|- -chan confirm:-chan
proc confirm:-chan { h i t } {
  set c [lindex [split $t] 0]; set l [lindex [split $t] 1]
  set m [string range [md5 "$h $i $::botnick $c"] 0 4]
  if {![validchan $c]} {
    *dcc:-chan $h $i $t
  } elseif {![string equal $m $l]} {
    putidx $i "WARNING! This will remove $c from the bot."
    putidx $i "To confirm this command use: -chan $t $m"
  } else { *dcc:-chan $h $i $c }
}


####################################################
# -user
####################################################
bind dcc m|- -user confirm:-user
proc confirm:-user { h i t } {
  set u [lindex [split $t] 0]; set l [lindex [split $t] 1]
  set m [string range [md5 "$h $i $::botnick $u"] 0 4]
  if {![validuser $u]} {
    *dcc:-user $h $i $t
  } elseif {![string equal $m $l]} {
    putidx $i "WARNING! This will remove user $u from the bot."
    putidx $i "To confirm this command use: -user $t $m"
  } else { *dcc:-user $h $i $u }
}


####################################################
# -bot
####################################################
bind dcc m|- -bot confirm:-bot
proc confirm:-bot { h i t } {
  set u [lindex [split $t] 0]; set l [lindex [split $t] 1]
  set m [string range [md5 "$h $i $::botnick $u"] 0 4]
  if {![validuser $u]} {
    *dcc:-bot $h $i $t
  } elseif {![string equal $m $l]} {
    putidx $i "WARNING! This will remove user $u from the bot."
    putidx $i "To confirm this command use: -bot $t $m"
  } else { *dcc:-bot $h $i $u }
}


set scriptdb(confirm) {
  "adds a confirmation requirement to dcc commands: die jump restart -chan -user -bot"
}

