From 0e70af8e37bd684a3a48f98818edcf0210216746 Mon Sep 17 00:00:00 2001 From: djmcgrath Date: Wed, 16 Apr 2008 01:41:43 +0000 Subject: [PATCH] * Fixed bug in factoid modification code that prevented matching against created_by properly * New +M flag to allow modifying factoids created by same nick * Added +M to help file * Released 1.5.1 git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@1659 c11ca15a-4712-0410-83d8-924469b57eb5 --- ChangeLog | 7 +++ VERSION | 2 +- files/infobot.help | 3 +- src/Factoids/Core.pl | 101 +++++++++++++++++++++++++++++-------------- 4 files changed, 78 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index e69de29..543f075 100644 --- a/ChangeLog +++ b/ChangeLog @@ -0,0 +1,7 @@ +1.5.1 +===== + +* Fixed bug in factoid modification code that prevented matching against +created_by properly + +* New +M flag to allow modifying factoids created by same nick diff --git a/VERSION b/VERSION index bc80560..26ca594 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.5.0 +1.5.1 diff --git a/files/infobot.help b/files/infobot.help index c0370ee..53e2b16 100644 --- a/files/infobot.help +++ b/files/infobot.help @@ -474,7 +474,8 @@ flags: D: "A" - bot administration over /msg (default is only via DCC CHAT) flags: D: "O" - dynamic ops (as on channel). (automatic +o) flags: D: "T" - add topics. flags: D: "a" - ask/request factoid. -flags: D: "m" - modify factoid. (includes renaming) +flags: D: "m" - modify all factoids. (includes renaming) +flags: D: "M" - modify own factoids. (includes renaming) flags: D: "n" - bot owner, can "reload" flags: D: "o" - master of bot (automatic +amrt) flags: D: - can search on factoid strings shorter than 2 chars diff --git a/src/Factoids/Core.pl b/src/Factoids/Core.pl index 4898008..dbf2d46 100644 --- a/src/Factoids/Core.pl +++ b/src/Factoids/Core.pl @@ -383,11 +383,26 @@ sub FactoidStuff { return; } - # who == nick!user@host. - if (&IsFlag('m') ne 'm' and $author !~ /^\Q$who\E\!/i) { - &msg($who, "factoid '$from' is not yours to modify."); - return; - } + # author == nick!user@host + # created_by == nick + my $author = &getFactInfo($from, 'created_by'); + $author =~ /^(.*)!/; + my $created_by = $1; + + # Can they even modify factoids? + if (&IsFlag('m') ne 'm' and &IsFlag('M') ne 'M' and &IsFlag('o') ne 'o') { + &performReply("You do not have permission to modify factoids"); + return; + + # If they have +M but they didnt create the factoid + } elsif (&IsFlag('M') eq 'M' and + $who !~ /^\Q$created_by\E$/i + &IsFlag('m') ne 'm' + &IsFlag('o') ne 'o') { + &performReply("factoid '$from' is not yours to modify."); + return; + } + # Else they have permission, so continue if ($_ = &getFactoid($to)) { &performReply("destination factoid already exists."); @@ -420,36 +435,56 @@ sub FactoidStuff { if (my $result = &getFactoid($faqtoid)) { return 'subst: locked' if (&IsLocked($faqtoid) == 1); my $was = $result; + my $faqauth = &getFactInfo($faqtoid, 'created_by'); if (($flags eq 'g' && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) { - # excessive length. - if (length $result > $param{'maxDataSize'}) { - &performReply("that's too long"); - return; - } - # empty - if (length $result == 0) { - &performReply("factoid would be empty. use forget?"); - return; - } - # min length. - my $faqauth = &getFactInfo($faqtoid, 'created_by'); - if ((length $result)*2 < length $was and - &IsFlag('o') ne 'o' and - &IsHostMatch($faqauth) != 2 - ) { - &performReply("too drastic change of factoid."); - } - - &setFactInfo($faqtoid, 'factoid_value', $result); - &status("update: '$faqtoid' =is=> '$result'; was '$was'"); - &performReply('OK'); - } else { - &performReply("that doesn't contain '$op'"); - } - } else { - &performReply("i didn't have anything called '$faqtoid' to modify"); - } + my $author = $faqauth; + $author =~ /^(.*)!/; + my $created_by = $1; + + # Can they even modify factoids? + if (&IsFlag('m') ne 'm' and &IsFlag('M') ne 'M' and &IsFlag('o') ne 'o') { + &performReply("You do not have permission to modify factoids"); + return; + + # If they have +M but they didnt create the factoid + } elsif (&IsFlag('M') eq 'M' and + $who !~ /^\Q$created_by\E$/i + &IsFlag('m') ne 'm' + &IsFlag('o') ne 'o') { + &performReply("factoid '$faqtoid' is not yours to modify."); + return; + } + + # excessive length. + if (length $result > $param{'maxDataSize'}) { + &performReply("that's too long"); + return; + } + + # empty + if (length $result == 0) { + &performReply("factoid would be empty. Use forget instead."); + return; + } + + # min length. + if ((length $result)*2 < length $was and + &IsFlag('o') ne 'o' and + &IsHostMatch($faqauth) != 2 + ) { + &performReply("too drastic change of factoid."); + } + + &setFactInfo($faqtoid, 'factoid_value', $result); + &status("update: '$faqtoid' =is=> '$result'; was '$was'"); + &performReply('OK'); + } else { + &performReply("that doesn't contain '$op'"); + } + } else { + &performReply("i didn't have anything called '$faqtoid' to modify"); + } return; } -- 2.39.5