Add chanlist command to list channel data

This commit is contained in:
Pragmatic Software 2014-03-05 14:28:58 +00:00
parent a5ae7478e1
commit 42c2554655
2 changed files with 20 additions and 7 deletions

View File

@ -29,11 +29,7 @@ sub new {
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
my $pbot = delete $conf{pbot}; my $pbot = delete $conf{pbot} // Carp::croak("Missing pbot reference to Channels");
if(not defined $pbot) {
Carp::croak ("Missing pbot reference to Channels");
}
my $filename = delete $conf{filename}; my $filename = delete $conf{filename};
$self->{pbot} = $pbot; $self->{pbot} = $pbot;
@ -43,6 +39,7 @@ sub initialize {
$pbot->commands->register(sub { $self->unset(@_) }, "chanunset", 40); $pbot->commands->register(sub { $self->unset(@_) }, "chanunset", 40);
$pbot->commands->register(sub { $self->add(@_) }, "chanadd", 40); $pbot->commands->register(sub { $self->add(@_) }, "chanadd", 40);
$pbot->commands->register(sub { $self->remove(@_) }, "chanrem", 40); $pbot->commands->register(sub { $self->remove(@_) }, "chanrem", 40);
$pbot->commands->register(sub { $self->list(@_) }, "chanlist", 10);
} }
sub set { sub set {
@ -91,6 +88,22 @@ sub remove {
return "/msg $nick " . $self->channels->remove($arguments); 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 { sub load_channels {
my $self = shift; my $self = shift;

View File

@ -13,8 +13,8 @@ use warnings;
# These are set automatically by the build/commit script # These are set automatically by the build/commit script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 503, BUILD_REVISION => 504,
BUILD_DATE => "2014-03-04", BUILD_DATE => "2014-03-05",
}; };
1; 1;