From 0260da349d165ae8b90c23a00359879b25c62334 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 31 Oct 2009 02:50:52 -0500 Subject: move !help out into its own default plugin --- lib/IM/Engine/Plugin/Commands.pm | 15 +++++++-------- lib/IM/Engine/Plugin/Commands/Command/Help.pm | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 lib/IM/Engine/Plugin/Commands/Command/Help.pm (limited to 'lib') diff --git a/lib/IM/Engine/Plugin/Commands.pm b/lib/IM/Engine/Plugin/Commands.pm index 4bd556c..e5ecec8 100644 --- a/lib/IM/Engine/Plugin/Commands.pm +++ b/lib/IM/Engine/Plugin/Commands.pm @@ -96,12 +96,6 @@ sub incoming { return unless $text =~ /^\Q$prefix\E(\w+)(?:\s+(.*))?/; my ($command_name, $action) = (lc($1), $2); - if ($command_name eq 'help') { - $command_name = $action; - $command_name =~ s/^-//; - $action = '-help'; - } - $command_name = $self->_find_command($command_name); return unless $command_name; @@ -145,7 +139,8 @@ sub incoming { } } else { - $self->say($command->default($sender, $action)); + my $output = $command->default($sender, $action); + $self->say($output) if defined $output; } if (!$command->is_active) { @@ -165,7 +160,11 @@ sub say { around commands => sub { my $orig = shift; my $self = shift; - return ($self->$orig(@_), 'IM::Engine::Plugin::Commands::Command::Cmdlist'); + return ( + $self->$orig(@_), + 'IM::Engine::Plugin::Commands::Command::Cmdlist', + 'IM::Engine::Plugin::Commands::Command::Help', + ); }; sub command_list { diff --git a/lib/IM/Engine/Plugin/Commands/Command/Help.pm b/lib/IM/Engine/Plugin/Commands/Command/Help.pm new file mode 100644 index 0000000..b28472a --- /dev/null +++ b/lib/IM/Engine/Plugin/Commands/Command/Help.pm @@ -0,0 +1,16 @@ +package IM::Engine::Plugin::Commands::Command::Help; +use IM::Engine::Plugin::Commands::OO; + +sub default { + my $self = shift; + my ($sender, $action) = @_; + $self->is_active(0); + my $prefix = $self->_ime_plugin->prefix; + my $message = IM::Engine::Incoming->new( + sender => $self->_ime_plugin->_last_message->sender, + message => "${prefix}$action -help", + ); + return $self->_ime_plugin->incoming($message); +} + +1; -- cgit v1.2.3-54-g00ecf