From 02dd5778cf86851ed8158551400149133843516a Mon Sep 17 00:00:00 2001 From: dms Date: Fri, 18 May 2001 15:20:48 +0000 Subject: [PATCH] - added support of ircTextCounters - works! thanks to #perl@OPN. - 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 --- src/CommandStubs.pl | 60 ++++++++-- src/Factoids/Question.pl | 131 +++++++++++++--------- src/Factoids/Reply.pl | 237 +++++++++++++++++++++------------------ src/Factoids/Update.pl | 17 ++- src/IRC/Irc.pl | 7 -- src/IRC/IrcHelpers.pl | 2 +- src/IRC/IrcHooks.pl | 17 ++- src/IRC/Schedulers.pl | 17 ++- src/Modules/Freshmeat.pl | 10 +- src/Modules/News.pl | 4 +- src/Modules/RootWarn.pl | 2 +- src/Process.pl | 21 ++-- src/UserExtra.pl | 2 +- src/core.pl | 13 ++- src/db_dbm.pl | 1 + src/db_mysql.pl | 38 ++++--- 16 files changed, 343 insertions(+), 236 deletions(-) diff --git a/src/CommandStubs.pl b/src/CommandStubs.pl index 7b2ca5d..1a583dd 100644 --- a/src/CommandStubs.pl +++ b/src/CommandStubs.pl @@ -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) { diff --git a/src/Factoids/Question.pl b/src/Factoids/Question.pl index 62feedf..a5ced7b 100644 --- a/src/Factoids/Question.pl +++ b/src/Factoids/Question.pl @@ -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*\s*(.*)/\cAACTION $1\cA/i; - $result =~ s/^\s*\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*\s*(.*)/\cAACTION $1\cA/i; + $result =~ s/^\s*\s*//i; + $result = &SARit($result); +# $result = &substVars($result); + + return $result; + } + + return; +} + 1; diff --git a/src/Factoids/Reply.pl b/src/Factoids/Reply.pl index 5fda25f..78c13d8 100644 --- a/src/Factoids/Reply.pl +++ b/src/Factoids/Reply.pl @@ -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; diff --git a/src/Factoids/Update.pl b/src/Factoids/Update.pl index 5fa7c4e..e94a7b7 100644 --- a/src/Factoids/Update.pl +++ b/src/Factoids/Update.pl @@ -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."); diff --git a/src/IRC/Irc.pl b/src/IRC/Irc.pl index 49c931d..18ae6ef 100644 --- a/src/IRC/Irc.pl +++ b/src/IRC/Irc.pl @@ -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: diff --git a/src/IRC/IrcHelpers.pl b/src/IRC/IrcHelpers.pl index bb8fe08..4c5c956 100644 --- a/src/IRC/IrcHelpers.pl +++ b/src/IRC/IrcHelpers.pl @@ -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. diff --git a/src/IRC/IrcHooks.pl b/src/IRC/IrcHooks.pl index e90d267..05a6fc0 100644 --- a/src/IRC/IrcHooks.pl +++ b/src/IRC/IrcHooks.pl @@ -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'}++; diff --git a/src/IRC/Schedulers.pl b/src/IRC/Schedulers.pl index 403e318..300bf85 100644 --- a/src/IRC/Schedulers.pl +++ b/src/IRC/Schedulers.pl @@ -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 { diff --git a/src/Modules/Freshmeat.pl b/src/Modules/Freshmeat.pl index cb6f7fd..62f1952 100644 --- a/src/Modules/Freshmeat.pl +++ b/src/Modules/Freshmeat.pl @@ -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/æ/a/g; s/ø/o/g; s/ð/e/g; + s/ß//g; + s/·//g; + } + + if ($str =~ s/\&(\S+);//g) { + &::DEBUG("fm: sarred $1 to ''."); } $p->parse($str, ProtocolEncoding => 'ISO-8859-1'); diff --git a/src/Modules/News.pl b/src/Modules/News.pl index 3888499..e9a1ef2 100644 --- a/src/Modules/News.pl +++ b/src/Modules/News.pl @@ -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}) { diff --git a/src/Modules/RootWarn.pl b/src/Modules/RootWarn.pl index 7a87214..1cdae16 100644 --- a/src/Modules/RootWarn.pl +++ b/src/Modules/RootWarn.pl @@ -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. diff --git a/src/Process.pl b/src/Process.pl index f35b41d..a685181 100644 --- a/src/Process.pl +++ b/src/Process.pl @@ -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; diff --git a/src/UserExtra.pl b/src/UserExtra.pl index fc6e000..c27605b 100644 --- a/src/UserExtra.pl +++ b/src/UserExtra.pl @@ -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"); diff --git a/src/core.pl b/src/core.pl index de587d5..714c125 100644 --- a/src/core.pl +++ b/src/core.pl @@ -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 { diff --git a/src/db_dbm.pl b/src/db_dbm.pl index ece2927..caefae9 100644 --- a/src/db_dbm.pl +++ b/src/db_dbm.pl @@ -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."); diff --git a/src/db_mysql.pl b/src/db_mysql.pl index c51ef20..d5f7b43 100644 --- a/src/db_mysql.pl +++ b/src/db_mysql.pl @@ -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 = ; + while () { + 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 $_..."); -- 2.39.2