line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::Cobalt::Plugin::Figlet; |
2
|
|
|
|
|
|
|
# ABSTRACT: Bot::Cobalt plugin for displaying figlets |
3
|
|
|
|
|
|
|
$Bot::Cobalt::Plugin::Figlet::VERSION = '0.001'; |
4
|
1
|
|
|
1
|
|
20799
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
365
|
use Bot::Cobalt; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Bot::Cobalt::Common; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use List::AllUtils qw(shuffle); |
11
|
|
|
|
|
|
|
use Path::Tiny; |
12
|
|
|
|
|
|
|
use Text::FIGlet; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { bless {}, shift } |
15
|
|
|
|
|
|
|
sub fontdir { path( shift->{fontdir} )->absolute } |
16
|
|
|
|
|
|
|
sub width { shift->{maxwidth} } |
17
|
|
|
|
|
|
|
sub prev { shift->{previous} } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub fonts { |
20
|
|
|
|
|
|
|
my $self = shift; |
21
|
|
|
|
|
|
|
my $extrx = qr/\.[tf]lf$/; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
return map { $_->basename($extrx) } $self->fontdir->children($extrx); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub Cobalt_register { |
27
|
|
|
|
|
|
|
my $self = shift; |
28
|
|
|
|
|
|
|
my $core = shift; |
29
|
|
|
|
|
|
|
my $conf = $core->get_plugin_cfg($self); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$self->{fontdir} = $conf->{fontdir} || '/usr/games/lib/figlet'; |
32
|
|
|
|
|
|
|
$self->{maxwidth} = $conf->{maxwidth} || -1; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
if (not -d $self->fontdir) { |
35
|
|
|
|
|
|
|
logger->warn("Unable to find figlet fonts at " . $self->fontdir); |
36
|
|
|
|
|
|
|
return PLUGIN_EAT_NONE; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
register( $self, 'SERVER', 'public_cmd_figlet', 'public_cmd_prev_figlet' ); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
logger->info("Registered, commands: !figlet, !prev_figlet"); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return PLUGIN_EAT_NONE; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub Cobalt_unregister { |
47
|
|
|
|
|
|
|
my $self = shift; |
48
|
|
|
|
|
|
|
my $core = shift; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
logger->info("Unregistered"); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
return PLUGIN_EAT_NONE; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub Bot_public_cmd_prev_figlet { |
56
|
|
|
|
|
|
|
my $self = shift; |
57
|
|
|
|
|
|
|
my $core = shift; |
58
|
|
|
|
|
|
|
my $msg = ${ shift() }; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
broadcast( 'message', $msg->context, $msg->channel, $self->prev ) |
61
|
|
|
|
|
|
|
if $self->prev; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
return PLUGIN_EAT_ALL; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub Bot_public_cmd_figlet { |
67
|
|
|
|
|
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
my $core = shift; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $msg = ${ shift() }; |
71
|
|
|
|
|
|
|
my $context = $msg->context; |
72
|
|
|
|
|
|
|
my $channel = $msg->target; |
73
|
|
|
|
|
|
|
my @split = split(/ /, $msg->stripped); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
shift @split; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $str = join(' ', @split); |
78
|
|
|
|
|
|
|
my $font = (shuffle($self->fonts))[0]; |
79
|
|
|
|
|
|
|
my $figlet = Text::FIGlet->new(-d => $self->fontdir, -f => $font); |
80
|
|
|
|
|
|
|
my $text = $figlet->figify(-A => $str, -w => $self->width); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$self->{previous} = $font; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
broadcast( 'message', $context, $channel, $_) |
85
|
|
|
|
|
|
|
foreach split /\n/, $text; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return PLUGIN_EAT_ALL; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |