This file is indexed.

/usr/share/perl5/Bot/BasicBot/Pluggable/Module/Loader.pm is in libbot-basicbot-pluggable-perl 1.20-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
package Bot::BasicBot::Pluggable::Module::Loader;
$Bot::BasicBot::Pluggable::Module::Loader::VERSION = '1.20';
use base qw(Bot::BasicBot::Pluggable::Module);
use warnings;
use strict;
use Try::Tiny;

sub init {
    my $self    = shift;
    my @modules = grep !/^user_/, $self->store_keys;
    for (@modules) {
        try { $self->{Bot}->load($_) } catch { warn "Error loading $_: $@." };
    }
}

sub help {
    return
"Module loader and unloader. Usage: !load <module>, !unload <module>, !reload <module>, !list.";
}

sub maybe_join {
    my ( $sep, @list ) = @_;
    return $list[0] if @list == 1;
    return join( $sep, @list ) if @list > 1;
    return '' if !@list;
    return;
}

sub told {
    my ( $self, $mess ) = @_;
    my $body = $mess->{body};

    # we don't care about commands that don't start with '!'
    return 0 unless defined $body;
    return 0 unless $body =~ /^!/;

    return if !$self->authed( $mess->{who} );

    my ( $command, $param ) = split( /\s+/, $body, 2 );
    $command = lc($command);

    if ( $command eq "!list" ) {
        my %available = map { lc $_ => $_ } $self->bot->available_modules();
        my @loaded = map { delete $available{$_} } @{ $self->bot->handlers() };
        my @available = values %available;

        my $loaded    = maybe_join( ', ', sort @loaded );
        my $available = maybe_join( ', ', sort @available );
        return "Loaded modules: $loaded\nAvailable modules: $available";

    }
    elsif ( $command eq "!load" ) {
        try { $self->bot->load($param) } catch { return "Failed: $@." };
        $self->set( $param => 1 );
        return "Success.";

    }
    elsif ( $command eq "!reload" ) {
        try { $self->bot->reload($param) } catch { return "Failed: $@." };
        return "Success.";

    }
    elsif ( $command eq "!unload" ) {
        try { $self->bot->unload($param) } catch { return "Failed: $@." };
        $self->unset($param);
        return "Success.";
    }
}

1;

__END__

=head1 NAME

Bot::BasicBot::Pluggable::Module::Loader - loads and unloads bot modules; remembers state

=head1 VERSION

version 1.20

=head1 IRC USAGE

=over 4

=item !load <module>

Loads the named module.

=item !unload <module>

Unloads the named module.

=item !reload <module>

Reloads a module (combines !unload and !load).

=item !list

Lists all loaded modules.

=back

=head1 AUTHOR

Mario Domgoergen <mdom@cpan.org>

This program is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.