]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Misc.pl
- irctextcounters: add percentage to top3
[infobot.git] / src / Misc.pl
index ce98779918eb42a8f7046b837bfad065a0812c43..ffc6fb6467a5f19784abed4c9969873d57b82998 100644 (file)
@@ -453,11 +453,9 @@ sub isStale {
     return 1 unless ( -f $file);
     if ($file =~ /idx/) {
        my $age2 = time() - (stat($file))[9];
-       &DEBUG("stale: $age2. (". &Time2String($age2) .")");
+       &VERB("stale: $age2. (". &Time2String($age2) .")",2);
     }
     $age *= 60*60*24 if ($age >= 0 and $age < 30);
-    &DEBUG("age = $age");
-    &DEBUG("... = ".(stat $file)[9] );
 
     return 1 if (time() - (stat($file))[9] > $age);
     return 0;
@@ -469,15 +467,21 @@ sub isStale {
 
 # Usage: &makeHostMask($host);
 sub makeHostMask {
-    my ($host) = @_;
+    my ($host) = @_;
+    my $nu     = "";
+
+    if ($host =~ s/^(\S+!\S+\@)//) {
+       &DEBUG("mHM: detected nick!user\@ for host arg; fixing");
+       $nu = $1;
+    }
 
     if ($host =~ /^$mask{ip}$/) {
-       return "$1.$2.$3.*";
+       return $nu."$1.$2.$3.*";
     }
 
     my @array = split(/\./, $host);
-    return $host if (scalar @array <= 3);
-    return "*.".join('.',@{array}[1..$#array]);
+    return $nu.$host if (scalar @array <= 3);
+    return $nu."*.".join('.',@{array}[1..$#array]);
 }
 
 # Usage: &makeRandom(int);
@@ -695,4 +699,19 @@ sub mkcrypt {
     return crypt($str, $salt);
 }
 
+sub closeStats {
+    return unless (&getChanConfList("ircTextCounters"));
+
+    foreach (keys %cmdstats) {
+       my $type        = $_;
+       my $i = &dbGet("stats", "counter", "nick=".&dbQuote($type).
+                       " AND type='cmdstats'");
+       $i      += $cmdstats{$type};
+
+       &dbReplace("stats",
+               (nick => $type, type => "cmdstats", counter => $i)
+       );
+    }
+}
+
 1;