]> git.donarmstrong.com Git - infobot.git/commitdiff
- added support of ircTextCounters - works! thanks to #perl@OPN.
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 18 May 2001 15:20:48 +0000 (15:20 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 18 May 2001 15:20:48 +0000 (15:20 +0000)
- minor change to listkeys/vals
- changed arguments to dbGet() - this breaks dbm support.
- remove karma table - created stats table instead.
- removed pub/msg/not sleep counters.
- dbReplace supports '-' for key for non-quoted value, like slashcode
- created SARit for Reply.pl - a bit cleaner now.
- Reply: attempted to move to &dbReplace but failed :(
- factoid arguments handling now works - fixed!
- factoid arguments: created &factoidArgs() - much cleaner.
- disabled automatic deletion of backed up factoids.

git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@491 c11ca15a-4712-0410-83d8-924469b57eb5

16 files changed:
src/CommandStubs.pl
src/Factoids/Question.pl
src/Factoids/Reply.pl
src/Factoids/Update.pl
src/IRC/Irc.pl
src/IRC/IrcHelpers.pl
src/IRC/IrcHooks.pl
src/IRC/Schedulers.pl
src/Modules/Freshmeat.pl
src/Modules/News.pl
src/Modules/RootWarn.pl
src/Process.pl
src/UserExtra.pl
src/core.pl
src/db_dbm.pl
src/db_mysql.pl

index 7b2ca5d37f198d9c6a29668a16000596ce0bb5b4..1a583dd4399af473c8f20b2ea17b6d44cf9a557b 100644 (file)
@@ -267,28 +267,66 @@ sub Modules {
        return;
     }
 
+    # text counters.
+    if ($_ = &getChanConf("ircTextCounters")) {
+       s/([^\w\s])/\\$1/g;
+       my $z = join '|', split ' ';
+
+       if ($message =~ /^($z)stats(\s+(\S+))?$/i) {
+           my $type    = $1;
+           my $arg     = $3;
+
+           if (!defined $arg or $arg =~ /^\s*$/) {
+               my $x = (&dbRawReturn("SELECT SUM(counter) FROM stats WHERE type=".&dbQuote($type) ))[0];
+
+               if (defined $x) {
+                   &pSReply("total count of '$type': $x");
+               } else {
+                   &pSReply("zero counter for '$type'.");
+               }
+           } else {
+               my $x = (&dbRawReturn("SELECT SUM(counter) FROM stats WHERE type=".
+                       &dbQuote($type)." AND nick=".&dbQuote($arg) ))[0];
+
+               if (defined $x) {       # defined.
+                   &pSReply("$arg has said $type $x times");
+               } else {                # !defined.
+                   &pSReply("$arg has not said $type yet.");
+               }
+           }
+
+           return;
+       }
+
+       if ($@) {
+           &DEBUG("regex failed: $@");
+           return;
+       }
+    }
+
     # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
     if ($message =~ /^list(\S+)( (.*))?$/i) {
        return unless (&hasParam("search"));
 
        my $thiscmd     = lc($1);
-       my $args        = $3;
-       $args           =~ s/\s+$//g;
-       # suggested by asuffield nad \broken.
-       if ($args =~ /^["']/ and $args =~ /["']$/) {
-           &DEBUG("list*: removed quotes.");
-           $args       =~ s/^["']|["']$//g;
-       }
-
-       $thiscmd =~ s/^vals$/values/;
+       $thiscmd        =~ s/^vals$/values/;
        return if ($thiscmd ne "keys" && $thiscmd ne "values");
 
+       my $args        = $3 || "";
+       $args           =~ s/\s+$//g;
+
        # Usage:
-       if (!defined $args) {
+       if (!defined $args or $args =~ /^\s*$/) {
            &help("list". $thiscmd);
            return;
        }
 
+       # suggested by asuffield and \broken.
+       if ($args =~ /^["']/ and $args =~ /["']$/) {
+           &DEBUG("list*: removed quotes.");
+           $args       =~ s/^["']|["']$//g;
+       }
+
        if (length $args == 1) {
            &msg($who,"search string is too short.");
            return;
@@ -484,7 +522,7 @@ sub seen {
     if ($person eq "random") {
        @seen = &randKey("seen", $select);
     } else {
-       @seen = &dbGet("seen", "nick", $person, $select);
+       @seen = &dbGet("seen", $select, "nick='$person'");
     }
 
     if (scalar @seen < 2) {
index 62feedfa7f67a4eb8e790ae4f5fc8d437969ed63..a5ced7be4eccce166a3a756538857a24ffb054c2 100644 (file)
@@ -81,62 +81,8 @@ sub doQuestion {
     }
 
     if (&IsChanConf("factoidArguments")) {
-       # to make it eleeter, split each arg and use "blah OR blah or BLAH"
-       # which will make it less than linear => quicker!
-       # todo: cache this, update cache when altered.
-       my @list = &searchTable("factoids", "factoid_key", "factoid_key", "CMD: ");
-
-       # from a design perspective, it's better to have the regex in
-       # the factoid key to reduce repetitive processing.
-
-       foreach (@list) {
-           s/^CMD: //;
-#          &DEBUG("factarg: ''$query[0]' =~ /^$_\$/'");
-           my @vals;
-           my $arg = $_;
-
-           # todo: make eval work with $$i's :(
-#          next unless (eval { $query[0] =~ /^$arg$/i });
-           next unless ($query[0] =~ /^$arg$/i);
-
-           if ($@) {   # it failed!!!
-               &WARN("factargs: regex failed! '$query[0]' =~ /^$_\$/");
-               next;
-           }
-
-               for ($i=1; $i<=5; $i++) {
-                   $val = $$i;
-                   last unless (defined $val);
-
-                   push(@vals, $val);
-               }
-#          };
-
-
-           &status("Question: factoid Arguments for '$query[0]'");
-           # todo: use getReply() - need to modify it :(
-           my $i       = 0;
-           my $result  = &getFactoid("CMD: $_");
-           $result     =~ s/^\((.*?)\): //;
-
-           foreach ( split(',', $1) ) {
-               my $val = $vals[$i];
-               if (!defined $val) {
-                   &status("factArgs: vals[$i] == undef; not SARing '$_' for '$query[0]'");
-                   next;
-               }
-
-               &status("factArgs: SARing '$_' to '$vals[$i]'.");
-               $result =~ s/\Q$_\E/$vals[$i]/;
-               $i++;
-           }
-
-           # nasty hack to get partial &getReply() functionality.
-           $result =~ s/^\s*<action>\s*(.*)/\cAACTION $1\cA/i;
-           $result =~ s/^\s*<reply>\s*//i;
-
-           return $result;
-       }
+       $result = &factoidArgs($query[0]);
+       return $result if (defined $result);
     }
 
     my @link;
@@ -210,4 +156,77 @@ sub doQuestion {
     return $reply;
 }
 
+sub factoidArgs {
+    my($str)   = @_;
+    my $result;
+
+    # to make it eleeter, split each arg and use "blah OR blah or BLAH"
+    # which will make it less than linear => quicker!
+    # todo: cache this, update cache when altered.
+    my @list = &searchTable("factoids", "factoid_key", "factoid_key", "CMD: ");
+
+    # from a design perspective, it's better to have the regex in
+    # the factoid key to reduce repetitive processing.
+
+    foreach (@list) {
+       next if (/#DEL#/);      # deleted.
+
+       s/^CMD: //;
+#      &DEBUG("factarg: ''$str' =~ /^$_\$/'");
+       my @vals;
+       my $arg = $_;
+
+       # todo: make eval work with $$i's :(
+       eval {
+           if ($str =~ /^$arg$/i) {
+               for ($i=1; $i<=5; $i++) {
+                   $val = $$i;
+                   last unless (defined $val);
+
+                   push(@vals, $val);
+               }
+           }
+       };
+
+       if ($@) {   # it failed!!!
+           &WARN("factargs: regex failed! '$str' =~ /^$_\$/");
+           next;
+       }
+
+       next unless (@vals);
+
+       &status("Question: factoid Arguments for '$str'");
+       # todo: use getReply() - need to modify it :(
+       my $i   = 0;
+       $result = &getFactoid("CMD: $_");
+       $result =~ s/^\((.*?)\): //;
+
+       foreach ( split(',', $1) ) {
+           my $val = $vals[$i];
+           if (!defined $val) {
+               &status("factArgs: vals[$i] == undef; not SARing '$_' for '$str'");
+               next;
+           }
+
+           if ($result = &substVars($result)) {
+               # hrm...
+           } else {
+               &status("factArgs: SARing '$_' to '$vals[$i]'.");
+               $result =~ s/\Q$_\E/$vals[$i]/;
+               $i++;
+           }
+       }
+
+       # nasty hack to get partial &getReply() functionality.
+       $result =~ s/^\s*<action>\s*(.*)/\cAACTION $1\cA/i;
+       $result =~ s/^\s*<reply>\s*//i;
+       $result = &SARit($result);
+#      $result = &substVars($result);
+
+       return $result;
+    }
+
+    return;
+}
+
 1;
index 5fda25f1c0dbe2b7b36e8f15d80645fce9da23e5..78c13d876be57231c52e292d62f791b76b97d373 100644 (file)
@@ -48,67 +48,32 @@ sub getReply {
        $result =~ s/^\s*//;
     }
 
-    my $fauthor = &dbGet("factoids", "factoid_key", $message, "created_by");
-    ### we need non-evaluating regex like in factoid sar.
-    if ($msgType =~ /^private$/) {
-       if (0 and defined $fauthor and $fauthor =~ /^\Q$who\E\!/i) {
-           &status("Reply.pl: author requested own factoid in private; literal!");
-           $literal = 1;
-       }
-    } else {
-       my $done = 0;
-
-       # (blah1|blah2)?
-       while ($result =~ /\((.*?)\)\?/) {
-           my $str = $1;
-           if (rand() > 0.5) {         # fix.
-               &status("Factoid transform: keeping '$str'.");
-               $result =~ s/\(\Q$str\E\)\?/$str/;
-           } else {                    # remove
-               &status("Factoid transform: removing '$str'.");
-               $result =~ s/\(\Q$str\E\)\?\s?//;
-           }
-           $done++;
-           last if ($done >= 10);      # just in case.
-       }
-       $done = 0;
-
-       # EG: (0-32768) => 6325
-       ### TODO: (1-10,20-30,40) => 24
-       while ($result =~ /\((\d+)-(\d+)\)/) {
-           my ($lower,$upper) = ($1,$2);
-           my $new = int(rand $upper-$lower) + $lower;
-
-           &status("Reply.pl: SARing '$&' to '$new'.");
-           $result =~ s/$&/$new/;
-           $done++;
-           last if ($done >= 10);      # just in case.
-       }
-       $done = 0;
-
-       # EG: (blah1|blah2|blah3|) => blah1
-       while ($result =~ /.*\((.*\|.*?)\).*/) {
-           $result = &smart_replace($result);
-
-           $done++;
-           last if ($done >= 10);      # just in case.
-       }
-       &status("Reply.pl: $done SARs done.") if ($done);
-    }
+    my $fauthor = &dbGet("factoids", "created_by", "factoid_key='$message'");
+    $result    = &SARit($result);
 
-    $reply = $result;
+    $reply     = $result;
     if ($result ne "") {
        ### AT LAST, REPEAT PREVENTION CODE REMOVED IN FAVOUR OF GLOBAL
        ### FLOOD REPETION AND PROTECTION. -20000124
 
        # stats code.
-       &setFactInfo($lhs,"requested_by", $nuh);
-       &setFactInfo($lhs,"requested_time", time());
        ### FIXME: old mysql doesn't support
-       ###     "requested_count=requested_count+1".
+       ### "requested_count=requested_count+1".
        my $count = &getFactInfo($lhs,"requested_count") || 0;
        $count++;
-       &setFactInfo($lhs,"requested_count", $count);
+       ### BROKEN!!!
+       if (1) {        # old code.
+           &setFactInfo($lhs,"requested_by", $nuh);
+           &setFactInfo($lhs,"requested_time", time());
+           &setFactInfo($lhs,"requested_count", $count);
+       } else {
+           &dbReplace("factoids", (
+               factoid_key     => $lhs,
+               requested_by    => $nuh,
+               requested_time  => time(),
+               requested_count => $count
+           ) );
+       }
 
        # todo: rename $real to something else!
        my $real   = 0;
@@ -170,7 +135,116 @@ sub getReply {
     ###
     ### $ SUBSTITUTION.
     ###
+
+    $reply = &substVars($reply);
     
+    $reply;
+}
+
+sub smart_replace {
+    my ($string) = @_;
+    my ($l,$r) = (0,0);        # l = left,  r = right.
+    my ($s,$t) = (0,0);        # s = start, t = marker.
+    my $i      = 0;
+    my $old    = $string;
+    my @rand;
+
+    foreach (split //, $string) {
+
+       if ($_ eq "(") {
+###        print "( l=>$l, r=>$r\n";
+
+           if (!$l and !$r) {
+#              print "STARTING at $i\n";
+               $s = $i;
+               $t = $i;
+           }
+
+           $l++;
+           $r--;
+       }
+
+       if ($_ eq ")") {
+###        print ") l=>$l, r=>$r\n";
+
+           $r++;
+           $l--;
+
+           if (!$l and !$r) {
+               my $substr = substr($old,$s,$i-$s+1);
+#              print "STOP at $i $substr\n";
+               push(@rand, substr($old,$t+1,$i-$t-1) );
+
+               my $rand = $rand[rand @rand];
+               &status("SARing '$substr' to '$rand'.");
+               $string =~ s/\Q$substr\E/$rand/;
+               undef @rand;
+           }
+       }
+
+       if ($_ eq "|" and $l+$r== 0 and $l==1) {
+#          print "| at $i (l=>$l,r=>$r)\n";
+           push(@rand, substr($old,$t+1,$i-$t-1) );
+           $t = $i;
+       }
+
+       $i++;
+    }
+
+    if ($old eq $string) {
+       &WARN("smart_replace: no subst made. (string => $string)");
+    }
+
+    return $string;
+}
+
+sub SARit {
+    my($txt) = @_;
+    my $done = 0;
+
+    # (blah1|blah2)?
+    while ($txt =~ /\((.*?)\)\?/) {
+       my $str = $1;
+       if (rand() > 0.5) {             # fix.
+           &status("Factoid transform: keeping '$str'.");
+           $txt =~ s/\(\Q$str\E\)\?/$str/;
+       } else {                        # remove
+           &status("Factoid transform: removing '$str'.");
+           $txt =~ s/\(\Q$str\E\)\?\s?//;
+       }
+       $done++;
+       last if ($done >= 10);  # just in case.
+    }
+    $done = 0;
+
+    # EG: (0-32768) => 6325
+    ### TODO: (1-10,20-30,40) => 24
+    while ($txt =~ /\((\d+)-(\d+)\)/) {
+       my ($lower,$upper) = ($1,$2);
+       my $new = int(rand $upper-$lower) + $lower;
+
+       &status("SARing '$&' to '$new' (2).");
+       $txt =~ s/$&/$new/;
+       $done++;
+       last if ($done >= 10);  # just in case.
+    }
+    $done = 0;
+
+    # EG: (blah1|blah2|blah3|) => blah1
+    while ($txt =~ /.*\((.*\|.*?)\).*/) {
+       $txt = &smart_replace($txt);
+
+       $done++;
+       last if ($done >= 10);  # just in case.
+    }
+    &status("Reply.pl: $done SARs done.") if ($done);
+
+    return $txt;
+}
+
+sub substVars {
+    my($reply) = @_;
+
     # $date, $time.
     my $date   =  scalar(localtime());
     $date      =~ s/\:\d+(\s+\w+)\s+\d+$/$1/;
@@ -250,64 +324,7 @@ sub getReply {
 
     $reply     =~ s/\$memusage/$memusage/;
 
-    $reply;
-}
-
-sub smart_replace {
-    my ($string) = @_;
-    my ($l,$r) = (0,0);                # l = left,  r = right.
-    my ($s,$t) = (0,0);                # s = start, t = marker.
-    my $i = 0;
-    my @rand;
-    my $old = $string;
-
-    foreach (split //, $string) {
-
-       if ($_ eq "(") {
-###        print "( l=>$l, r=>$r\n";
-
-           if (!$l and !$r) {
-#              print "STARTING at $i\n";
-               $s = $i;
-               $t = $i;
-           }
-
-           $l++;
-           $r--;
-       }
-
-       if ($_ eq ")") {
-###        print ") l=>$l, r=>$r\n";
-
-           $r++;
-           $l--;
-
-           if (!$l and !$r) {
-               my $substr = substr($old,$s,$i-$s+1);
-#              print "STOP at $i $substr\n";
-               push(@rand, substr($old,$t+1,$i-$t-1) );
-
-               my $rand = $rand[rand @rand];
-               &status("Reply.pl: SARing '$substr' to '$rand'.");
-               $string =~ s/\Q$substr\E/$rand/;
-               undef @rand;
-           }
-       }
-
-       if ($_ eq "|" and $l+$r== 0 and $l==1) {
-#          print "| at $i (l=>$l,r=>$r)\n";
-           push(@rand, substr($old,$t+1,$i-$t-1) );
-           $t = $i;
-       }
-
-       $i++;
-    }
-
-    if ($old eq $string) {
-       &WARN("smart_replace: no subst made. (string => $string)");
-    }
-
-    return $string;
+    return $reply;
 }
 
 1;
index 5fa7c4edceef36f11ce89d12cd618bcb5309fddf..e94a7b7108a6ae1ed4746aa9dfa9b382b26595dc 100644 (file)
@@ -55,7 +55,7 @@ sub update {
     # freshmeat
     if (&IsChanConf("freshmeatForFactoid")) {
        # todo: "name" is invalid for fm ][
-       if (&dbGet("freshmeat", "name", $lhs, "name")) {
+       if (&dbGet("freshmeat", "name", "name='$lhs'")) {
            &msg($who, "permission denied. (freshmeat)");
            &status("alert: $who wanted to teach me something that freshmeat already has info on.");
            return 1;
@@ -107,9 +107,18 @@ sub update {
 
        &performAddressedReply("okay");
 
-       &setFactInfo($lhs,"created_by", $nuh);
-       &setFactInfo($lhs,"created_time", time());
-       &setFactInfo($lhs,"factoid_value", $rhs);
+       ### BROKEN!!!
+       if (1) {        # old
+           &setFactInfo($lhs,"created_by", $nuh);
+           &setFactInfo($lhs,"created_time", time());
+           &setFactInfo($lhs,"factoid_value", $rhs);
+       } else {
+           &dbReplace("factoids", (
+               factoid_key     => $lhs,
+               created_by      => time(),
+               factoid_value   => $rhs,
+           ) );
+       }
 
        if (!defined $rhs or $rhs eq "") {
            &ERROR("Update: rhs1 == NULL.");
index 49c931db836df443719adcb48033078e654f3722..18ae6ef6225e443263c2541e93d3c6d9c5314b56 100644 (file)
@@ -201,11 +201,9 @@ sub say {
 
            if ( ($pubcount % $i) == 0 and $pubcount) {
                sleep 1;
-               $pubsleep++;
            } elsif ($pubsize > $j) {
                sleep 1;
                $pubsize -= $j;
-               $pubsleep++;
            }
 
        } else {
@@ -244,11 +242,9 @@ sub msg {
            my $j = &getChanConfDefault("sendPrivateLimitBytes", 1000);
            if ( ($msgcount % $i) == 0 and $msgcount) {
                sleep 1;
-               $msgsleep++;
            } elsif ($msgsize > $j) {
                sleep 1;
                $msgsize -= $j;
-               $msgsleep++;
            }
 
        } else {
@@ -302,11 +298,9 @@ sub notice {
 
        if ( ($notcount % $i) == 0 and $notcount) {
            sleep 1;
-           $notsleep++;
        } elsif ($notsize > $j) {
            sleep 1;
            $notsize -= $j;
-           $notsleep++;
        }
 
     } else {
@@ -626,7 +620,6 @@ sub joinNextChan {
        }
 
        return;
-
     }
 
     # !scalar @joinchan:
index bb8fe089c561f17c942d97a2fe1ebc5174d872f1..4c5c956f2d35ebb7d5a73564bf06cf8962b17da5 100644 (file)
@@ -120,7 +120,7 @@ sub hookMsg {
        &DEBUG("FIXME: floodwho = ???");
     }
 
-    my $val = &getChanConfDefault("floodRepeat", "2:10", $c);
+    my $val = &getChanConfDefault("floodRepeat", "2:5", $c);
     my ($count, $interval) = split /:/, $val;
 
     # flood repeat protection.
index e90d26745842a8fb7c1403e493f4ef8ea8df6712..05a6fc04ab7b6d81ae41d4059817d4ca741af329 100644 (file)
@@ -790,9 +790,20 @@ sub on_public {
        $userstats{lc $nick}{'Time'} = time();
     }
 
-#    if (&IsChanConf("hehCounter")) {
-#      #...
-#    }
+    # would this slow things down?
+    if ($_ = &getChanConf("ircTextCounters")) {
+       foreach (split /[\s]+/) {
+           next unless ($msg =~ /^\Q$_\E$/i);
+           &status("textcounters: $_ matched for $who");
+
+           my $v = &dbGet("stats", "counter", "nick='$who' and type='$msg'");
+           $v++;
+
+           &dbReplace("stats", (nick => $who, type => $_, counter => $v) );
+           # does not work, atleast with old mysql!!! :(
+#          &dbReplace("stats", (nick => $who, type => $_, -counter => "counter+1") );
+       }
+    }
 
     &hookMsg('public', $chan, $nick, $msg);
     $chanstats{$chan}{'PublicMsg'}++;
index 403e3185f051f8ea2b73bc4c58170d886c836057..300bf857279442b54ccabe3574236e1a6c15919b 100644 (file)
@@ -261,7 +261,7 @@ sub seenFlushOld {
        my $time = time();
 
        foreach (keys %seen) {
-           my $delta_time = $time - &dbGet("seen", "NULL", $_, "time");
+           my $delta_time = $time - &dbGet("seen", "time", "nick='$_'");
            next unless ($delta_time > $max_time);
 
            &DEBUG("seenFlushOld: ".&Time2String($delta_time) );
@@ -523,8 +523,8 @@ sub seenFlush {
 
     if ($param{'DBType'} =~ /^mysql|pg|postgres/i) {
        foreach $nick (keys %seencache) {
-           my $retval = &dbReplace("seen", "nick", $nick, (
-###                    "nick" => $seencache{$nick}{'nick'},
+           my $retval = &dbReplace("seen", (
+                       "nick" => $seencache{$nick}{'nick'},
                        "time" => $seencache{$nick}{'time'},
                        "host" => $seencache{$nick}{'host'},
                        "channel" => $seencache{$nick}{'chan'},
@@ -539,7 +539,7 @@ sub seenFlush {
            ### old code.
            ###
 
-           my $exists = &dbGet("seen","nick", $nick, "nick");
+           my $exists = &dbGet("seen", "nick", "nick='$nick'");
 
            if (defined $exists and $exists) {
                &dbUpdate("seen", "nick", $nick, (
@@ -737,11 +737,6 @@ sub ircCheck {
        delete $channels{''};
     }
 
-    &DEBUG("ircstats...");
-    &DEBUG("  pubsleep: $pubsleep");
-    &DEBUG("  msgsleep: $msgsleep");
-    &DEBUG("  notsleep: $notsleep");
-
     ### USER FILE.
     if ($utime_userfile > $wtime_userfile and time() - $wtime_userfile > 3600) {
        &writeUserFile();
@@ -1052,6 +1047,7 @@ sub factoidCheck {
 
     my @list   = &searchTable("factoids", "factoid_key", "factoid_key", " #DEL#");
     my $stale  = &getChanConfDefault("factoidDeleteDelay", 30) *60*60*24;
+    &DEBUG("stale => $stale");
     my $time   = time();
 
     foreach (@list) {
@@ -1081,9 +1077,10 @@ sub factoidCheck {
        my $agestr = &Time2String($time - $age);
        &DEBUG("safedel: Removing '$_' for good. [$agestr old]");
 
+       last;
+
        &delFactoid($_);
     }
-
 }
 
 sub dccStatus {
index cb6f7fdf262e3c4e4bd45104be91b747f2d3aff2..62f1952c5df8368bad52649d3ebbc99e34cbfc44 100644 (file)
@@ -22,7 +22,7 @@ sub Freshmeat {
     my $refresh        = &::getChanConfDefault("freshmeatRefreshInterval",
                        "", 24) * 60 * 60 * 7;
 
-    my $last_refresh = &::dbGet("freshmeat", "projectname_short", "_", "latest_version");
+    my $last_refresh = &::dbGet("freshmeat", "latest_version", "projectname_short='_'");
     my $renewtable   = 0;
 
     if (defined $last_refresh and $last_refresh =~ /^\d+$/) {
@@ -84,7 +84,7 @@ sub Freshmeat {
 
 sub showPackage {
     my ($pkg)  = @_;
-    my @fm     = &::dbGet("freshmeat", "projectname_short", $pkg, "*");
+    my @fm     = &::dbGet("freshmeat", "*", "projectname_short='$pkg'");
 
     if (scalar @fm) {          #1: perfect match of name.
        my $retval;
@@ -231,6 +231,12 @@ sub downloadIndex {
                s/&aelig;/a/g;
                s/&oslash;/o/g;
                s/&eth;/e/g;
+               s/&szlig;//g;
+               s/&middot;//g;
+       }
+
+       if ($str =~ s/\&(\S+);//g) {
+           &::DEBUG("fm: sarred $1 to ''.");
        }
 
        $p->parse($str, ProtocolEncoding => 'ISO-8859-1');
index 38884994756f829f922cd941700c6833e319df61..e9a1ef29ac6ffaef59a34cfff26a49741de59a19 100644 (file)
@@ -681,7 +681,9 @@ sub set {
 sub latest {
     my($tchan, $flag) = @_;
 
-    $chan ||= $tchan;  # hack hack hack.
+    # hack hack hack.
+    $chan      ||= $tchan;
+    $who       ||= $::who;
 
     # todo: if chan = undefined, guess.
 #    if (!exists $::news{$chan}) {
index 7a87214675a63c8ae9dd2950be1d6273da52a11f..1cdae16abe68fbdd14126e2357162d3b85fb4cd1 100644 (file)
@@ -9,7 +9,7 @@ use strict;
 
 sub rootWarn {
     my ($nick,$user,$host,$chan) = @_;
-    my $attempt = &dbGet("rootwarn", "nick", lc($nick), "attempt") || 0;
+    my $attempt = &dbGet("rootwarn", "attempt", "nick='.lc($nick)."'") || 0;
     my $warnmode       = &getChanConf("rootWarnMode");
 
     if ($attempt == 0) {       # first timer.
index f35b41d53b681681f681de914b4e32d487b67f1e..a685181327a36520db746b304e275ebcad5cc5db 100644 (file)
@@ -287,19 +287,20 @@ sub process {
            return;
        }
 
-       if (lc($term) eq lc($who)) {
+       if (lc $term eq lc $who) {
            &msg($who, "please don't karma yourself");
            return;
        }
 
-       my $karma = &dbGet("karma", "nick",$term,"karma") || 0;
+       my $karma = &dbGet("stats", "counter", "nick='$term' and type='karma'") || 0;
        if ($inc eq '++') {
            $karma++;
        } else {
            $karma--;
        }
 
-       &dbSet("karma", "nick",$term,"karma",$karma);
+       &dbSet("stats", "nick",$term, "type","karma");
+#      &dbSet("stats", "nick",$term, "type","karma");
 
        return;
     }
@@ -408,7 +409,7 @@ sub FactoidStuff {
                return;
            }
 
-           if (&IsParam("factoidDeleteDelay")) {
+           if (&IsParam("factoidDeleteDelay") or &IsChanConf("factoidDeleteDelay")) {
                if ($faqtoid =~ / #DEL#$/ and !&IsFlag("o")) {
                    &msg($who, "cannot delete it ($faqtoid).");
                    return;
@@ -417,12 +418,12 @@ sub FactoidStuff {
                &status("forgot (safe delete): <$who> '$faqtoid' =is=> '$result'");
                ### TODO: check if the "backup" exists and overwrite it
                my $check = &getFactoid("$faqtoid #DEL#");
-               &DEBUG("Process: check => '$check'.");
 
-               if (!$check) {
+               if (!defined $check or $check =~ /^\s*$/) {
                    if ($faqtoid !~ / #DEL#$/) {
-                       &DEBUG("Process: backing up $faqtoid to '$new'.");
                        my $new = $faqtoid." #DEL#";
+                       &DEBUG("Process: backing up $faqtoid to '$new'.");
+
                        # this looks weird but does it work?
                        &setFactInfo($faqtoid, "factoid_key", $new);
                        &setFactInfo($new, "modified_by", $who);
@@ -455,7 +456,10 @@ sub FactoidStuff {
     if ($message =~ s/^un(forget|delete)\s+//i) {
        return 'unforget: no addr' unless ($addressed);
 
-       if (!&IsParam("factoidDeleteDelay")) {
+       my $i = 0;
+       $i++ if (&IsParam("factoidDeleteDelay"));
+       $i++ if (&IsChanConf("factoidDeleteDelay"));
+       if (!$i) {
            &performReply("safe delete has been disable so what is there to undelete?");
            return;
        }
@@ -475,7 +479,6 @@ sub FactoidStuff {
            return;
        }
 
-       &DEBUG("unforget: check => $check");
        if (defined $check) {
            &performReply("cannot undeleted '$faqtoid' because it already exists?");
            return;
index fc6e000c50e16bb64ef9adedddd57b50729eae84..c27605ba57ff2fd6c29d76d605349cd929b17d19 100644 (file)
@@ -219,7 +219,7 @@ sub factstats {
 
 sub karma {
     my $target = lc( shift || $who );
-    my $karma  = &dbGet("karma", "nick",$target,"karma") || 0;
+    my $karma  = &dbGet("stats", "counter", "nick='$target' and type='karma'") || 0;
 
     if ($karma != 0) {
        &pSReply("$target has karma of $karma");
index de587d566ff395b4cbed2c0abe737f76b1faf011..714c1250475a85001e100f6102e0b6ac98e18331 100644 (file)
@@ -19,9 +19,9 @@ use vars qw(
        $flag_quit $msgType
        $utime_userfile $wtime_userfile $ucount_userfile
        $utime_chanfile $wtime_chanfile $ucount_chanfile
-       $pubsize $pubcount $pubtime $pubsleep
-       $msgsize $msgcount $msgtime $msgsleep
-       $notsize $notcount $nottime $notsleep
+       $pubsize $pubcount $pubtime
+       $msgsize $msgcount $msgtime
+       $notsize $notcount $nottime
 );
 
 # dynamic hash.
@@ -59,13 +59,13 @@ $ucount_chanfile = 0;
 ### more variables...
 $msgtime       = time();
 $msgsize       = 0;
-$msgcount      = $msgsleep     = 0;
+$msgcount      = 0;
 $pubtime       = 0;
 $pubsize       = 0;
-$pubcount      = $pubsleep     = 0;
+$pubcount      = 0;
 $nottime       = 0;
 $notsize       = 0;
-$notcount      = $notsleep     = 0;
+$notcount      = 0;
 ###
 if ( -d "CVS" ) {
     use POSIX qw(strftime);
@@ -375,6 +375,7 @@ sub setup {
     $param{tempDir} =~ s#\~/#$ENV{HOME}/#;
 
     &status("Initial memory usage: $memusage kB");
+    &status("-------------------------------------------------------");
 }
 
 sub setupConfig {
index ece2927e58e982e560019c212585b989c4875fbe..caefae9619626bcb94cf94f701312e70370eb037 100644 (file)
@@ -99,6 +99,7 @@ sub dbGet {
     my @retval;
     my $i;
     &DEBUG("dbGet($db, $key, $val, $select);");
+    # TODO: support change that's done for db_mysql!
 
     if (!scalar @{ "${db}_format" }) {
        &ERROR("dG: no valid format layout for $db.");
index c51ef201ae0842c5d8568b3e6f54defbdccb3088..d5f7b43f9960b878dcf3e807531a211160e32cb4 100644 (file)
@@ -40,11 +40,11 @@ sub dbQuote {
 }
 
 #####
-# Usage: &dbGet($table, $primkey, $primval, $select);
+# Usage: &dbGet($table, $select, $where);
 sub dbGet {
-    my ($table, $primkey, $primval, $select) = @_;
-    my $query = "SELECT $select FROM $table WHERE $primkey=". 
-               &dbQuote($primval);
+    my ($table, $select, $where) = @_;
+    my $query   = "SELECT $select FROM $table";
+    $query     .= " WHERE $where" if ($where);
 
     my $sth;
     if (!($sth = $dbh->prepare($query))) {
@@ -55,7 +55,7 @@ sub dbGet {
     &SQLDebug($query);
     if (!$sth->execute) {
        &ERROR("Get => '$query'");
-       &ERROR("Get => $DBI::errstr");
+#      &ERROR("Get => $DBI::errstr");
        $sth->finish;
        return 0;
     }
@@ -137,7 +137,7 @@ sub dbSet {
     my ($table, $primkey, $primval, $key, $val) = @_;
     my $query;
 
-    my $result = &dbGet($table,$primkey,$primval,$primkey);
+    my $result = &dbGet($table, $primkey, "$primkey='$primval'");
     if (defined $result) {
        $query = "UPDATE $table SET $key=".&dbQuote($val).
                " WHERE $primkey=".&dbQuote($primval);
@@ -193,14 +193,19 @@ sub dbInsert {
 }
 
 #####
-# Usage: &dbReplace($table, $primkey, $primval, %hash);
+# Usage: &dbReplace($table, %hash);
 sub dbReplace {
-    my ($table, $primkey, $primval, %hash) = @_;
+    my ($table, %hash) = @_;
     my (@keys, @vals);
 
     foreach (keys %hash) {
-       push(@keys, $_);
-       push(@vals, &dbQuote($hash{$_}));
+       if (s/^-//) {   # as is.
+           push(@keys, $_);
+           push(@vals, $hash{'-'.$_});
+       } else {
+           push(@keys, $_);
+           push(@vals, &dbQuote($hash{$_}));
+       }
     }
 
     &dbRaw("Replace($table)", "REPLACE INTO $table (".join(',',@keys).
@@ -246,10 +251,12 @@ sub dbRaw {
        return 0;
     }
 
+#    &DEBUG("query => '$query'.");
+
     &SQLDebug($query);
     if (!$sth->execute) {
        &ERROR("Raw($prefix): => '$query'");
-#      &ERROR("Raw($prefix): $DBI::errstr");
+       # $DBI::errstr is printed as warning automatically.
        $sth->finish;
        return 0;
     }
@@ -378,7 +385,7 @@ sub searchTable {
 #####
 # Usage: &getFactInfo($faqtoid, type);
 sub getFactInfo {
-    return &dbGet("factoids", "factoid_key", $_[0], $_[1]);
+    return &dbGet("factoids", $_[1], "factoid_key='$_[0]'");
 }
 
 #####
@@ -420,7 +427,10 @@ sub dbCreateTable {
        &DEBUG("found!!!");
 
        open(IN, $file);
-       $data = <IN>;
+       while (<IN>) {
+           chop;
+           $data .= $_;
+       }
 
        $found++;
        last;
@@ -448,7 +458,7 @@ sub checkTables {
        &dbRaw("create(db $param{'DBName'})", $query);
     }
 
-    foreach ("factoids", "freshmeat", "karma", "rootwarn", "seen",
+    foreach ("factoids", "freshmeat", "rootwarn", "seen", "stats",
     ) {
        next if (exists $db{$_});
        &status("  creating new table $_...");