From a262139fd286d16819932be923dca02a162731ff Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Thu, 7 Nov 2024 01:45:15 -0800 Subject: [PATCH] Factoids: require `locked` to be exactly `1` to invoke commands with `required_caps` This allows us to set `locked` to a value greater than `1` to lock a factoid WITHOUT allowing invocation of `required_caps` commands. This lets us safely lock a factoid that has unrestrained `$args` or variables. --- doc/Factoids.md | 4 ++-- lib/PBot/Core/Commands.pm | 4 ++-- lib/PBot/Core/Factoids/Interpreter.pm | 6 +----- lib/PBot/VERSION.pm | 4 ++-- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/doc/Factoids.md b/doc/Factoids.md index 734820d3..501006cb 100644 --- a/doc/Factoids.md +++ b/doc/Factoids.md @@ -59,7 +59,7 @@ ## About -Factoids are a very special type of command. Anybody interacting with PBot can create, edit, delete and invoke factoids. Factoids can be locked by the creator of the factoid to prevent them from being edited by others. +Factoids are a very special type of command. Anybody interacting with PBot can create, edit, delete and invoke factoids. At its most simple, a factoid merely displays the text the creator sets. @@ -622,7 +622,7 @@ Name | Capability | Description `type` | botowner | The type of the factoid. "text" for regular factoid; "module" for module. `edited_by` | botowner | The hostmask of the person to last edit the factoid. `edited_on` | botowner | The timestamp of when the factoid was last edited. -`locked` | chanop | If enabled, prevents the factoid from being changed or removed. +`locked` | chanop | If enabled, prevents the factoid from being changed or removed. Must be set to `1` to allow factoid to invoke a command that has `required_caps` enabled. Can be set to a value greater than `1` to lock the factoid without allowing `required_caps` commands to be invoked. `add_nick` | chanop | Prepends the nick of the person invoking the factoid to the output of the factoid. `nooverride` | chanop | Prevents the creation of a factoid with an identical name in a different channel. `cap-override` | botowner | Provides a user with the capability specified, just for this factoid invocation. diff --git a/lib/PBot/Core/Commands.pm b/lib/PBot/Core/Commands.pm index fc8ffd8c..ffb09d6f 100644 --- a/lib/PBot/Core/Commands.pm +++ b/lib/PBot/Core/Commands.pm @@ -193,8 +193,8 @@ sub interpreter($self, $context) { } } - if ($context->{factoid} && !$context->{locked}) { - return "/msg $context->{nick} The $keyword command requires the can-$keyword capability and cannot be invoked from an unlocked factoid."; + if ($context->{factoid} && $context->{locked} != 1) { + return "/msg $context->{nick} The $keyword command requires the can-$keyword capability and cannot be invoked from a factoid that does not have `locked` set to 1."; } } diff --git a/lib/PBot/Core/Factoids/Interpreter.pm b/lib/PBot/Core/Factoids/Interpreter.pm index b1db0e26..bd33294f 100644 --- a/lib/PBot/Core/Factoids/Interpreter.pm +++ b/lib/PBot/Core/Factoids/Interpreter.pm @@ -195,11 +195,7 @@ sub interpreter($self, $context) { } } - if ($self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'locked')) { - $context->{locked} = 1; - } else { - $context->{locked} = 0; - } + $context->{locked} = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'locked') // 0; # rate-limiting if ($context->{interpret_depth} <= 1 diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index 52ae2976..aced9730 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,8 +25,8 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4840, - BUILD_DATE => "2024-11-06", + BUILD_REVISION => 4841, + BUILD_DATE => "2024-11-07", }; sub initialize {}