App-RoboBot

 view release on metacpan or  search on metacpan

lib/App/RoboBot/Plugin/Core/Help.pm  view on Meta::CPAN

        'help-all' => { method      => 'help_all',
                        description => 'Displays a complete listing of all functions and macros available on the current network.', },
    }},
);

sub help {
    my ($self, $message, $command, $rpl, $section, @args) = @_;

    if (defined $section && $section =~ m{\w+}o) {
        if ($section =~ m{^\:?(mod(ule)|plugin)?$}oi) {
            if (@args && defined $args[0] && $args[0] =~ m{\w+}o) {
                $self->plugin_help($message, $args[0]);
            } else {
                $self->general_help($message);
            }
        } elsif (exists $self->bot->commands->{$section}) {
            $self->command_help($message, $section);
        } elsif (exists $self->bot->macros->{$message->network->id}{lc($section)}) {
            $self->macro_help($message, $section);
        } elsif (grep { lc($section) eq $_->ns } @{$self->bot->plugins}) {
            $self->plugin_help($message, $section);
        } else {
            $message->response->push(sprintf('Unknown help section: %s', $section));
        }
    } else {
        $self->general_help($message);
    }

    return;
}

sub help_all {
    my ($self, $message) = @_;

    my @functions = sort { $a cmp $b } (
        map { keys %{$_->commands} }
        grep { ! exists $message->network->disabled_plugins->{lc($_->name)} }
        @{$self->bot->plugins}
    );

    my @macros = sort { $a cmp $b } (
        map { lc($_) }
        keys %{$self->bot->macros->{$message->network->id}}
    );

    my $res = $self->bot->config->db->do(q{
        select var_name
        from global_vars
        where network_id = ?
        order by lower(var_name) asc
    }, $message->network->id);

    my @globals;
    if ($res) {
        while ($res->next) {
            push(@globals, $res->{'var_name'});
        }
    }

    $message->response->push(sprintf('*Functions*: %s', join(', ', @functions))) if @functions > 0;
    $message->response->push(sprintf('*Macros*: %s', join(', ', @macros))) if @macros > 0;
    $message->response->push(sprintf('*Globals*: %s', join(', ', @globals))) if @globals > 0;

    return;
}

sub general_help {
    my ($self, $message) = @_;

    my %plugins = (
        map { $_->ns => 1 }
        grep { ! exists $message->network->disabled_plugins->{lc($_->name)} }
        @{$self->bot->plugins}
    );

    $message->response->push(sprintf('App::RoboBot v%s', $self->bot->version));
    $message->response->push(sprintf('Documentation: https://robobot.automatomatromaton.com/'));
    $message->response->push(sprintf('For additional help, use (help <function>) or (help :module "<name>"). Use (help-all) to see a complete list of functions and macros available on the current network.'));
    $message->response->push(sprintf('Active modules: %s', join(', ', sort keys %plugins)));

    # Return before the function display for now.
    return;

    local $Text::Wrap::columns = 200;
    my @functions = split(
        /\n/o,
        wrap( 'Available functions: ',
              '',
              join(', ',
                  sort { lc($a) cmp lc($b) }
                  grep { $_ !~ m{\w+/[^/]+$}o && !exists $message->network->disabled_plugins->{lc($self->bot->commands->{$_}->name)} }
                  keys %{$self->bot->commands}
              )
        )
    );
    $message->response->push($_) for @functions;

    return;
}

sub plugin_help {
    my ($self, $message, $plugin_name) = @_;

    my ($plugin) = (grep { $_->ns eq lc($plugin_name) } @{$self->bot->plugins});

    if (defined $plugin) {
        $message->response->push(sprintf('App::RoboBot Module: %s', $plugin->ns));
        $message->response->push(sprintf('Documentation: https://robobot.automatomatromaton.com/modules/%s/index.html', $plugin->ns));
        $message->response->push($plugin->description) if $plugin->has_description;
        $message->response->push(sprintf('Exports functions: %s', join(', ', sort keys %{$plugin->commands})));
    } else {
        $message->response->push(sprintf('Unknown module: %s', $plugin_name));
    }

    return;
}

sub command_help {
    my ($self, $message, $command_name, $rpl) = @_;

    if (exists $self->bot->commands->{$command_name}) {



( run in 0.496 second using v1.01-cache-2.11-cpan-39bf76dae61 )