]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Misc.pl
show modified by in factinfo
[infobot.git] / src / Misc.pl
index 0b39297c98d5cc97f7d8a1bc6ff42a481f819c47..68e4fa4c3a7275426bf88a110a065af0522d5e1c 100644 (file)
@@ -5,18 +5,18 @@
 #      NOTE: Based on code by Kevin Lenzo & Patrick Cole  (c) 1997
 #
 
-if (&IsParam("useStrict")) { use strict; }
+#use strict;
 
 sub help {
     my $topic = shift;
-    my $file  = $bot_misc_dir."/blootbot.help";
+    my $file  = $bot_data_dir."/blootbot.help";
     my %help  = ();
 
     # crude hack for pSReply() to work as expected.
     $msgType = "private" if ($msgType eq "public");
 
     if (!open(FILE, $file)) {
-       &ERROR("FAILED loadHelp ($file): $!");
+       &ERROR("Failed reading help file ($file): $!");
        return;
     }
 
@@ -66,7 +66,7 @@ sub help {
 
     if (exists $help{$topic}) {
        foreach (split /\n/, $help{$topic}) {
-           &performStrictReply($_);
+           &pSReply($_);
        }
     } else {
        &pSReply("no help on $topic.  Use 'help' without arguments.");
@@ -200,9 +200,9 @@ sub fixFileList {
 
     # generate a hash list.
     foreach (@files) {
-       if (/^(.*\/)(.*?)$/) {
-           $files{$1}{$2} = 1;
-       }
+       next unless /^(.*\/)(.*?)$/;
+
+       $files{$1}{$2} = 1;
     }
     @files = ();       # reuse the array.
 
@@ -295,30 +295,27 @@ sub fixPlural {
 sub getRandomLineFromFile {
     my($file) = @_;
 
-    if (! -f $file) {
-       &WARN("gRLfF: file '$file' does not exist.");
+    if (!open(IN, $file)) {
+       &WARN("gRLfF: could not open ($file): $!");
        return;
     }
 
-    if (open(IN,$file)) {
-       my @lines = <IN>;
+    my @lines = <IN>;
+    close IN;
 
-       if (!scalar @lines) {
-           &ERROR("GRLF: nothing loaded?");
-           return;
-       }
+    if (!scalar @lines) {
+       &ERROR("GRLF: nothing loaded?");
+       return;
+    }
 
-       while (my $line = &getRandom(@lines)) {
-           chop $line;
+    # could we use the filehandler instead and put it through getRandom?
+    while (my $line = &getRandom(@lines)) {
+       chop $line;
 
-           next if ($line =~ /^\#/);
-           next if ($line =~ /^\s*$/);
+       next if ($line =~ /^\#/);
+       next if ($line =~ /^\s*$/);
 
-           return $line;
-       }
-    } else {
-       &WARN("gRLfF: could not open file '$file'.");
-       return;
+       return $line;
     }
 }
 
@@ -343,7 +340,7 @@ sub getLineFromFile {
        chop $line;
        return $line;
     } else {
-       &ERROR("getLineFromFile: could not open file '$file'.");
+       &ERROR("gLFF: Could not open file ($file): $!");
        return 0;
     }
 }
@@ -416,7 +413,10 @@ sub IsHostMatch {
        $local{'host'} = &makeHostMask(lc $3);
     }
 
-    if ($thisnuh =~ /^(\S+)!(\S+)@(\S+)/) {
+    if (!defined $thisnuh) {
+       &WARN("IHM: thisnuh == NULL.");
+       return 0;
+    } elsif ($thisnuh =~ /^(\S+)!(\S+)@(\S+)/) {
        $this{'nick'} = lc $1;
        $this{'user'} = lc $2;
        $this{'host'} = &makeHostMask(lc $3);
@@ -475,6 +475,7 @@ sub makeHostMask {
 
     if ($host =~ s/^(\S+!\S+\@)//) {
        &DEBUG("mHM: detected nick!user\@ for host arg; fixing");
+       &DEBUG("nu => $nu");
        $nu = $1;
     }
 
@@ -642,7 +643,7 @@ sub closeStats {
        );              
        $hash{time} = time() if ($z);
 
-       &dbReplace("stats", %hash);
+       &dbReplace("stats", "nick", %hash);
     }
 }