# Alternate/Automatic (Easier) DCC Get/Chat
# version 1.1
# for use with sirc by orabidoo
#
# T-Bone/DaveK 3/?/95:
# ircII version done
#
# DaveK 6/25/95:
# ported to perl
#
# T-Bone 6/26/95:
# straightened things out generally
#
# orabidoo 6/28/95:
# a few little bugfixes
#
# T-Bone 7/4/95:
# some fixes and reordering
# made rename work
# made it perl4 compatible

$AUTOGET = "OFF" unless $AUTOGET;
$adcc    = "ON";

sub cmd_adcc {
    if ($args) {
	$adcc = ($args =~ /^on/i) ? 'ON' : 'OFF';
    } else {
	&tell("*\cbD\cb* adcc is currently $adcc.");
    }
} &addcmd("adcc");

sub hook_adcc_get {
    return unless $ssfe
	&& $_[0]	eq 'SEND'
	&& $adcc	eq 'ON'
	&& $AUTOGET	eq 'OFF';

    local($dfile) = $_[3];

    while (1) {
	&getuserline
	    ("*\cbD\cb* \cbR\cb = rename; \cbG\cb = get; \cbC\cb = close",
	    "C/R/G> ");
	if (m(^r (.*))i) {
	    &docommand("dcc rename $who $dfile $1");
	    $dfile = $1;
        } elsif (m(^c)i) {
	    &docommand("dcc close get $who $dfile");
	    return;
	} elsif (m(^g)i) {
	    &docommand("dcc get $who $dfile");
	    return;
	} else {
	    &tell("*\cbE\cb* Error in adcc command: $_");
	}
    }
} &addhook("dcc_request", "adcc_get");

sub hook_adcc_chat {
    return unless $ssfe
	&& $_[0]	eq 'CHAT'
	&& $adcc	eq 'ON';

    while (1) {
	&getuserline("*\cbD\cb* \cbA\cb = accept; \cbC\cb = close", "A/C> ");
	if (m(^a)i) {
	    &docommand("dcc chat $who");
	    return;
	} elsif (m(^c)i) {
	    &docommand("dcc close chat $who");
	    return;
	} else {
	    &tell("*\cbE\cb* Error in adcc command: $_");
	}
    }
} &addhook("dcc_request", "adcc_chat");

1;
