line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::BasicBot::Pluggable::Module::Loader; |
2
|
|
|
|
|
|
|
$Bot::BasicBot::Pluggable::Module::Loader::VERSION = '1.20'; |
3
|
2
|
|
|
2
|
|
9
|
use base qw(Bot::BasicBot::Pluggable::Module); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
146
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
48
|
|
5
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
39
|
|
6
|
2
|
|
|
2
|
|
6
|
use Try::Tiny; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1138
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub init { |
9
|
2
|
|
|
2
|
1
|
2
|
my $self = shift; |
10
|
2
|
|
|
|
|
11
|
my @modules = grep !/^user_/, $self->store_keys; |
11
|
2
|
|
|
|
|
6
|
for (@modules) { |
12
|
0
|
|
|
0
|
|
|
try { $self->{Bot}->load($_) } catch { warn "Error loading $_: $@." }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub help { |
17
|
|
|
|
|
|
|
return |
18
|
0
|
|
|
0
|
1
|
|
"Module loader and unloader. Usage: !load <module>, !unload <module>, !reload <module>, !list."; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub maybe_join { |
22
|
0
|
|
|
0
|
0
|
|
my ( $sep, @list ) = @_; |
23
|
0
|
0
|
|
|
|
|
return $list[0] if @list == 1; |
24
|
0
|
0
|
|
|
|
|
return join( $sep, @list ) if @list > 1; |
25
|
0
|
0
|
|
|
|
|
return '' if !@list; |
26
|
0
|
|
|
|
|
|
return; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub told { |
30
|
0
|
|
|
0
|
1
|
|
my ( $self, $mess ) = @_; |
31
|
0
|
|
|
|
|
|
my $body = $mess->{body}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# we don't care about commands that don't start with '!' |
34
|
0
|
0
|
|
|
|
|
return 0 unless defined $body; |
35
|
0
|
0
|
|
|
|
|
return 0 unless $body =~ /^!/; |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
return if !$self->authed( $mess->{who} ); |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my ( $command, $param ) = split( /\s+/, $body, 2 ); |
40
|
0
|
|
|
|
|
|
$command = lc($command); |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
if ( $command eq "!list" ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my %available = map { lc $_ => $_ } $self->bot->available_modules(); |
|
0
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my @loaded = map { delete $available{$_} } @{ $self->bot->handlers() }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my @available = values %available; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $loaded = maybe_join( ', ', sort @loaded ); |
48
|
0
|
|
|
|
|
|
my $available = maybe_join( ', ', sort @available ); |
49
|
0
|
|
|
|
|
|
return "Loaded modules: $loaded\nAvailable modules: $available"; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif ( $command eq "!load" ) { |
53
|
0
|
|
|
0
|
|
|
try { $self->bot->load($param) } catch { return "Failed: $@." }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
$self->set( $param => 1 ); |
55
|
0
|
|
|
|
|
|
return "Success."; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
elsif ( $command eq "!reload" ) { |
59
|
0
|
|
|
0
|
|
|
try { $self->bot->reload($param) } catch { return "Failed: $@." }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return "Success."; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif ( $command eq "!unload" ) { |
64
|
0
|
|
|
0
|
|
|
try { $self->bot->unload($param) } catch { return "Failed: $@." }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$self->unset($param); |
66
|
0
|
|
|
|
|
|
return "Success."; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 NAME |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Bot::BasicBot::Pluggable::Module::Loader - loads and unloads bot modules; remembers state |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 VERSION |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
version 1.20 |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 IRC USAGE |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=over 4 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item !load <module> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Loads the named module. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item !unload <module> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Unloads the named module. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item !reload <module> |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Reloads a module (combines !unload and !load). |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item !list |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Lists all loaded modules. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=back |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHOR |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Mario Domgoergen <mdom@cpan.org> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This program is free software; you can redistribute it |
109
|
|
|
|
|
|
|
and/or modify it under the same terms as Perl itself. |