From be47b2cbf22865e448284e1b68e76c01cba6c460 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Fri, 20 Mar 2015 21:14:07 -0700 Subject: [PATCH] Improve output of blacklist and ignorelist commands --- PBot/BlackList.pm | 14 +++++++++----- PBot/IgnoreList.pm | 2 +- PBot/IgnoreListCommands.pm | 18 +++++++++++++----- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/PBot/BlackList.pm b/PBot/BlackList.pm index a30ece2c..8ccb711c 100644 --- a/PBot/BlackList.pm +++ b/PBot/BlackList.pm @@ -161,12 +161,16 @@ sub blacklist { when($_ eq "list" or $_ eq "show") { my $text = "Blacklist:\n"; my $entries = 0; - foreach my $channel (keys %{ $self->{blacklist} }) { + foreach my $channel (sort keys %{ $self->{blacklist} }) { + if ($channel eq '.*') { + $text .= " all channels:\n"; + } else { $text .= " $channel:\n"; - foreach my $mask (keys %{ $self->{blacklist}->{$channel} }) { - $text .= " $mask,\n"; - $entries++; - } + } + foreach my $mask (sort keys %{ $self->{blacklist}->{$channel} }) { + $text .= " $mask,\n"; + $entries++; + } } $text .= "none" if $entries == 0; return $text; diff --git a/PBot/IgnoreList.pm b/PBot/IgnoreList.pm index 3b169a53..e8d3a107 100644 --- a/PBot/IgnoreList.pm +++ b/PBot/IgnoreList.pm @@ -44,7 +44,7 @@ sub add { my $self = shift; my ($hostmask, $channel, $length) = @_; - if($length == -1) { + if($length < 0) { $self->{ignore_list}->{$hostmask}->{$channel} = -1; } else { $self->{ignore_list}->{$hostmask}->{$channel} = gettimeofday + $length; diff --git a/PBot/IgnoreListCommands.pm b/PBot/IgnoreListCommands.pm index b3f41064..deffecfe 100644 --- a/PBot/IgnoreListCommands.pm +++ b/PBot/IgnoreListCommands.pm @@ -9,6 +9,7 @@ use warnings; use strict; use Time::HiRes qw(gettimeofday); +use Time::Duration; use Carp (); sub new { @@ -53,9 +54,9 @@ sub ignore_user { my $text = "Ignored: "; my $sep = ""; - foreach my $ignored (keys %{ $self->{pbot}->{ignorelist}->{ignore_list} }) { - foreach my $channel (keys %{ ${ $self->{pbot}->{ignorelist}->{ignore_list} }{$ignored} }) { - $text .= $sep . "[$ignored]->[$channel]->[" . (${ $self->{pbot}->{ignorelist}->{ignore_list} }{$ignored}{$channel} == -1 ? -1 : int(gettimeofday - ${ $self->{pbot}->{ignorelist}->{ignore_list} }{$ignored}{$channel})) . "]"; + foreach my $ignored (sort keys %{ $self->{pbot}->{ignorelist}->{ignore_list} }) { + foreach my $channel (sort keys %{ ${ $self->{pbot}->{ignorelist}->{ignore_list} }{$ignored} }) { + $text .= $sep . "$ignored [$channel] " . ($self->{pbot}->{ignorelist}->{ignore_list}->{$ignored}->{$channel} < 0 ? "perm" : duration($self->{pbot}->{ignorelist}->{ignore_list}->{$ignored}->{$channel} - gettimeofday)); $sep = ";\n"; } } @@ -70,9 +71,16 @@ sub ignore_user { $length = -1; # permanently } - $self->{pbot}->{logger}->log("$nick added [$target][$channel] to ignore list for $length seconds\n"); $self->{pbot}->{ignorelist}->add($target, $channel, $length); - return "/msg $nick [$target][$channel] added to ignore list for $length seconds"; + + if ($length >= 0) { + $length = "for " . duration($length); + } else { + $length = "permanently"; + } + + $self->{pbot}->{logger}->log("$nick added [$target][$channel] to ignore list $length\n"); + return "/msg $nick [$target][$channel] added to ignore list $length"; } sub unignore_user {