Skip to content

Commit

Permalink
Wrote working Help plugin, Echo is the example of a Help-friendly plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadeusz Sośnierz committed Aug 17, 2010
1 parent 4894ac5 commit 4ae9640
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
4 changes: 4 additions & 0 deletions xmpbot/Plugin/Echo.pm
Expand Up @@ -7,6 +7,10 @@ sub BUILD {
$self->register_command('echo');
}

sub help {
'this plugin echoes what user has said'
}

sub echo {
my ($self, $msg, $data) = @_;
warn "Echo/log: $data->{jid} said exactly $data->{raw}\n";
Expand Down
28 changes: 10 additions & 18 deletions xmpbot/Plugin/Help.pm
Expand Up @@ -4,29 +4,21 @@ with 'xmpbot::Plugin';

sub BUILD {
my $self = shift;
$self->command('help');
$self->description('list all available commands');
$self->help('This plugin shows a list of available commands with short descriptions, or a longer help for a specified command');
$self->register_command('help')
}

sub msg_cb {
my ($self, $args, $bot) = @_;
my $resp;
sub help {
my ($self, $args) = @_;
if (not defined $args) {
for my $pair ($bot->plugins_pairs) {
$resp .= "$pair->[0]\t".$pair->[1]->description."\n";
}
return 'what can I help you with?'
}

my $comm = $self->bot->get_plugin($args);
if ($comm and $comm->can('help')) {
return $comm->help;
} else {
my $comm = $bot->get_plugin($args);
if ($comm) {
$resp = $comm->help;
} else {
#TODO CHANGE this!
$resp= $self->{loc}->localize('No help available for') ." ". $args;
# $resp = "No help available for '%s'",$args;
}
return "no help available for $args"
}
return $resp;
}

1;

0 comments on commit 4ae9640

Please sign in to comment.