From 4fb1ed815bcfff7dd76034fa12aa118977654e18 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Fri, 24 Apr 2020 22:58:40 -0700 Subject: [PATCH] Users: add `id` command --- PBot/Users.pm | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/PBot/Users.pm b/PBot/Users.pm index 367f2a89..38110e8f 100644 --- a/PBot/Users.pm +++ b/PBot/Users.pm @@ -26,6 +26,7 @@ sub initialize { $self->{pbot}->{commands}->register(sub { $self->userunset(@_) }, "userunset", 1); $self->{pbot}->{commands}->register(sub { $self->users(@_) }, "users", 0); $self->{pbot}->{commands}->register(sub { $self->mycmd(@_) }, "my", 0); + $self->{pbot}->{commands}->register(sub { $self->idcmd(@_) }, "id", 0); $self->{pbot}->{capabilities}->add('admin', 'can-useradd', 1); $self->{pbot}->{capabilities}->add('admin', 'can-userdel', 1); @@ -39,7 +40,6 @@ sub initialize { $self->{pbot}->{event_dispatcher}->register_handler('irc.kick', sub { $self->on_kick(@_) }); $self->{pbot}->{event_dispatcher}->register_handler('pbot.part', sub { $self->on_self_part(@_) }); - $self->{user_index} = {}; $self->{user_cache} = {}; @@ -617,4 +617,33 @@ sub mycmd { return $result; } +sub idcmd { + my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_; + + my $target = length $arguments ? $arguments : $nick; + + my ($message_account, $hostmask) = $self->{pbot}->{messagehistory}->{database}->find_message_account_by_nick($target); + my $ancestor_id = $self->{pbot}->{messagehistory}->{database}->get_ancestor_id($message_account); + my $nickserv = $self->{pbot}->{messagehistory}->{database}->get_current_nickserv_account($message_account); + + my ($u, $name) = $self->find_user($from, $hostmask, 1); + + my $result = "$nick ($hostmask): user id: $message_account; "; + + if ($message_account != $ancestor_id) { + $result .= "parent user id: $ancestor_id; "; + } + + if (defined $u) { + $result .= "user account: $name ("; + $result .= ($u->{loggedin} ? "logged in" : "not logged in") . '); '; + } + + if (defined $nickserv and length $nickserv) { + $result .= "NickServ: $nickserv"; + } + + return $result; +} + 1;