3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-22 18:52:40 +01:00

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.
This commit is contained in:
Pragmatic Software 2024-11-07 01:45:15 -08:00
parent 12ec8bb77c
commit a262139fd2
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE
4 changed files with 7 additions and 11 deletions

View File

@ -59,7 +59,7 @@
<!-- md-toc-end -->
## 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.

View File

@ -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.";
}
}

View File

@ -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

View File

@ -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 {}