From 5dd4566ad4dfca398146deceda3914a9984fa93a Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Tue, 27 Jul 2021 23:46:54 -0700 Subject: [PATCH] Add `usershow` command to show user metadata --- lib/PBot/Core/Commands/Users.pm | 26 +++++++++++++++++++++++++- lib/PBot/VERSION.pm | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/PBot/Core/Commands/Users.pm b/lib/PBot/Core/Commands/Users.pm index 3c9da6de..0fb2efb8 100644 --- a/lib/PBot/Core/Commands/Users.pm +++ b/lib/PBot/Core/Commands/Users.pm @@ -18,6 +18,7 @@ sub initialize { $self->{pbot}->{commands}->register(sub { $self->cmd_logout(@_) }, "logout", 0); $self->{pbot}->{commands}->register(sub { $self->cmd_useradd(@_) }, "useradd", 1); $self->{pbot}->{commands}->register(sub { $self->cmd_userdel(@_) }, "userdel", 1); + $self->{pbot}->{commands}->register(sub { $self->cmd_usershow(@_) }, "usershow", 0); $self->{pbot}->{commands}->register(sub { $self->cmd_userset(@_) }, "userset", 1); $self->{pbot}->{commands}->register(sub { $self->cmd_userunset(@_) }, "userunset", 1); $self->{pbot}->{commands}->register(sub { $self->cmd_users(@_) }, "users", 0); @@ -188,6 +189,30 @@ sub cmd_userdel { return $self->{pbot}->{users}->remove_user($context->{arguments}); } +sub cmd_usershow { + my ($self, $context) = @_; + + my ($name, $key) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2); + + if (not defined $name) { return "Usage: usershow [key]"; } + + my $channel = $context->{from}; + + my $target = $self->{pbot}->{users}->{storage}->get_data($name); + + if (not $target) { + return "There is no user account $name."; + } + + if (lc $key eq 'password') { + return "I don't think so."; + } + + my $result = $self->{pbot}->{users}->{storage}->set($name, $key, undef); + $result =~ s/^password: .*;?$/password: ;/m; + return $result; +} + sub cmd_userset { my ($self, $context) = @_; @@ -226,7 +251,6 @@ sub cmd_userset { } my $result = $self->{pbot}->{users}->{storage}->set($name, $key, $value); - print "result [$result]\n"; $result =~ s/^password: .*;?$/password: ;/m; if (defined $key and ($key eq 'channels' or $key eq 'hostmasks') and defined $value) { diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index c190c3c0..abb72da0 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,7 +25,7 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4322, + BUILD_REVISION => 4323, BUILD_DATE => "2021-07-27", };