if (word(2 $loadinfo()) != [pf]) { load -pf $word(1 $loadinfo()); return; };

#
# Autoget!  Because people keep asking me for this.
# Ok.  Here's the plan.
# /autoget <pattern> [<pattern> ....] will auto-get any file that matches
#	any of the patterns.
# /autoget -<pattern>  will stop autogetting any file that matches this
#	pattern.
# You can mix and match <pattern>s and -<pattern>s.
#
# New:  Patterns will now be matched against nick!user@host,IP,file.
#       This shouldn't really be incompatible unless you autoget
#       files begining with specific names.
# New:  /autoreget acts much the same as /autoget, but the patterns apply
#       to requests for which the file already exists.
#       /autoclobber takes two arguments specifying the reget modes.
#       These can be one of GET, RESUME, RENAME.  For RENAME,
#       a random string will be appended to the filename.
# Note: All commas in the filename are replaced with dots for the purpose
#       of matching to make it harder for people to accidentally or
#       purposely bypass well written masks by sending you specific
#       filenames.  Nevertheless, this isn't really a safe authentication
#       method.
#
# Note: If the sender (an fserv perhaps) sends elaborate messages before
#       the transfer begins and NO_CTCP_FLOOD is on (it is on by
#       default), the ctcp flood protection mechanism can be triggered
#       and the transfer can fail to start.  It may be better for you
#       to turn this feature off and make other flood protection
#       arrangements.
#

package autoget;

# Take possession of these variables while not clobbering them.
fe (patterns.get * patterns.reget * reget.part resume reget.full close) var val {
	@ autoget[$var] = autoget.$var ? autoget.$var : [$val];
};

on #-dcc_request 414 "% SEND *" {
	@ :path = [$getset(dcc_store_path)/$urldecode($2)];
	if ([$6] <= fsize("$path")) {
		@ :patterns = autoget.patterns.reget;
		@ :action = autoget.reget.full;
	} elsif (0 < fsize("$path")) {
		@ :patterns = autoget.patterns.reget;
		@ :action = autoget.reget.part;
	} else {
		@ :patterns = autoget.patterns.get;
		@ :action = [get];
	};
	if (rmatch($0!$userhost(),$3,$tr(/,/./$2) $autoget.patterns.reject)) {
		# Nothing.
	} elsif (rmatch($0!$userhost(),$3,$tr(/,/./$2) $patterns)) {
		if (action == []) {
			return;
		} elsif (action == [rename]) {
			@ :extra = 0;
			do {
				@ extra += rand(10);
			} while (0 < fexist("$path~$extra"));
			@ rename("$path" "$path~$extra");
			@ action = [get];
		} elsif (action == [close]) {
			@ action =                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    