From d945e2726ea8cd6c2c6a997d5e683b0af8e47ddb Mon Sep 17 00:00:00 2001
From: dms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Date: Mon, 21 May 2001 13:11:45 +0000
Subject: [PATCH] - if autoload fails, make poor attempt to load module. -
 modified Question() to use substVars() - added hack for "me => $who" - don't
 do factoidDeleteDelay if stale is invalid. - fixed typo in rootWarn.

git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@493 c11ca15a-4712-0410-83d8-924469b57eb5
---
 blootbot/src/Factoids/Question.pl | 21 +++++++++++++++++----
 blootbot/src/Factoids/Reply.pl    |  9 ++++++---
 blootbot/src/IRC/Schedulers.pl    |  5 +++++
 blootbot/src/Modules/RootWarn.pl  |  4 ++--
 blootbot/src/modules.pl           | 13 +++++++++----
 5 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/blootbot/src/Factoids/Question.pl b/blootbot/src/Factoids/Question.pl
index a5ced7b..fa73b9f 100644
--- a/blootbot/src/Factoids/Question.pl
+++ b/blootbot/src/Factoids/Question.pl
@@ -195,6 +195,8 @@ sub factoidArgs {
 
 	next unless (@vals);
 
+	&DEBUG("vals => @vals");
+
 	&status("Question: factoid Arguments for '$str'");
 	# todo: use getReply() - need to modify it :(
 	my $i	= 0;
@@ -203,18 +205,29 @@ sub factoidArgs {
 
 	foreach ( split(',', $1) ) {
 	    my $val = $vals[$i];
+	    &DEBUG("val => $val");
 	    if (!defined $val) {
 		&status("factArgs: vals[$i] == undef; not SARing '$_' for '$str'");
 		next;
 	    }
 
-	    if ($result = &substVars($result)) {
-		# hrm...
-	    } else {
+	    my $done = 0;
+	    my $old = $result;
+	    while (1) {
+		$result = &substVars($result,1);
+		last if ($old eq $result);
+		$old = $result;
+		$done++;
+	    }
+
+	    # hack.
+	    $vals[$i] =~ s/^me$/$who/gi;
+
+	    if (!$done) {
 		&status("factArgs: SARing '$_' to '$vals[$i]'.");
 		$result =~ s/\Q$_\E/$vals[$i]/;
-		$i++;
 	    }
+	    $i++;
 	}
 
 	# nasty hack to get partial &getReply() functionality.
diff --git a/blootbot/src/Factoids/Reply.pl b/blootbot/src/Factoids/Reply.pl
index 78c13d8..dbe9336 100644
--- a/blootbot/src/Factoids/Reply.pl
+++ b/blootbot/src/Factoids/Reply.pl
@@ -243,7 +243,7 @@ sub SARit {
 }
 
 sub substVars {
-    my($reply) = @_;
+    my($reply,$flag) = @_;
 
     # $date, $time.
     my $date	=  scalar(localtime());
@@ -253,8 +253,11 @@ sub substVars {
     $reply	=~ s/\$time/$date/gi;
 
     # dollar variables.
-    $reply	=~ s/\$nick/$who/g;
-    $reply	=~ s/\$who/$who/g;	# backward compat.
+    if ($flag) {
+	$reply	=~ s/\$nick/$who/g;
+	$reply	=~ s/\$who/$who/g;	# backward compat.
+    }
+
     if ($reply =~ /\$(user(name)?|host)/) {
 	my ($username, $hostname) = split /\@/, $uh;
 	$reply	=~ s/\$user(name)?/$username/g;
diff --git a/blootbot/src/IRC/Schedulers.pl b/blootbot/src/IRC/Schedulers.pl
index 300bf85..6032750 100644
--- a/blootbot/src/IRC/Schedulers.pl
+++ b/blootbot/src/IRC/Schedulers.pl
@@ -1047,6 +1047,11 @@ sub factoidCheck {
 
     my @list	= &searchTable("factoids", "factoid_key", "factoid_key", " #DEL#");
     my $stale	= &getChanConfDefault("factoidDeleteDelay", 30) *60*60*24;
+    if ($stale < 1) {
+	# disable it since it's "illegal".
+	return;
+    }
+
     &DEBUG("stale => $stale");
     my $time	= time();
 
diff --git a/blootbot/src/Modules/RootWarn.pl b/blootbot/src/Modules/RootWarn.pl
index 1cdae16..0cdc6a4 100644
--- a/blootbot/src/Modules/RootWarn.pl
+++ b/blootbot/src/Modules/RootWarn.pl
@@ -5,11 +5,11 @@
 #     Created: 19991008
 #
 
-use strict;
+### use strict;
 
 sub rootWarn {
     my ($nick,$user,$host,$chan) = @_;
-    my $attempt = &dbGet("rootwarn", "attempt", "nick='.lc($nick)."'") || 0;
+    my $attempt = &dbGet("rootwarn", "attempt", "nick='".lc($nick)."'") || 0;
     my $warnmode	= &getChanConf("rootWarnMode");
 
     if ($attempt == 0) {	# first timer.
diff --git a/blootbot/src/modules.pl b/blootbot/src/modules.pl
index 30c5a40..6aea9e0 100644
--- a/blootbot/src/modules.pl
+++ b/blootbot/src/modules.pl
@@ -369,10 +369,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);
     }
 }
 
-- 
2.39.5