3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-03 01:48:38 +02:00

Users: id command can now search by wildcarded hostmasks

This commit is contained in:
Pragmatic Software 2021-09-14 14:23:35 -07:00
parent 5cf9ac1b9f
commit fa65bfc878
3 changed files with 38 additions and 5 deletions

View File

@ -383,6 +383,36 @@ sub cmd_id {
$hostmask = $self->{pbot}->{messagehistory}->{database}->find_message_account_by_id($target);
return "I don't know anybody with id $target." if not $hostmask;
$message_account = $target;
} elsif ($target =~ m/[!@]/) {
my @accounts = $self->{pbot}->{messagehistory}->{database}->find_message_accounts_by_mask($target, 20);
my %seen;
@accounts = grep !$seen{$_}++, @accounts;
if (not @accounts) {
return "I don't know anybody matching hostmask $target.";
} elsif (@accounts > 1) {
# found more than one account, list them
my %users;
foreach my $account (@accounts) {
next if exists $users{$account};
my $hostmask = $self->{pbot}->{messagehistory}->{database}->find_most_recent_hostmask($account);
$users{$account} = $hostmask;
}
my @hostmasks;
foreach my $id (keys %users) {
push @hostmasks, "$users{$id} ($id)";
}
return "Found multiple accounts: " . (join ', ', sort @hostmasks);
} else {
# found just one account, we'll use it
$message_account = $accounts[0];
$hostmask = $self->{pbot}->{messagehistory}->{database}->find_most_recent_hostmask($accounts[0]);
}
} else {
($message_account, $hostmask) = $self->{pbot}->{messagehistory}->{database}->find_message_account_by_nick($target);
return "I don't know anybody named $target." if not $message_account;

View File

@ -378,17 +378,20 @@ sub find_message_accounts_by_nickserv {
}
sub find_message_accounts_by_mask {
my ($self, $mask) = @_;
my ($self, $mask, $limit) = @_;
$limit //= 100;
my $qmask = quotemeta $mask;
$qmask =~ s/_/\\_/g;
$qmask =~ s/\\\./_/g;
$qmask =~ s/\\\*/%/g;
$qmask =~ s/\\\?/_/g;
$qmask =~ s/\\\$.*$//;
my $accounts = eval {
my $sth = $self->{dbh}->prepare('SELECT id FROM Hostmasks WHERE hostmask LIKE ? ESCAPE "\"');
$sth->execute($qmask);
my $sth = $self->{dbh}->prepare('SELECT id FROM Hostmasks WHERE hostmask LIKE ? ESCAPE "\" LIMIT ?');
$sth->execute($qmask, $limit);
return $sth->fetchall_arrayref();
};
$self->{pbot}->{logger}->log($@) if $@;

View File

@ -25,8 +25,8 @@ use PBot::Imports;
# These are set by the /misc/update_version script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 4388,
BUILD_DATE => "2021-09-12",
BUILD_REVISION => 4389,
BUILD_DATE => "2021-09-14",
};
sub initialize {}