From 65a936279f6b34da2bae1091908c14e73ecd457d Mon Sep 17 00:00:00 2001 From: dms Date: Wed, 26 Dec 2001 11:51:20 +0000 Subject: [PATCH] - make ignoreAdd a little more verbose. - added factoidPreventForgetLimitTime. if a factoid exceeds this age, prevent forget. - added factoidPreventForgetRedirect. if this factoid is redirected to by other factoids, prevent forget. - don't evaluate dollar vars in factoid request if it's a factoid command. git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@534 c11ca15a-4712-0410-83d8-924469b57eb5 --- src/DynaConfig.pl | 3 +++ src/Factoids/Core.pl | 51 ++++++++++++++++++++++++++++++++++++----- src/Factoids/Reply.pl | 9 +++++--- src/Modules/Factoids.pl | 2 +- src/Modules/News.pl | 9 ++++++++ 5 files changed, 64 insertions(+), 10 deletions(-) diff --git a/src/DynaConfig.pl b/src/DynaConfig.pl index b76e757..e24b0d4 100644 --- a/src/DynaConfig.pl +++ b/src/DynaConfig.pl @@ -513,6 +513,9 @@ sub ignoreAdd { $ignore{$chan}{$mask} = [$expire, time(), $who, $comment]; + # todo: improve this. + &status("ignore: Added $mask for $chan to expire $expire, by $who, for $comment"); + if ($exist) { $utime_userfile = time(); $ucount_userfile++; diff --git a/src/Factoids/Core.pl b/src/Factoids/Core.pl index d8d559a..067e494 100644 --- a/src/Factoids/Core.pl +++ b/src/Factoids/Core.pl @@ -148,8 +148,11 @@ sub FactoidStuff { if (defined $result) { my $author = &getFactInfo($faqtoid, "created_by"); my $count = &getFactInfo($faqtoid, "requested_count") || 0; - my $limit = &getChanConfDefault("factoidPreventForgetLimit", - 100, $chan); + my $limit = &getChanConfDefault( + "factoidPreventForgetLimit", 100, $chan); + my $limitage = &getChanConfDefault( + "factoidPreventForgetLimitTime", 180, $chan); + my $age = time() - &getFactInfo($faqtoid, "created_time"); if (IsFlag("r") ne "r") { &msg($who, "you don't have access to remove factoids"); @@ -157,16 +160,52 @@ sub FactoidStuff { } return 'locked factoid' if (&IsLocked($faqtoid) == 1); + my $isop = (&IsFlag("o") eq "o") ? 1 : 0; + + ### lets go do some checking. + + # factoidPreventForgetLimitTime: + if (!$isop and $age/(60*60*24) > $limitage) { + &msg($who, "cannot remove factoid since it is protected by Time."); + return; + } # factoidPreventForgetLimit: - if ($limit and $count > $limit and (&IsFlag("o") ne "o")) { + if (!$isop and $limit and $count > $limit) { &msg($who, "will not delete '$faqtoid', count > limit ($count > $limit)"); return; } - # prevent/minimize abuse. + # this may eat some memory. + # prevent deletion if other factoids redirect to it. + # todo: use hash instead of array. + my @list; + if (&getChanConf("factoidPreventForgetRedirect")) { + &status("Factoids/Core: forget: checking for redirect factoids"); + @list = &searchTable("factoids", "factoid_key", + "factoid_value", "^ see "); + } + + my $match = 0; + for (@list) { + my $f = $_; + my $v = &getFactInfo($f, "factoid_value"); + my $fsafe = quotemeta($faqtoid); + next unless ($v =~ /^ ?see( also)? $fsafe\.?$/i); + + &DEBUG("Factoids/Core: match! ($f || $faqtoid)"); + + $match++; + } + # todo: warn for op aswell, but allow force delete. + if (!$isop and $match) { + &msg($who, "uhm, other (redirection) factoids depend on this one."); + return; + } + + # minimize abuse. my $faqauth = &getFactInfo($faqtoid, "created_by"); - if (&IsFlag("o") ne "o" and &IsHostMatch($faqauth) != 2) { + if (!$isop and &IsHostMatch($faqauth) != 2) { $cache{forget}{$h}++; # warn. @@ -186,7 +225,7 @@ sub FactoidStuff { # lets do it! if (&IsParam("factoidDeleteDelay") or &IsChanConf("factoidDeleteDelay")) { - if ($faqtoid =~ / #DEL#$/ and !&IsFlag("o")) { + if (!$isop and $faqtoid =~ / #DEL#$/) { &msg($who, "cannot delete it ($faqtoid)."); return; } diff --git a/src/Factoids/Reply.pl b/src/Factoids/Reply.pl index e73a73e..5c472fc 100644 --- a/src/Factoids/Reply.pl +++ b/src/Factoids/Reply.pl @@ -136,9 +136,12 @@ sub getReply { ### $ SUBSTITUTION. ### -# &DEBUG("Reply: reply => $reply"); - $reply = &substVars($reply,1); -# &DEBUG("Reply: reply => $reply"); + # don't evaluate if it has factoid arguments. + if ($message =~ /^CMD:/i) { + &status("Reply: not doing substVars (eval dollar vars)"); + } else { + $reply = &substVars($reply,1); + } $reply; } diff --git a/src/Modules/Factoids.pl b/src/Modules/Factoids.pl index caadae6..f00bdaa 100644 --- a/src/Modules/Factoids.pl +++ b/src/Modules/Factoids.pl @@ -271,7 +271,7 @@ sub CmdFactStats { for (@list) { my $factoid = $_; my $val = &getFactInfo($factoid, "factoid_value"); - if ($val =~ /^ see( also)? (.*?)\.?$/i) { + if ($val =~ /^ ?see( also)? (.*?)\.?$/i) { my $redirf = lc $2; my $redir = &getFactInfo($redirf, "factoid_value"); next if (defined $redir); diff --git a/src/Modules/News.pl b/src/Modules/News.pl index c9a8fdd..6acebdb 100644 --- a/src/Modules/News.pl +++ b/src/Modules/News.pl @@ -442,6 +442,15 @@ sub read { my $item = &getNewsItem($str); if (!defined $item or !scalar keys %{ $::news{$chan}{$item} }) { + # todo: numerical check. + if ($str =~ /^(\d+) (\d+)$/ or + $str =~ /^(\d+)-(\d+)$/ or + $str =~ /^-(\d+)$/ or $str =~ /^(\d+)-$/ or 0 + ) { + &::notice($who, "We don't support multiple requests of news items, sorry."); + return; + } + &::notice($who, "No news item called '$str'"); return; } -- 2.39.2