]> git.donarmstrong.com Git - infobot.git/blobdiff - blootbot/src/IRC/IrcHooks.pl
- ircTextCounters stuff moved into a separate function.
[infobot.git] / blootbot / src / IRC / IrcHooks.pl
index 87c5f904e8b8a7aaa6ebbeb1d3fd27b90feac1d4..e8eb96280c3968aa234c27d902bf7e2ab3f9e242 100644 (file)
@@ -5,8 +5,6 @@
 #        NOTE: Based on code by Kevin Lenzo & Patrick Cole  (c) 1997
 #
 
-# use strict;  # TODO
-
 # GENERIC. TO COPY.
 sub on_generic {
     my ($self, $event) = @_;
@@ -869,33 +867,36 @@ sub on_public {
        $userstats{lc $nick}{'Time'} = time();
     }
 
-    # would this slow things down?
-    if ($_ = &getChanConf("ircTextCounters")) {
-       my $time = time();
-
-       foreach (split /[\s]+/) {
-           my $x = $_;
+    # cache it.
+    my $time   = time();
+    if (!$cache{ircTextCounters}) {
+       &DEBUG("caching ircTextCounters for first time.");
+       my @str = split(/\s+/, &getChanConf("ircTextCounters"));
+       for (@str) { $_ = quotemeta($_); }
+       $cache{ircTextCounters} = join('|', @str);
+    }
 
-           # either full word or ends with a space, etc...
-           next unless ($msg =~ /^\Q$x\E[\$\s!.]/i);
+    my $str = $cache{ircTextCounters};
+    if ($str && $msg =~ /^($str)[\s!\.]?$/i) {
+       my $x = $1;
 
-           &VERB("textcounters: $x matched for $who",2);
-           my $c = $chan || "PRIVATE";
+       &VERB("textcounters: $x matched for $who",2);
+       my $c = $chan || "PRIVATE";
 
-           my ($v,$t) = &sqlSelect("stats", "counter,time", {
+       # better to do "counter=counter+1".
+       # but that will avoid time check.
+       my ($v,$t) = &sqlSelect("stats", "counter,time", {
                        nick    => $who,
                        type    => $x,
                        channel => $c,
-           } );
-           $v++;
-
-           # don't allow ppl to cheat the stats :-)
-           next unless (defined $t);
-           next unless ($time - $t > 10);
+       } );
+       $v++;
 
+       # don't allow ppl to cheat the stats :-)
+       if (defined $t && $time - $t > 60) { 
            &sqlReplace("stats", {
-               nick => $who,
-               type => $x,
+               nick    => $who,
+               type    => $x,
                channel => $c,
                time    => $time,
                counter => $v,