#!/usr/local/bin/perl

# infobot -- copyright kevin lenzo (c) 1997-infinity

# no warrantee expressed or implied. terms as the 
# license for X11R6 when needed.

BEGIN {
    $filesep = '/';
    # set this to the absolute path if you need it; especially
    # if . is not in your path

    $infobot_base_dir = '.';  # '/usr/local/lib/infobot/'; 

    $infobot_src_dir = $infobot_base_dir.$filesep."src";

    # change this next line if you run a local instance of
    # an infobot and use the code from the main location.
    # the 'files' directory contains infobot.config and
    # infobot.users, among other things.

    $initmiscdir = $infobot_base_dir.$filesep.'files';
    # $initmiscdir = '/my_dir/files';

    $param{'miscdir'} = $initmiscdir;

    # these are here individually so you can mix
    # and match code segments for different infobots.

    # everything is loaded, then the variables that
    # you want to set will override the defaults; this
    # is why all these requires are here.  

    opendir DIR, $infobot_src_dir 
	or die "can't open source directory $infobot_src_dir: $!";

    while ($file = readdir DIR) {
	next unless $file =~ /\.pl$/;
	require "$infobot_src_dir$filesep$file";
    }
    closedir DIR;
}

# get the command line arguments
&getArgs();

# initialize everything 
&setup();

# launch the irc event loop
&irc();

exit 0;  # just so you don't look farther down in this file :)


# --- support routines

sub usage {
    print "\n";
    print "  usage: $0 [-h] [<paramfile1> [<pf2> ...]]\n";
    print "\n";
    print "		 -h   this message\n";
    print "\n";
}

sub getArgs {
    if (@ARGV) {
	while (@ARGV) {
	    my $arg = shift @ARGV;
	    if ($arg =~ s/^-//) {
		# switchies
		if ($arg eq 'i') {
		    # go into irc mode despite db setting
		    $overrideMode = 'IRC';
		} else {
		    # -h is in here by default
		    &usage;
		    exit(1);
		}
	    } else {
		# no switchie.  currently assumed to be
		# a paramfile by default
		push @paramfiles, $arg;
	    }
	}
    } else {
	@paramfiles = ();
    }
}

1;
