use Xchat ':all'; use strict; use warnings; use constant DEBUG => 0; my $cmd_name = "send_batch"; my $cmd_usage = < example: $cmd_name Foo /home/bar/files/* USAGE register my$NAME="DCC Batch Upload", 1, "Upload a batch of files (use /$cmd_name)"; my$PRE="\cB$NAME\cB\t"; prnt "\cB$NAME\cB Loaded. (use /$cmd_name)"; hook_command($cmd_name, sub { my (undef, $them, $dir) = @{$_[0]}; unless( defined $them and defined $dir ) { prnt $cmd_usage; return EAT_XCHAT; } # for non-glob second arg #unless( -e $dir ) { prnt "Directory does not exist."; prnt $cmd_usage; return EAT_NONE; } #unless( -d $dir ) { prnt "File is not a directory."; prnt $cmd_usage; return EAT_NONE; } # non-directory files my @files = grep !-d($_), glob($dir); unless( @files ) { prnt "$PRE No files found."; return EAT_XCHAT; } if(DEBUG) { local $" = ", "; prnt "Files found: @files"; return EAT_XCHAT; } # first one prnt "$PRE Sending $files[0]..."; command("DCC SEND $them $files[0]"); my $done = 0; # index of current file my %hooks; # have %hooks defined in the subs' scopes %hooks = ( abort => hook_print("DCC SEND Abort", sub { my ($nick, $file) = @{$_[0]}; return EAT_NONE unless lc$nick eq lc$them; prnt "$PRE Aborting operation."; unhook($_) for values %hooks; # abort EAT_NONE; }), complete => hook_print("DCC SEND Complete", sub { my ($file, $nick, $cps) = @{$_[0]}; return EAT_NONE unless lc$nick eq lc$them; if( $done+1 < @files ) { prnt "$PRE $done completed. Continuing..."; $done++; prnt "$PRE Sending $files[$done]..."; command("DCC SEND $them $files[$done]"); } else { prnt "$PRE Done. $done files uploaded to $them."; } EAT_NONE; }), failed => hook_print("DCC SEND Failed", sub { my ($file, $nick, $error) = @{$_[0]}; return EAT_NONE unless lc$nick eq lc$them; prnt "$PRE Aborting operation."; unhook($_) for values %hooks; # abort EAT_NONE; }), ); EAT_XCHAT; }); 1; __END__ problems: doesn't check for empty files