| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::LLEvalBot; |
|
2
|
3
|
|
|
3
|
|
20868
|
use 5.010001; |
|
|
3
|
|
|
|
|
12
|
|
|
|
3
|
|
|
|
|
123
|
|
|
3
|
3
|
|
|
3
|
|
15
|
use strict; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
103
|
|
|
4
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
|
3
|
|
|
|
|
15
|
|
|
|
3
|
|
|
|
|
135
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
|
7
|
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
2416
|
use UnazuSan; |
|
|
3
|
|
|
|
|
362034
|
|
|
|
3
|
|
|
|
|
110
|
|
|
9
|
3
|
|
|
3
|
|
4469
|
use LLEval; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Mouse; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has config => ( |
|
14
|
|
|
|
|
|
|
is => 'ro', |
|
15
|
|
|
|
|
|
|
isa => 'HashRef', |
|
16
|
|
|
|
|
|
|
lazy => 1, |
|
17
|
|
|
|
|
|
|
default => sub { {} }, |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has lleval => ( |
|
21
|
|
|
|
|
|
|
is => 'ro', |
|
22
|
|
|
|
|
|
|
isa => 'LLEval', |
|
23
|
|
|
|
|
|
|
lazy => 1, |
|
24
|
|
|
|
|
|
|
default => sub { LLEval->new }, |
|
25
|
|
|
|
|
|
|
); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has unazu_san => ( |
|
28
|
|
|
|
|
|
|
is => 'ro', |
|
29
|
|
|
|
|
|
|
isa => 'UnazuSan', |
|
30
|
|
|
|
|
|
|
lazy => 1, |
|
31
|
|
|
|
|
|
|
default => sub { |
|
32
|
|
|
|
|
|
|
my $self = shift; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my %conf = %{ $self->config }; |
|
35
|
|
|
|
|
|
|
UnazuSan->new(%conf); |
|
36
|
|
|
|
|
|
|
}, |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has _languages => ( |
|
40
|
|
|
|
|
|
|
is => 'ro', |
|
41
|
|
|
|
|
|
|
isa => 'HashRef', |
|
42
|
|
|
|
|
|
|
lazy => 1, |
|
43
|
|
|
|
|
|
|
default => sub { |
|
44
|
|
|
|
|
|
|
shift->lleval->languages; |
|
45
|
|
|
|
|
|
|
}, |
|
46
|
|
|
|
|
|
|
); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
no Mouse; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub call_eval { |
|
51
|
|
|
|
|
|
|
my ($self, $message) = @_; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $lleval = $self->lleval; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my %languages = %{ $self->_languages }; |
|
56
|
|
|
|
|
|
|
my $langs = '(?:' . join('|', map { quotemeta } keys %languages) . ')'; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $reg_nick = quotemeta $self->config->{nickname}; |
|
59
|
|
|
|
|
|
|
$message =~ s/\A \s* $reg_nick \s* : \s*//xms; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my ($lang, $src) = $message =~ /\A ($langs) \s+ (.+)/xms; |
|
62
|
|
|
|
|
|
|
unless ($lang) { |
|
63
|
|
|
|
|
|
|
$lang = 'pl'; |
|
64
|
|
|
|
|
|
|
$src = $message; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
if ($lang =~ /^pl/) { |
|
67
|
|
|
|
|
|
|
unless ( $src =~ /(?:print|say)/ ) { |
|
68
|
|
|
|
|
|
|
$src = "print sub { ${src} }->()"; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
$src = 'use 5.016;use warnings;'.$src; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $result = $lleval->call_eval( $src, $lang ); |
|
74
|
|
|
|
|
|
|
$result->{lang} = $lang; |
|
75
|
|
|
|
|
|
|
$result; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub run { |
|
79
|
|
|
|
|
|
|
my $self = shift; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $unazu_san = $self->unazu_san; |
|
82
|
|
|
|
|
|
|
$unazu_san->on_command( |
|
83
|
|
|
|
|
|
|
'' => sub { |
|
84
|
|
|
|
|
|
|
my $receive = shift; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $result = $self->call_eval($receive->message); |
|
87
|
|
|
|
|
|
|
my $language = $self->_languages->{$result->{lang}}; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# error? |
|
90
|
|
|
|
|
|
|
if ($result->{status}) { |
|
91
|
|
|
|
|
|
|
$receive->reply("$language returned $result->{status}!!"); |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
if ($result->{error}) { |
|
94
|
|
|
|
|
|
|
$receive->reply("error: $result->{error}"); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
for my $out (qw/stdout stderr/) { |
|
98
|
|
|
|
|
|
|
my $s = $result->{$out}; |
|
99
|
|
|
|
|
|
|
next unless defined $s; |
|
100
|
|
|
|
|
|
|
my @lines = split /\n/, $s; |
|
101
|
|
|
|
|
|
|
if (@lines > 15) { |
|
102
|
|
|
|
|
|
|
@lines = @lines[0..14]; |
|
103
|
|
|
|
|
|
|
push @lines, ' (snip!)'; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
$receive->reply($_) for @lines; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
}, |
|
108
|
|
|
|
|
|
|
); |
|
109
|
|
|
|
|
|
|
$unazu_san->run; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
|
113
|
|
|
|
|
|
|
__END__ |