From: dms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Date: Sun, 6 Jan 2002 13:49:58 +0000 (+0000)
Subject: - modules: age of a few files were set to time(); use stat.  Fixed.
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=6fed910843baea1da9fcb74f679e17520054dc15;p=infobot.git

- modules: age of a few files were set to time(); use stat.  Fixed.
- validChan: check for undefine arg; check for $c{$c} to avoid creating it.
- chanservCheck: check for $c{$c} to avoid creating it.
- factoidCheck: now deferred.


git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@542 c11ca15a-4712-0410-83d8-924469b57eb5
---

diff --git a/blootbot/src/IRC/Irc.pl b/blootbot/src/IRC/Irc.pl
index e8a3a92..6b35bca 100644
--- a/blootbot/src/IRC/Irc.pl
+++ b/blootbot/src/IRC/Irc.pl
@@ -717,14 +717,20 @@ sub IsNickInAnyChan {
 
 # Usage: &validChan($chan);
 sub validChan {
+    # todo: use $c instead?
     my ($chan) = @_;
 
+    if (!defined $chan or $chan =~ /^\s*$/) {
+	return 0;
+    }
+
     if (lc $chan ne $chan) {
 	&WARN("validChan: lc chan != chan. ($chan); fixing.");
 	$chan =~ tr/A-Z/a-z/;
     }
 
-    if (exists $channels{$chan}) {
+    # it's possible that this check creates the hash if empty.
+    if (defined $channels{$chan} or exists $channels{$chan}) {
 	if ($chan eq "_default") {
 #	    &WARN("validC: chan cannot be _default! returning 0!");
 	    return 0;
diff --git a/blootbot/src/IRC/IrcHelpers.pl b/blootbot/src/IRC/IrcHelpers.pl
index 0bc344d..2ce1acb 100644
--- a/blootbot/src/IRC/IrcHelpers.pl
+++ b/blootbot/src/IRC/IrcHelpers.pl
@@ -321,7 +321,7 @@ sub chanLimitVerify {
 sub chanServCheck {
     ($chan) = @_;
 
-    if (!defined $chan or $chan =~ /^$/) {
+    if (!defined $chan or $chan =~ /^\s*$/) {
 	&WARN("chanServCheck: chan == NULL.");
 	return 0;
     }
@@ -341,7 +341,11 @@ sub chanServCheck {
 	&rawout("WHO NickServ");
 	return 0;
     }
-    return 0 if (exists $channels{$chan}{'o'}{$ident});
+    # check for first hash then for next hash.
+    # todo: a function for &ischanop()? &isvoice()?
+    if (exists $channels{$chan} and exists $channels{$chan}{'o'}{$ident}) {
+	return 0;
+    }
 
     &status("ChanServ ==> Requesting ops for $chan. (chanServCheck)");
     &rawout("PRIVMSG ChanServ :OP $chan $ident");
diff --git a/blootbot/src/IRC/Schedulers.pl b/blootbot/src/IRC/Schedulers.pl
index 2077d48..54ada62 100644
--- a/blootbot/src/IRC/Schedulers.pl
+++ b/blootbot/src/IRC/Schedulers.pl
@@ -37,7 +37,7 @@ sub setupSchedulers {
     &freshmeatLoop(2);
     &kernelLoop(2);
     &wingateWriteFile(2);
-    &factoidCheck(1);
+    &factoidCheck(2);	# takes a couple of seconds on a 486. defer it
     &newsFlush(1);
 
 #    my $count = map { exists $sched{$_}{TIME} } keys %sched;
diff --git a/blootbot/src/modules.pl b/blootbot/src/modules.pl
index c567c2e..bea0f2e 100644
--- a/blootbot/src/modules.pl
+++ b/blootbot/src/modules.pl
@@ -76,7 +76,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";
@@ -87,8 +88,9 @@ sub loadDBModules {
 	&showProc(" (DBI // mysql)");
 
 	&status("  using MySQL support.");
-	require "$bot_src_dir/db_mysql.pl";
-	$moduleAge{"$bot_src_dir/db_mysql.pl"} = time();
+	$f = "$bot_src_dir/db_mysql.pl";
+	require $f;
+	$moduleAge{$f} = (stat $f)[9];
 
     } elsif ($param{'DBType'} =~ /^pgsql$/i) {
 #	eval "use Pg";
@@ -248,6 +250,8 @@ sub reloadModule {
 
 	if ($age < $moduleAge{$file}) {
 	    &WARN("rM: we're not gonna downgrade '$file'; use touch.");
+	    &DEBUG("age => $age");
+	    &DEBUG("mA{$file} => $moduleAge{$file}");
 	    return;
 	}