mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-26 22:09:26 +01:00
Add ability to show alias relationships in aka
command
This commit is contained in:
parent
5effcd57ac
commit
d7d6083a25
@ -128,7 +128,7 @@ sub aka_unlink {
|
|||||||
sub list_also_known_as {
|
sub list_also_known_as {
|
||||||
my ($self, $from, $nick, $user, $host, $arguments) = @_;
|
my ($self, $from, $nick, $user, $host, $arguments) = @_;
|
||||||
|
|
||||||
my $usage = "Usage: aka [-h] [-i] [-n] <nick>; -h show hostmasks; -i show ids; -n show nickserv accounts";
|
my $usage = "Usage: aka [-h] [-i] [-n] [-r] <nick>; -h show hostmasks; -i show ids; -n show nickserv accounts; -r show relationships";
|
||||||
|
|
||||||
if(not length $arguments) {
|
if(not length $arguments) {
|
||||||
return $usage;
|
return $usage;
|
||||||
@ -140,10 +140,11 @@ sub list_also_known_as {
|
|||||||
chomp $getopt_error;
|
chomp $getopt_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
my ($show_hostmasks, $show_nickserv, $show_id, $dont_use_aliases_table);
|
my ($show_hostmasks, $show_nickserv, $show_id, $show_relationship, $dont_use_aliases_table);
|
||||||
my ($ret, $args) = GetOptionsFromString($arguments,
|
my ($ret, $args) = GetOptionsFromString($arguments,
|
||||||
'h' => \$show_hostmasks,
|
'h' => \$show_hostmasks,
|
||||||
'n' => \$show_nickserv,
|
'n' => \$show_nickserv,
|
||||||
|
'r' => \$show_relationship,
|
||||||
'nt' => \$dont_use_aliases_table,
|
'nt' => \$dont_use_aliases_table,
|
||||||
'i' => \$show_id);
|
'i' => \$show_id);
|
||||||
|
|
||||||
@ -170,8 +171,18 @@ sub list_also_known_as {
|
|||||||
$result .= "$sep$aka";
|
$result .= "$sep$aka";
|
||||||
}
|
}
|
||||||
$result .= " ($akas{$aka}->{nickserv})" if $show_nickserv and exists $akas{$aka}->{nickserv};
|
$result .= " ($akas{$aka}->{nickserv})" if $show_nickserv and exists $akas{$aka}->{nickserv};
|
||||||
$result .= " [$akas{$aka}->{id}]" if $show_id;
|
|
||||||
if ($show_hostmasks or $show_nickserv or $show_id) {
|
if ($show_relationship) {
|
||||||
|
if ($akas{$aka}->{id} == $akas{$aka}->{alias}) {
|
||||||
|
$result .= " [$akas{$aka}->{id}]";
|
||||||
|
} else {
|
||||||
|
$result .= " [$akas{$aka}->{id} -> $akas{$aka}->{alias}]";
|
||||||
|
}
|
||||||
|
} elsif ($show_id) {
|
||||||
|
$result .= " [$akas{$aka}->{id}]";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($show_hostmasks or $show_nickserv or $show_id or $show_relationship) {
|
||||||
$sep = ",\n";
|
$sep = ",\n";
|
||||||
} else {
|
} else {
|
||||||
$sep = ", ";
|
$sep = ", ";
|
||||||
|
@ -956,14 +956,13 @@ sub get_also_known_as {
|
|||||||
my %akas = eval {
|
my %akas = eval {
|
||||||
my (%akas, %hostmasks, %ids);
|
my (%akas, %hostmasks, %ids);
|
||||||
|
|
||||||
if (not $dont_use_aliases_table) {
|
unless ($dont_use_aliases_table) {
|
||||||
my ($id, $hostmask) = $self->find_message_account_by_nick($nick);
|
my ($id, $hostmask) = $self->find_message_account_by_nick($nick);
|
||||||
|
|
||||||
if (not defined $id) {
|
if (not defined $id) {
|
||||||
return %akas;
|
return %akas;
|
||||||
}
|
}
|
||||||
|
|
||||||
$akas{$hostmask} = { hostmask => $hostmask, id => $id };
|
|
||||||
$ids{$id} = $id;
|
$ids{$id} = $id;
|
||||||
|
|
||||||
my $sth = $self->{dbh}->prepare('SELECT alias FROM Aliases WHERE id = ?');
|
my $sth = $self->{dbh}->prepare('SELECT alias FROM Aliases WHERE id = ?');
|
||||||
@ -972,7 +971,18 @@ sub get_also_known_as {
|
|||||||
my $rows = $sth->fetchall_arrayref({});
|
my $rows = $sth->fetchall_arrayref({});
|
||||||
|
|
||||||
foreach my $row (@$rows) {
|
foreach my $row (@$rows) {
|
||||||
$ids{$row->{alias}} = $row->{alias};
|
$ids{$row->{alias}} = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach my $id (keys %ids) {
|
||||||
|
my $sth = $self->{dbh}->prepare('SELECT alias FROM Aliases WHERE id = ?');
|
||||||
|
$sth->bind_param(1, $id);
|
||||||
|
$sth->execute();
|
||||||
|
my $rows = $sth->fetchall_arrayref({});
|
||||||
|
|
||||||
|
foreach my $row (@$rows) {
|
||||||
|
$ids{$row->{alias}} = $id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $id (keys %ids) {
|
foreach my $id (keys %ids) {
|
||||||
@ -982,7 +992,7 @@ sub get_also_known_as {
|
|||||||
$rows = $sth->fetchall_arrayref({});
|
$rows = $sth->fetchall_arrayref({});
|
||||||
|
|
||||||
foreach my $row (@$rows) {
|
foreach my $row (@$rows) {
|
||||||
$akas{$row->{hostmask}} = { hostmask => $row->{hostmask}, id => $id };
|
$akas{$row->{hostmask}} = { hostmask => $row->{hostmask}, id => $id, alias => $ids{$id} };
|
||||||
}
|
}
|
||||||
|
|
||||||
$sth = $self->{dbh}->prepare('SELECT nickserv FROM Nickserv WHERE id = ?');
|
$sth = $self->{dbh}->prepare('SELECT nickserv FROM Nickserv WHERE id = ?');
|
||||||
|
Loading…
Reference in New Issue
Block a user