]> git.donarmstrong.com Git - infobot.git/blobdiff - src/modules.pl
A round of fixes:
[infobot.git] / src / modules.pl
index ef18cbbe094de55a4977a4e7914b8be9f1b130c8..30c5a40c8d9d2d2113ab89e7d0f159ec9bf4e5c4 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 {
@@ -184,11 +192,9 @@ sub loadMyModulesNow {
            next;
        }
 
-       &DEBUG("_ => $_");
-
-       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.");
            }
@@ -200,7 +206,7 @@ sub loadMyModulesNow {
        $loaded++;
     }
 
-    &status("Module: Loaded/Total [$loaded/$total]");
+    &status("Module: Runtime: Loaded/Total [$loaded/$total]");
 }
 
 ### rename to moduleReloadAll?
@@ -233,25 +239,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?