From 8b60162a108734a3121ad472f5e60642e01061d8 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 25 Nov 2019 13:56:55 -0800 Subject: [PATCH] Registry: can now set nick-specific registry values; e.g. default_ban_timeout.nick.pragma- --- PBot/Registry.pm | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/PBot/Registry.pm b/PBot/Registry.pm index e0f5d2f2..0467726e 100644 --- a/PBot/Registry.pm +++ b/PBot/Registry.pm @@ -145,27 +145,41 @@ sub unset { } sub get_value { - my ($self, $section, $item, $as_text) = @_; + my ($self, $section, $item, $as_text, $stuff) = @_; + my $key = $item; - if (exists $self->{registry}->hash->{$section} and exists $self->{registry}->hash->{$section}->{$item}) { - if (not $as_text and $self->{registry}->hash->{$section}->{$item}->{type} eq 'array') { - return split /\s*,\s*/, $self->{registry}->hash->{$section}->{$item}->{value}; + if (defined $stuff and exists $stuff->{nick}) { + if (exists $self->{registry}->hash->{$section} and exists $self->{registry}->hash->{$section}->{"$item.nick.$stuff->{nick}"}) { + $key = "$item.nick.$stuff->{nick}"; + } + } + + if (exists $self->{registry}->hash->{$section} and exists $self->{registry}->hash->{$section}->{$key}) { + if (not $as_text and $self->{registry}->hash->{$section}->{$key}->{type} eq 'array') { + return split /\s*,\s*/, $self->{registry}->hash->{$section}->{$key}->{value}; } else { - return $self->{registry}->hash->{$section}->{$item}->{value}; + return $self->{registry}->hash->{$section}->{$key}->{value}; } } return undef; } sub get_array_value { - my ($self, $section, $item, $index) = @_; + my ($self, $section, $item, $index, $stuff) = @_; + my $key = $item; - if (exists $self->{registry}->hash->{$section} and exists $self->{registry}->hash->{$section}->{$item}) { - if ($self->{registry}->hash->{$section}->{$item}->{type} eq 'array') { - my @array = split /\s*,\s*/, $self->{registry}->hash->{$section}->{$item}->{value}; + if (defined $stuff and exists $stuff->{nick}) { + if (exists $self->{registry}->hash->{$section} and exists $self->{registry}->hash->{$section}->{"$item.nick.$stuff->{nick}"}) { + $key = "$item.nick.$stuff->{nick}"; + } + } + + if (exists $self->{registry}->hash->{$section} and exists $self->{registry}->hash->{$section}->{$key}) { + if ($self->{registry}->hash->{$section}->{$key}->{type} eq 'array') { + my @array = split /\s*,\s*/, $self->{registry}->hash->{$section}->{$key}->{value}; return $array[$index >= $#array ? $#array : $index]; } else { - return $self->{registry}->hash->{$section}->{$item}->{value}; + return $self->{registry}->hash->{$section}->{$key}->{value}; } } return undef;