mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-29 15:29:32 +01:00
Correct user cross-channel contamination
This commit is contained in:
parent
99a3266106
commit
94ee5f03a5
@ -137,9 +137,10 @@ sub save {
|
||||
}
|
||||
|
||||
sub find_user_account {
|
||||
my ($self, $channel, $hostmask) = @_;
|
||||
my ($self, $channel, $hostmask, $any_channel) = @_;
|
||||
$channel = lc $channel;
|
||||
$hostmask = lc $hostmask;
|
||||
$any_channel //= 0;
|
||||
|
||||
my $sort;
|
||||
if ($channel =~ m/^#/) {
|
||||
@ -149,7 +150,7 @@ sub find_user_account {
|
||||
}
|
||||
|
||||
foreach my $chan (sort $sort keys %{ $self->{users}->{hash} }) {
|
||||
if ($channel !~ m/^#/ or $channel =~ m/^$chan$/i) {
|
||||
if (($channel !~ m/^#/ and $any_channel) or $channel =~ m/^$chan$/i) {
|
||||
if (not exists $self->{users}->{hash}->{$chan}->{$hostmask}) {
|
||||
# find hostmask by account name or wildcard
|
||||
foreach my $mask (keys %{ $self->{users}->{hash}->{$chan} }) {
|
||||
@ -177,8 +178,10 @@ sub find_user_account {
|
||||
}
|
||||
|
||||
sub find_user {
|
||||
my ($self, $channel, $hostmask) = @_;
|
||||
($channel, $hostmask) = $self->find_user_account($channel, $hostmask);
|
||||
my ($self, $channel, $hostmask, $any_channel) = @_;
|
||||
$any_channel //= 0;
|
||||
($channel, $hostmask) = $self->find_user_account($channel, $hostmask, $any_channel);
|
||||
return undef if not $any_channel and not defined $channel;
|
||||
|
||||
$channel = '.*' if not defined $channel;
|
||||
$hostmask = '.*' if not defined $hostmask;
|
||||
@ -193,7 +196,7 @@ sub find_user {
|
||||
|
||||
my $user = eval {
|
||||
foreach my $channel_regex (sort $sort keys %{ $self->{users}->{hash} }) {
|
||||
if ($channel !~ m/^#/ or $channel =~ m/^$channel_regex$/i) {
|
||||
if (($channel !~ m/^#/ and $any_channel) or $channel =~ m/^$channel_regex$/i) {
|
||||
foreach my $hostmask_regex (keys %{ $self->{users}->{hash}->{$channel_regex} }) {
|
||||
next if $hostmask_regex eq '_name';
|
||||
if ($hostmask_regex =~ m/[*?]/) {
|
||||
@ -270,6 +273,13 @@ sub logout {
|
||||
delete $user->{loggedin} if defined $user;
|
||||
}
|
||||
|
||||
sub get_user_metadata {
|
||||
my ($self, $channel, $hostmask, $key) = @_;
|
||||
my $user = $self->find_user($channel, $hostmask, 1);
|
||||
return $user->{lc $key} if $user;
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub get_loggedin_user_metadata {
|
||||
my ($self, $channel, $hostmask, $key) = @_;
|
||||
my $user = $self->loggedin($channel, $hostmask);
|
||||
@ -530,7 +540,7 @@ sub mycmd {
|
||||
my $channel = $from;
|
||||
my $hostmask = "$nick!$user\@$host";
|
||||
|
||||
my $u = $self->find_user($channel, $hostmask);
|
||||
my $u = $self->find_user($channel, $hostmask, 1);
|
||||
|
||||
if (not $u) {
|
||||
$channel = '.*';
|
||||
@ -579,8 +589,8 @@ sub mycmd {
|
||||
$result = "Usage: my <key> [value]; ";
|
||||
}
|
||||
|
||||
my ($found_channel, $found_hostmask) = $self->find_user_account($channel, $hostmask);
|
||||
($found_channel, $found_hostmask) = $self->find_user_account('.*', $hostmask) if not defined $found_channel;
|
||||
my ($found_channel, $found_hostmask) = $self->find_user_account($channel, $hostmask, 1);
|
||||
($found_channel, $found_hostmask) = $self->find_user_account('.*', $hostmask, 1) if not defined $found_channel;
|
||||
return "No user account found in $channel." if not defined $found_channel;
|
||||
$result .= $self->{users}->set($found_channel, $found_hostmask, $key, $value);
|
||||
$result =~ s/^password => .*;?$/password => <private>;/m;
|
||||
|
@ -48,7 +48,7 @@ sub datecmd {
|
||||
$arguments = "@$args";
|
||||
|
||||
my $hostmask = defined $user_override ? $user_override : "$nick!$user\@$host";
|
||||
my $tz_override = $self->{pbot}->{users}->get_loggedin_user_metadata($from, $hostmask, 'timezone') // '';
|
||||
my $tz_override = $self->{pbot}->{users}->get_user_metadata($from, $hostmask, 'timezone') // '';
|
||||
|
||||
my $timezone = $self->{pbot}->{registry}->get_value('date', 'default_timezone') // 'UTC';
|
||||
$timezone = $tz_override if $tz_override;
|
||||
|
@ -49,7 +49,7 @@ sub weathercmd {
|
||||
$arguments = "@$args";
|
||||
|
||||
my $hostmask = defined $user_override ? $user_override : "$nick!$user\@$host";
|
||||
my $location_override = $self->{pbot}->{users}->get_loggedin_user_metadata($from, $hostmask, 'location') // '';
|
||||
my $location_override = $self->{pbot}->{users}->get_user_metadata($from, $hostmask, 'location') // '';
|
||||
$arguments = $location_override if not length $arguments;
|
||||
|
||||
if (defined $user_override and not length $location_override) {
|
||||
|
@ -77,7 +77,7 @@ sub wttrcmd {
|
||||
$arguments = "@$args";
|
||||
|
||||
my $hostmask = defined $options{u} ? $options{u} : "$nick!$user\@$host";
|
||||
my $location_override = $self->{pbot}->{users}->get_loggedin_user_metadata($from, $hostmask, 'location') // '';
|
||||
my $location_override = $self->{pbot}->{users}->get_user_metadata($from, $hostmask, 'location') // '';
|
||||
$arguments = $location_override if not length $arguments;
|
||||
|
||||
if (defined $options{u} and not length $location_override) {
|
||||
|
Loading…
Reference in New Issue
Block a user