3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-26 22:09:26 +01:00

Factoids: replace hard-coded max length values with registry values

This commit is contained in:
Pragmatic Software 2019-05-09 18:04:52 -07:00
parent f9a50f0d27
commit 7da4003ffd
2 changed files with 15 additions and 12 deletions

View File

@ -753,11 +753,11 @@ sub factmove {
} }
} }
if (length $target > 60) { if (length $target > $self->{pbot}->{registry}->get_value('factoids', 'max_name_length')) {
return "/say $nick: I don't think the factoid name needs to be that long."; return "/say $nick: I don't think the factoid name needs to be that long.";
} }
if (length $target_channel > 20) { if (length $target_channel > $self->{pbot}->{registry}->get_value('factoids', 'max_channel_length')) {
return "/say $nick: I don't think the channel name needs to be that long."; return "/say $nick: I don't think the channel name needs to be that long.";
} }
@ -842,11 +842,11 @@ sub factalias {
return "Usage: factalias [channel] <keyword> <command>"; return "Usage: factalias [channel] <keyword> <command>";
} }
if (length $alias > 60) { if (length $alias > $self->{pbot}->{registry}->get_value('factoids', 'max_name_length')) {
return "/say $nick: I don't think the factoid name needs to be that long."; return "/say $nick: I don't think the factoid name needs to be that long.";
} }
if (length $chan > 20) { if (length $chan > $self->{pbot}->{registry}->get_value('factoids', 'max_channel_length')) {
return "/say $nick: I don't think the channel name needs to be that long."; return "/say $nick: I don't think the channel name needs to be that long.";
} }
@ -932,11 +932,11 @@ sub factadd {
$from_chan = '.*' if $from_chan !~ /^#/; $from_chan = '.*' if $from_chan !~ /^#/;
if (length $keyword > 60) { if (length $keyword > $self->{pbot}->{registry}->get_value('factoids', 'max_name_length')) {
return "/say $nick: I don't think the factoid name needs to be that long."; return "/say $nick: I don't think the factoid name needs to be that long.";
} }
if (length $from_chan > 20) { if (length $from_chan > $self->{pbot}->{registry}->get_value('factoids', 'max_channel_length')) {
return "/say $nick: I don't think the channel needs to be that long."; return "/say $nick: I don't think the channel needs to be that long.";
} }

View File

@ -63,7 +63,10 @@ sub initialize {
$self->{commands} = PBot::FactoidCommands->new(pbot => $pbot); $self->{commands} = PBot::FactoidCommands->new(pbot => $pbot);
$self->{factoidmodulelauncher} = PBot::FactoidModuleLauncher->new(pbot => $pbot); $self->{factoidmodulelauncher} = PBot::FactoidModuleLauncher->new(pbot => $pbot);
$self->{pbot}->{registry}->add_default('text', 'factoids', 'default_rate_limit', '15'); $self->{pbot}->{registry}->add_default('text', 'factoids', 'default_rate_limit', 15);
$self->{pbot}->{registry}->add_default('text', 'factoids', 'max_name_length', 100);
$self->{pbot}->{registry}->add_default('text', 'factoids', 'max_content_length', 1024 * 8);
$self->{pbot}->{registry}->add_default('text', 'factoids', 'max_channel_length', 20);
$self->{pbot}->{atexit}->register(sub { $self->save_factoids; return; }); $self->{pbot}->{atexit}->register(sub { $self->save_factoids; return; });
@ -405,7 +408,7 @@ sub expand_special_vars {
$action =~ s/\$randomnick/my $random = $self->{pbot}->{nicklist}->random_nick($from); $random ? $random : $nick/ge; $action =~ s/\$randomnick/my $random = $self->{pbot}->{nicklist}->random_nick($from); $random ? $random : $nick/ge;
$action =~ s/\$0\b/$root_keyword/g; $action =~ s/\$0\b/$root_keyword/g;
return validate_string($action); return validate_string($action, $self->{pbot}->{registry}->get_value('factoids', 'max_content_length'));
} }
sub expand_factoid_vars { sub expand_factoid_vars {
@ -539,14 +542,14 @@ sub expand_factoid_vars {
$action = $self->expand_special_vars($from, $nick, $root_keyword, $action); $action = $self->expand_special_vars($from, $nick, $root_keyword, $action);
} }
return validate_string($action); return validate_string($action, $self->{pbot}->{registry}->get_value('factoids', 'max_content_length'));
} }
sub expand_action_arguments { sub expand_action_arguments {
my ($self, $action, $input, $nick) = @_; my ($self, $action, $input, $nick) = @_;
$action = validate_string($action); $action = validate_string($action, $self->{pbot}->{registry}->get_value('factoids', 'max_content_length'));
$input = validate_string($input); $input = validate_string($input, $self->{pbot}->{registry}->get_value('factoids', 'max_content_length'));
my %h; my %h;
if (not defined $input or $input eq '') { if (not defined $input or $input eq '') {
@ -734,7 +737,7 @@ sub execute_code_factoid_using_safe {
$action = $self->expand_factoid_vars($from, $nick, $root_keyword, $action); $action = $self->expand_factoid_vars($from, $nick, $root_keyword, $action);
$action = $self->expand_action_arguments($action, $arguments, $nick); $action = $self->expand_action_arguments($action, $arguments, $nick);
} else { } else {
$action = validate_string($action); $action = validate_string($action, $self->{pbot}->{registry}->get_value('factoids', 'max_content_length'));
} }
return $action; return $action;