]> git.donarmstrong.com Git - infobot.git/blobdiff - src/core.pl
IRC/IrcHooks.pl
[infobot.git] / src / core.pl
index 2b8b36e5eeb1ca9cf6dd428551999ae3941b6199..aec5affb884601762386f3c726e5851d7e5c9a92 100644 (file)
@@ -55,8 +55,7 @@ $utime_chanfile       = 0;
 $wtime_chanfile        = 0;
 $ucount_chanfile = 0;
 
-### CHANGE TO STATIC.
-$bot_version = "blootbot cvs (20001212) -- $^O";
+$bot_version   = "blootbot cvs (20010214) -- $^O";
 $noreply       = "NOREPLY";
 
 ##########
@@ -86,6 +85,7 @@ sub doExit {
        &writeUserFile();
        &writeChanFile();
        &uptimeWriteFile()      if (&ChanConfList("uptime"));
+       &News::writeNews()      if (&ChanConfList("news"));
        &closeDB();
        &closeSHM($shm);
        &dumpallvars()          if (&IsParam("dumpvarsAtExit"));
@@ -131,8 +131,11 @@ sub ChanConfList {
     return unless (defined $param);
     my %chan   = &getChanConfList($param);
 
-    ### TODO: -option is included aswell though.
-    return keys %chan;
+    if (exists $chan{_default}) {
+       return keys %chanconf;
+    } else {
+       return keys %chan;
+    }
 }
 
 #####
@@ -172,24 +175,53 @@ sub getChanConfList {
 # Return: 1 for enabled, 0 for passive disable, -1 for active disable.
 sub IsChanConf {
     my($param) = shift;
+    my $debug  = 0;    # knocked tons of bugs with this! :)
 
     if (!defined $param) {
-       &WARN("param == NULL.");
+       &WARN("IsChanConf: param == NULL.");
        return 0;
     }
 
+    if ($chan =~ tr/A-Z/a-z/) {
+       &WARN("IsChanConf: lowercased chan.");
+    }
+
     ### TODO: VERBOSITY on how chanconf returned 1 or 0 or -1.
     my %chan   = &getChanConfList($param);
-    if (!defined $msgType) {
-       return $chan{_default} || 0;
+    if (!defined $msgType or $msgType eq "") {
+       if ($chan{$chan}) {
+           &DEBUG("ICC: !msgType: $chan{$chan} (_default/$param)") if ($debug);
+       } elsif ($chan{_default}) {
+           &DEBUG("ICC: !msgType: $chan{_default} (_default/$param)") if ($debug);
+       } else {
+           &DEBUG("ICC: !msgType: 0 ($param)") if ($debug);
+       }
+
+       return $chan{$chan} || $chan{_default} || 0;
     }
 
     if ($msgType eq "public") {
-       return $chan{lc $chan} || $chan{_default} || 0;
+       if ($chan{$chan}) {
+           &DEBUG("ICC: public: $chan{$chan} ($chan/$param)") if ($debug);
+       } elsif ($chan{_default}) {
+           &DEBUG("ICC: public: $chan{_default} (_default/$param)") if ($debug);
+       } else {
+           &DEBUG("ICC: public: 0 ($param)") if ($debug);
+       }
+
+       return $chan{$chan} || $chan{_default} || 0;
     }
 
     if ($msgType eq "private") {
-       return $chan{_default} || 0;
+       if ($chan{_default}) {
+           &DEBUG("ICC: private: $chan{_default} (_default/$param)") if ($debug);
+       } elsif ($chan{$chan}) {
+           &DEBUG("ICC: private: $chan{$chan} ($chan/$param) (hack)") if ($debug);
+       } else {
+           &DEBUG("ICC: private: 0 ($param)") if ($debug);
+       }
+
+       return $chan{$chan} || $chan{_default} || 0;
     }
 
 ### debug purposes only.
@@ -198,6 +230,8 @@ sub IsChanConf {
 #      &DEBUG("   $_ => $chan{$_}");
 #    }
 
+    &DEBUG("ICC: no-match: 0/$param (msgType = $msgType)");
+
     return 0;
 }
 
@@ -237,29 +271,37 @@ sub showProc {
        }
        close IN;
 
-       if (defined $memusageOld and &IsParam("DEBUG")) {
-           # it's always going to be increase.
-           my $delta = $memusage - $memusageOld;
-           my $str;
-           if ($delta == 0) {
-               return;
-           } elsif ($delta > 500) {
-               $str = "MEM:$prefix increased by $delta kB. (total: $memusage kB)";
-           } elsif ($delta > 0) {
-               $str = "MEM:$prefix increased by $delta kB";
-           } else {    # delta < 0.
-               $delta = -$delta;
-               # never knew RSS could decrease, probably Size can't?
-               $str = "MEM:$prefix decreased by $delta kB. YES YES YES";
-           }
-
-           &status($str);
-       }
-       $memusageOld = $memusage;
+    } elsif ($^O eq "netbsd") {
+       $memusage = (stat "/proc/$$/mem")[7]/1024;
+
+    } elsif ($^O =~ /^(free|open)bsd$/) {
+       my @info  = split /\s+/, `/bin/ps -l -p $$`;
+       $memusage = $info[20];
+
     } else {
        $memusage = "UNKNOWN";
+       return;
     }
-    ### TODO: FreeBSD/*BSD support.
+
+    if (defined $memusageOld and &IsParam("DEBUG")) {
+       # it's always going to be increase.
+       my $delta = $memusage - $memusageOld;
+       my $str;
+       if ($delta == 0) {
+           return;
+       } elsif ($delta > 500) {
+           $str = "MEM:$prefix increased by $delta kB. (total: $memusage kB)";
+       } elsif ($delta > 0) {
+           $str = "MEM:$prefix increased by $delta kB";
+       } else {        # delta < 0.
+           $delta = -$delta;
+           # never knew RSS could decrease, probably Size can't?
+           $str = "MEM:$prefix decreased by $delta kB. YES YES YES";
+       }
+
+       &status($str);
+    }
+    $memusageOld = $memusage;
 }
 
 ######
@@ -280,7 +322,7 @@ sub setup {
 
     # read.
     &loadLang($bot_misc_dir.           "/blootbot.lang");
-    &loadIRCServers($bot_misc_dir.     "/ircII.servers");
+    &loadIRCServers();
     &readUserFile();
     &readChanFile();
     &loadMyModulesNow();       # must be after chan file.
@@ -290,6 +332,7 @@ sub setup {
     &openDB($param{'DBName'}, $param{'SQLUser'}, $param{'SQLPass'});
 
     &status("Setup: ". &countKeys("factoids") ." factoids.");
+    &News::readNews() if (&ChanConfList("news"));
 
     $param{tempDir} =~ s#\~/#$ENV{HOME}/#;
 
@@ -342,6 +385,12 @@ sub shutdown {
     # reverse order of &setup().
     &DEBUG("shutdown called.");
 
+    # opened files must be written to on shutdown/hup/whatever
+    # unless they're write-only, like uptime.
+    &writeUserFile();
+    &writeChanFile();
+    &News::writeNews() if (&ChanConfList("news"));
+
     &closeDB();
     &closeSHM($shm);   # aswell. TODO: use this in &doExit?
     &closeLog();