]> git.donarmstrong.com Git - infobot.git/blobdiff - src/modules.pl
add initial SQLite support
[infobot.git] / src / modules.pl
index 83d7890e2228b4b7414983b767bb6e59e4bc8e46..ae2dac531699f771d1b09400cd0852303562b0a0 100644 (file)
@@ -5,7 +5,7 @@
 #     Created: 20000624
 #
 
-if (&IsParam("useStrict")) { use strict; }
+#use strict;
 use vars qw($AUTOLOAD);
 
 ###
@@ -21,17 +21,19 @@ if ($@) {
 
 ### MODULES.
 %myModules = (
+       "bzflag"        => "BZFlag.pl",
        "countdown"     => "Countdown.pl",
        "debian"        => "Debian.pl",
        "debianExtra"   => "DebianExtra.pl",
        "dict"          => "Dict.pl",
        "dumpvars"      => "DumpVars.pl",
+       "symdump"       => "DumpVars2.pl",
        "factoids"      => "Factoids.pl",
        "freshmeat"     => "Freshmeat.pl",
        "kernel"        => "Kernel.pl",
-       "ircdcc"        => "UserDCC.pl",
        "perlMath"      => "Math.pl",
        "news"          => "News.pl",
+       "plug"          => "Plug.pl",
        "quote"         => "Quote.pl",
        "rootwarn"      => "RootWarn.pl",
        "search"        => "Search.pl",
@@ -39,17 +41,22 @@ if ($@) {
        "topic"         => "Topic.pl",
        "units"         => "Units.pl",
        "uptime"        => "Uptime.pl",
+       "ircdcc"        => "UserDCC.pl",
        "userinfo"      => "UserInfo.pl",
        "wwwsearch"     => "W3Search.pl",
        "whatis"        => "WhatIs.pl",
        "wingate"       => "Wingate.pl",
+       "babelfish"     => "babel.pl",
        "insult"        => "insult.pl",
        "nickometer"    => "nickometer.pl",
-       "babelfish"     => "babel.pl",
+       "zfi"           => "zfi.pl",
+       "zsi"           => "zsi.pl",
 );
 ### THIS IS NOT LOADED ON RELOAD :(
+my @myModulesLoadNow;
+my @myModulesReloadNot;
 BEGIN {
-    @myModulesLoadNow  = ('topic', 'uptime', 'news', 'rootWarn');
+    @myModulesLoadNow  = ('topic', 'uptime', 'news', 'rootWarn', 'symdump');
     @myModulesReloadNot        = ('IRC/Irc.pl','IRC/Schedulers.pl');
 }
 
@@ -74,9 +81,8 @@ sub loadCoreModules {
 }
 
 sub loadDBModules {
-    &status("Loading DB modules...");
-
-    $moduleAge{"$bot_src_dir/modules.pl"} = time();
+    my $f = "$bot_src_dir/modules.pl";
+    $moduleAge{$f} = (stat $f)[9];
 
     if ($param{'DBType'} =~ /^mysql$/i) {
        eval "use DBI";
@@ -84,32 +90,28 @@ sub loadDBModules {
            &ERROR("libdbd-mysql-perl is not installed!");
            exit 1;
        }
+       &status("Loading MySQL support.");
+       $f = "$bot_src_dir/db_mysql.pl";
+       require $f;
+       $moduleAge{$f} = (stat $f)[9];
        &showProc(" (DBI // mysql)");
-
-       &status("  using MySQL support.");
-       require "$bot_src_dir/db_mysql.pl";
-       $moduleAge{"$bot_src_dir/db_mysql.pl"} = time();
-
     } elsif ($param{'DBType'} =~ /^pgsql$/i) {
-       eval "use Pg";
+#      eval "use Pg";
+       eval "use DBI";
        if ($@) {
            &ERROR("libpgperl is not installed!");
            exit 1;
        }
-       &showProc(" (Pg // postgreSQLl)");
-
-       &status("  using PostgreSQL support.");
+       &status("Loading pgsql support.");
        require "$bot_src_dir/db_pgsql.pl";
-    } elsif ($param{'DBType'} =~ /^dbm$/i) {
-
-       &status("  using Berkeley DBM 1.85/2.0 support.");
-       &ERROR("dbm support is broken... you want it, you fix it!");
-       &shutdown();
-       exit 1;
-
-#      require "$bot_src_dir/db_dbm.pl";
+       &showProc(" (pgsql)");
+    } elsif ($param{'DBType'} =~ /^sqlite$|^dbm$/i) {
+       &status("Loading " . $param{'DBType'} . " support.");
+       $f="$bot_src_dir/db_" . $param{'DBType'} . ".pl";
+       $moduleAge{$f} = (stat $f)[9];
+       require $f;
+       &showProc(" $bot_src_dir/db_" . $param{'DBType'} . ".pl");
     } else {
-
        &status("DB support DISABLED.");
        return;
     }
@@ -138,7 +140,8 @@ sub loadFactoidsModules {
 }
 
 sub loadIRCModules {
-    if (&whatInterface() =~ /IRC/) {
+    my ($interface) = &whatInterface();
+    if ($interface =~ /IRC/) {
        &status("Loading IRC modules...");
 
        eval "use Net::IRC";
@@ -147,18 +150,22 @@ sub loadIRCModules {
            exit 1;
        }
        &showProc(" (Net::IRC)");
-
     } else {
        &status("IRC support DISABLED.");
-       return;
+       # disabling forking.
+       $param{forking} = 0;
+       $param{noSHM}   = 1;
     }
 
-    foreach ( &getPerlFiles("$bot_src_dir/IRC") ) {
-       my $mod = "$bot_src_dir/IRC/$_";
+    foreach ( &getPerlFiles("$bot_src_dir/$interface") ) {
+       my $mod = "$bot_src_dir/$interface/$_";
 
+       # hrm... use another config option besides DEBUG to display
+       # change in memory usage.
+       &status("Loading Modules \"$mod\"") if (!&IsParam("DEBUG"));
        eval "require \"$mod\"";
        if ($@) {
-           &ERROR("lIRCM => $@");
+           &ERROR("require \"$mod\" => $@");
            &shutdown();
            exit 1;
         }
@@ -233,7 +240,7 @@ sub reloadModule {
     }
 
     if (grep /$mod/, @myModulesReloadNot) {
-       &DEBUG("rM: SHOULD NOT RELOAD $mod!!!");
+       &DEBUG("rM: should not reload $mod");
        return;
     }
 
@@ -245,7 +252,9 @@ sub reloadModule {
        return if ($age == $moduleAge{$file});
 
        if ($age < $moduleAge{$file}) {
-           &WARN("rM: we're not gonna downgrade the file. use 'touch'.");
+           &WARN("rM: we're not gonna downgrade '$file'; use touch.");
+           &DEBUG("age => $age");
+           &DEBUG("mA{$file} => $moduleAge{$file}");
            return;
        }
 
@@ -274,8 +283,8 @@ sub reloadModule {
 ### OPTIONAL MODULES.
 ###
 
-local %perlModulesLoaded  = ();
-local %perlModulesMissing = ();
+my %perlModulesLoaded  = ();
+my %perlModulesMissing = ();
 
 sub loadPerlModule {
     return 0 if (exists $perlModulesMissing{$_[0]});
@@ -302,7 +311,7 @@ sub loadMyModule {
        return 0; 
     }
 
-    my ($modulebase, $modulefile);
+    my ($modulename, $modulebase);
     if (exists $myModules{$tmp}) {
        ($modulename, $modulebase) = ($tmp, $myModules{$tmp});
     } else {
@@ -312,7 +321,7 @@ sub loadMyModule {
            $modulename = $tmp;
        }
     }
-    $modulefile = "$bot_src_dir/Modules/$modulebase";
+    my $modulefile = "$bot_src_dir/Modules/$modulebase";
 
     # call reloadModule() which checks age of file and reload.
     if (grep /\/$modulebase$/, keys %INC) {
@@ -360,10 +369,15 @@ if ($@) {
 &showProc(" (Time::HiRes)");
 
 sub AUTOLOAD {
+    if (!defined $AUTOLOAD and defined $::AUTOLOAD) {
+       &DEBUG("AUTOLOAD: hrm.. ::AUTOLOAD defined!");
+    }
+    return unless (defined $AUTOLOAD);
     return if ($AUTOLOAD =~ /__/);     # internal.
 
     my $str = join(', ', @_);
-    &ERROR("UNKNOWN FUNCTION CALLED: $AUTOLOAD ($str)");
+    my ($package, $filename, $line) = caller;
+    &ERROR("UNKNOWN FUNCTION CALLED: $AUTOLOAD ($str) $filename line $line");
 
     $AUTOLOAD =~ s/^(\S+):://g;
 
@@ -378,7 +392,7 @@ sub getPerlFiles {
     my($dir) = @_;
 
     if (!opendir(DIR, $dir)) {
-        &ERROR("cannot open source directory $dir: $!");
+        &ERROR("Cannot open source directory ($dir): $!");
         exit 1;
     }