line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package LiBot::Handler::LLEval; |
2
|
1
|
|
|
1
|
|
1716
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
6
|
use utf8; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
5
|
1
|
|
|
1
|
|
26
|
use Furl; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
6
|
1
|
|
|
1
|
|
13
|
use URI::Escape qw(uri_escape_utf8); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
71
|
|
7
|
1
|
|
|
1
|
|
6
|
use JSON qw(decode_json); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
8
|
1
|
|
|
1
|
|
162
|
use Text::Shorten qw(shorten_scalar); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
7
|
use Mouse; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
449
|
no Mouse; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub lleval { |
15
|
0
|
|
|
0
|
0
|
|
my ($src, $lang) = @_; |
16
|
0
|
|
|
|
|
|
my $ua = Furl->new(agent => 'lleval2lingr', timeout => 5); |
17
|
0
|
|
|
|
|
|
my $res = $ua->get(sprintf('http://api.dan.co.jp/lleval.cgi?l=%s&s=%s', $lang, uri_escape_utf8($src))); |
18
|
0
|
0
|
|
|
|
|
$res->is_success or die $res->status_line; |
19
|
0
|
|
|
|
|
|
print $res->content, "\n"; |
20
|
0
|
|
|
|
|
|
return decode_json($res->content); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub init { |
24
|
0
|
|
|
0
|
0
|
|
my ($self, $bot) = @_; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$bot->register( |
27
|
|
|
|
|
|
|
qr/^!\s*(.*)/s => sub { |
28
|
0
|
|
|
0
|
|
|
my ( $cb, $event, $code ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $lang = 'pl'; |
31
|
0
|
0
|
|
|
|
|
if ($code =~ /^!\s*([a-z0-9]+)\s*(.+)/s) { |
32
|
0
|
|
|
|
|
|
$lang = $1; |
33
|
0
|
|
|
|
|
|
$code = $2; |
34
|
|
|
|
|
|
|
} else { |
35
|
0
|
0
|
|
|
|
|
unless ( $code =~ m{^(print|say)} ) { |
36
|
0
|
|
|
|
|
|
$code = "print sub { ${code} }->()"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
my $res = lleval($code, $lang); |
40
|
0
|
0
|
|
|
|
|
if ( defined $res->{error} ) { |
41
|
0
|
|
|
|
|
|
$cb->( shorten_scalar( $res->{error}, 80 ) ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
0
|
|
|
|
|
|
$cb->( shorten_scalar( $res->{stdout} . $res->{stderr}, 80 ) ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
0
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
__END__ |