From c124d12dd54c2ec6525a1b90e5c584988894e83b Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 31 Oct 2009 02:37:02 -0500 Subject: convert !cmdlist into a default plugin rather than hardcoding it --- lib/IM/Engine/Plugin/Commands.pm | 17 +++++++++-------- lib/IM/Engine/Plugin/Commands/Command/Cmdlist.pm | 11 +++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 lib/IM/Engine/Plugin/Commands/Command/Cmdlist.pm diff --git a/lib/IM/Engine/Plugin/Commands.pm b/lib/IM/Engine/Plugin/Commands.pm index 38b9850..4bd556c 100644 --- a/lib/IM/Engine/Plugin/Commands.pm +++ b/lib/IM/Engine/Plugin/Commands.pm @@ -1,6 +1,7 @@ package IM::Engine::Plugin::Commands; use Moose; use Module::Pluggable sub_name => 'commands'; +Sub::Name::subname('commands', \&commands); use List::Util qw(first); extends 'IM::Engine::Plugin'; @@ -95,11 +96,6 @@ sub incoming { return unless $text =~ /^\Q$prefix\E(\w+)(?:\s+(.*))?/; my ($command_name, $action) = (lc($1), $2); - if ($command_name eq 'cmdlist') { # XXX: make this configurable - $self->say(join ' ', map { $self->prefix . $_} $self->command_list); - return; - } - if ($command_name eq 'help') { $command_name = $action; $command_name =~ s/^-//; @@ -124,8 +120,8 @@ sub incoming { if (!$self->_active_commands->{$command_name}->is_active && (!defined($action) || $action !~ /^-/)) { - $self->say($command->init($sender)) if $command->can('init'); $self->_active_commands->{$command_name}->is_active(1); + $self->say($command->init($sender)) if $command->can('init'); } return unless defined $action; @@ -166,10 +162,15 @@ sub say { $self->engine->send_message($self->_last_message->reply($message)); } +around commands => sub { + my $orig = shift; + my $self = shift; + return ($self->$orig(@_), 'IM::Engine::Plugin::Commands::Command::Cmdlist'); +}; + sub command_list { my $self = shift; - my $namespace = $self->namespace; - return sort map { s/\Q${namespace}:://; lc } $self->commands; + return sort map { s/.*:://; lc } $self->commands; } sub is_command { diff --git a/lib/IM/Engine/Plugin/Commands/Command/Cmdlist.pm b/lib/IM/Engine/Plugin/Commands/Command/Cmdlist.pm new file mode 100644 index 0000000..6d9444a --- /dev/null +++ b/lib/IM/Engine/Plugin/Commands/Command/Cmdlist.pm @@ -0,0 +1,11 @@ +package IM::Engine::Plugin::Commands::Command::Cmdlist; +use IM::Engine::Plugin::Commands::OO; + +sub init { + my $self = shift; + $self->is_active(0); + return join ' ', map { $self->_ime_plugin->prefix . $_} + $self->_ime_plugin->command_list; +} + +1; -- cgit v1.2.3