From 42c2554655e70e73a68c96b5a6965fdde05f5533 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Wed, 5 Mar 2014 14:28:58 +0000 Subject: [PATCH] Add chanlist command to list channel data --- PBot/Channels.pm | 23 ++++++++++++++++++----- PBot/VERSION.pm | 4 ++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/PBot/Channels.pm b/PBot/Channels.pm index 06132f2f..f1ca2e9d 100644 --- a/PBot/Channels.pm +++ b/PBot/Channels.pm @@ -29,11 +29,7 @@ sub new { sub initialize { my ($self, %conf) = @_; - my $pbot = delete $conf{pbot}; - if(not defined $pbot) { - Carp::croak ("Missing pbot reference to Channels"); - } - + my $pbot = delete $conf{pbot} // Carp::croak("Missing pbot reference to Channels"); my $filename = delete $conf{filename}; $self->{pbot} = $pbot; @@ -43,6 +39,7 @@ sub initialize { $pbot->commands->register(sub { $self->unset(@_) }, "chanunset", 40); $pbot->commands->register(sub { $self->add(@_) }, "chanadd", 40); $pbot->commands->register(sub { $self->remove(@_) }, "chanrem", 40); + $pbot->commands->register(sub { $self->list(@_) }, "chanlist", 10); } sub set { @@ -91,6 +88,22 @@ sub remove { return "/msg $nick " . $self->channels->remove($arguments); } +sub list { + my ($self, $from, $nick, $user, $host, $arguments) = @_; + my $result; + + foreach my $index (sort keys %{ $self->channels->hash }) { + $result .= "$index: {"; + my $comma = ' '; + foreach my $key (sort keys %{ ${ $self->channels->hash }{$index} }) { + $result .= "$comma$key => ${ $self->channels->hash }{$index}{$key}"; + $comma = ', '; + } + $result .= " }\n"; + } + return "/msg $nick $result"; +} + sub load_channels { my $self = shift; diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index cfcfb7f5..c21f25e3 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,8 +13,8 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 503, - BUILD_DATE => "2014-03-04", + BUILD_REVISION => 504, + BUILD_DATE => "2014-03-05", }; 1;