summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-10-31 02:37:02 -0500
committerJesse Luehrs <doy@tozt.net>2009-10-31 02:37:02 -0500
commitc124d12dd54c2ec6525a1b90e5c584988894e83b (patch)
treee0b31310d5c1f722b420534091d44bba70ed330b
parent72ea018ebf9e31f8249a43f2b0aeb57b6facb6e3 (diff)
downloadim-engine-plugin-commands-c124d12dd54c2ec6525a1b90e5c584988894e83b.tar.gz
im-engine-plugin-commands-c124d12dd54c2ec6525a1b90e5c584988894e83b.zip
convert !cmdlist into a default plugin rather than hardcoding it
-rw-r--r--lib/IM/Engine/Plugin/Commands.pm17
-rw-r--r--lib/IM/Engine/Plugin/Commands/Command/Cmdlist.pm11
2 files changed, 20 insertions, 8 deletions
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;