- if (&IsChanConf("seenStats")) {
- $userstats{lc $nick}{'Count'}++;
- $userstats{lc $nick}{'Time'} = time();
- }
-
- # would this slow things down?
- if ($_ = &getChanConf("ircTextCounters")) {
- my $time = time();
-
- foreach (split /[\s]+/) {
- my $x = $_;
-
- # either full word or ends with a space, etc...
- next unless ($msg =~ /^\Q$x\E[\$\s!.]/i);
-
- &VERB("textcounters: $x matched for $who",2);
- my $c = $chan || "PRIVATE";
-
- my ($v,$t) = &dbGet("stats", "counter,time",
- "nick=". &dbQuote($who)
- ." AND type=".&dbQuote($x)
- ." AND channel=".&dbQuote($c)
- );
- $v++;
-
- # don't allow ppl to cheat the stats :-)
- next unless ($time - $t > 10);
-
- my %hash = (
- nick => $who,
- type => $x,
- channel => $c,
-
- time => $time,
- counter => $v,
- );
-
-
- &dbReplace("stats", "nick", %hash);
- # does not work, atleast with old mysql!!! :(
-# &dbReplace("stats", (nick => $who, type => $x, -counter => "counter+1") );
- }
- }
-
- &hookMsg('public', $chan, $nick, $msg);
+ if ( &IsChanConf('seenStats') > 0 ) {
+ $userstats{ lc $nick }{'Count'}++;
+ $userstats{ lc $nick }{'Time'} = time();
+ }
+
+ # 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 );
+ }
+
+ my $str = $cache{ircTextCounters};
+ if ( $str && $msg =~ /^($str)[\s!\.]?$/i ) {
+ my $x = $1;
+
+ &VERB( "textcounters: $x matched for $who", 2 );
+ my $c = $chan || 'PRIVATE';
+
+ # 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 :-)
+ if ( ( defined $t && $time - $t > 60 ) or ( !defined $t ) ) {
+ &sqlSet(
+ 'stats',
+ {
+ 'nick' => $who,
+ 'type' => $x,
+ 'channel' => $c,
+ },
+ {
+ time => $time,
+ counter => $v,
+ }
+ );
+ }
+ }
+
+ &hookMsg( 'public', $chan, $nick, $msg );