]> git.donarmstrong.com Git - infobot.git/blobdiff - src/modules.pl
- modified db_mysql to allow eleet usage of dbSet
[infobot.git] / src / modules.pl
index 333c43e145950a3d9f5e78d8658e94261cc62a52..162279d65c6124a9c5e677edfeefe2dab5eb34f5 100644 (file)
@@ -31,6 +31,7 @@ if ($@) {
        "kernel"        => "Kernel.pl",
        "ircdcc"        => "UserDCC.pl",
        "perlMath"      => "Math.pl",
+       "news"          => "News.pl",
        "quote"         => "Quote.pl",
        "rootwarn"      => "RootWarn.pl",
        "search"        => "Search.pl",
@@ -44,9 +45,13 @@ if ($@) {
        "wingate"       => "Wingate.pl",
        "insult"        => "insult.pl",
        "nickometer"    => "nickometer.pl",
+       "babelfish"     => "babel.pl",
 );
-@myModulesLoadNow      = ('topic', 'uptime',);
-@myModulesReloadNot    = ('IRC/Irc.pl','IRC/Schedulers.pl');
+### THIS IS NOT LOADED ON RELOAD :(
+BEGIN {
+    @myModulesLoadNow  = ('topic', 'uptime', 'news');
+    @myModulesReloadNot        = ('IRC/Irc.pl','IRC/Schedulers.pl');
+}
 
 sub loadCoreModules {
     if (!opendir(DIR, $bot_src_dir)) {
@@ -54,14 +59,18 @@ sub loadCoreModules {
        exit 1;
     }
 
-    &status("Loading CORE modules...");
-
+    my @mods;
     while (defined(my $file = readdir DIR)) {
        next unless $file =~ /\.pl$/;
        next unless $file =~ /^[A-Z]/;
-       my $mod = "$bot_src_dir/$file";
+       push(@mods, $file);
+    }
+    closedir DIR;
+    &status("Loading ".scalar(@mods)." CORE modules...");
+
+    foreach (sort @mods) {
+       my $mod = "$bot_src_dir/$_";
 
-       ### TODO: use eval and exit gracefully?
        eval "require \"$mod\"";
        if ($@) {
            &ERROR("lCM => $@");
@@ -70,9 +79,8 @@ sub loadCoreModules {
        }
 
        $moduleAge{$mod} = (stat $mod)[9];
-       &showProc(" ($file)") if (&IsParam("DEBUG"));
+       &showProc(" ($_)") if (&IsParam("DEBUG"));
     }
-    closedir DIR;
 }
 
 sub loadDBModules {
@@ -102,7 +110,11 @@ sub loadDBModules {
     } elsif ($param{'DBType'} =~ /^dbm$/i) {
 
        &status("  using Berkeley DBM 1.85/2.0 support.");
-       require "$bot_src_dir/db_dbm.pl";
+       &ERROR("dbm support is broken... you want it, you fix it!");
+       &shutdown();
+       exit 1;
+
+#      require "$bot_src_dir/db_dbm.pl";
     } else {
 
        &status("DB support DISABLED.");
@@ -184,9 +196,9 @@ sub loadMyModulesNow {
            next;
        }
 
-       if (!&IsParam($_) and !&IsChanConf($_)) {
+       if (!&IsParam($_) and !&IsChanConf($_) and !&getChanConfList($_)) {
            if (exists $myModules{$_}) {
-               &DEBUG("myModule: $myModules{$_} (1) not loaded.");
+               &status("myModule: $myModules{$_} or $_ (1) not loaded.");
            } else {
                &DEBUG("myModule: $_ (2) not loaded.");
            }
@@ -198,7 +210,7 @@ sub loadMyModulesNow {
        $loaded++;
     }
 
-    &status("Module: Loaded/Total [$loaded/$total]");
+    &status("Module: Runtime: Loaded/Total [$loaded/$total]");
 }
 
 ### rename to moduleReloadAll?
@@ -231,25 +243,31 @@ sub reloadModule {
        return;
     }
 
-    my $age = (stat $file)[9];
-    return if ($age == $moduleAge{$file});
-
-    if ($age < $moduleAge{$file}) {
-       &WARN("rM: we're not gonna downgrade the file. use 'touch'.");
-       return;
-    }
-
     if (grep /$mod/, @myModulesReloadNot) {
        &DEBUG("rM: SHOULD NOT RELOAD $mod!!!");
        return;
     }
 
-    my $dc  = &Time2String($age   - $moduleAge{$file});
-    my $ago = &Time2String(time() - $moduleAge{$file});
+    my $age = (stat $file)[9];
+
+    if (!exists $moduleAge{$file}) {
+       &DEBUG("Looks like $file was not loaded; fixing.");
+    } else {
+       return if ($age == $moduleAge{$file});
+
+       if ($age < $moduleAge{$file}) {
+           &WARN("rM: we're not gonna downgrade the file. use 'touch'.");
+           return;
+       }
+
+       my $dc  = &Time2String($age   - $moduleAge{$file});
+       my $ago = &Time2String(time() - $moduleAge{$file});
+
+       &VERB("Module:  delta change: $dc",2);
+       &VERB("Module:           ago: $ago",2);
+    }
 
     &status("Module: Loading $mod...");
-    &VERB("Module:  delta change: $dc",2);
-    &VERB("Module:           ago: $ago",2);
 
     delete $INC{$file};
     eval "require \"$file\"";  # require or use?
@@ -355,10 +373,15 @@ if ($@) {
 sub AUTOLOAD {
     return if ($AUTOLOAD =~ /__/);     # internal.
 
-    &ERROR("UNKNOWN FUNCTION CALLED: $AUTOLOAD");
-    foreach (@_) {
-       next unless (defined $_);
-       &status("  => $_");
+    my $str = join(', ', @_);
+    &ERROR("UNKNOWN FUNCTION CALLED: $AUTOLOAD ($str)");
+
+    $AUTOLOAD =~ s/^(\S+):://g;
+
+    if (exists $myModules{lc $AUTOLOAD}) {
+       # hopefully this will work.
+       &DEBUG("Trying to load module $AUTOLOAD...");
+       &loadMyModule(lc $AUTOLOAD);
     }
 }