line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::Cobalt::Plugin::URLTitle; |
2
|
|
|
|
|
|
|
# ABSTRACT: Bot::Cobalt plugin for printing the title of a URL |
3
|
|
|
|
|
|
|
$Bot::Cobalt::Plugin::URLTitle::VERSION = '0.003'; |
4
|
1
|
|
|
1
|
|
13824
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
406
|
use Bot::Cobalt; |
|
1
|
|
|
|
|
8657
|
|
|
1
|
|
|
|
|
6
|
|
8
|
1
|
|
|
1
|
|
1358
|
use Bot::Cobalt::Common; |
|
1
|
|
|
|
|
226165
|
|
|
1
|
|
|
|
|
7
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
9078
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
258190
|
|
|
1
|
|
|
|
|
10
|
|
11
|
1
|
|
|
1
|
|
704
|
use HTML::Entities qw(decode_entities); |
|
1
|
|
|
|
|
4878
|
|
|
1
|
|
|
|
|
101
|
|
12
|
1
|
|
|
1
|
|
539
|
use Text::Unidecode qw(unidecode); |
|
1
|
|
|
|
|
1078
|
|
|
1
|
|
|
|
|
52
|
|
13
|
1
|
|
|
1
|
|
426
|
use URI::Find::Simple qw(list_uris); |
|
1
|
|
|
|
|
6628
|
|
|
1
|
|
|
|
|
378
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
0
|
93
|
sub new { bless {}, shift } |
16
|
0
|
|
|
0
|
0
|
|
sub ua { shift->{useragent} } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub Cobalt_register { |
19
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
20
|
0
|
|
|
|
|
|
my $core = shift; |
21
|
0
|
|
|
|
|
|
my $conf = $core->get_plugin_cfg($self); |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
$self->{useragent} = Mojo::UserAgent->new; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
register( $self, 'SERVER', 'public_msg' ); |
26
|
0
|
|
|
|
|
|
logger->info("Registered"); |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
return PLUGIN_EAT_NONE; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub Cobalt_unregister { |
32
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
33
|
0
|
|
|
|
|
|
my $core = shift; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
logger->info("Unregistered"); |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
return PLUGIN_EAT_NONE; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub Bot_public_msg { |
41
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
42
|
0
|
|
|
|
|
|
my $core = shift; |
43
|
0
|
|
|
|
|
|
my $msg = ${ shift() }; |
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $context = $msg->context; |
46
|
0
|
|
|
|
|
|
my $channel = $msg->target; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
foreach my $uri ( list_uris($msg->message) ) { |
49
|
0
|
0
|
|
|
|
|
next if not $uri; |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
my $title = $self->ua->get($uri)->result->dom->at('title')->text or next; |
52
|
0
|
|
|
|
|
|
my $uni = unidecode($title); |
53
|
0
|
0
|
|
|
|
|
my $resp = sprintf('[ %s ]', $uni ? $uni : $title); |
54
|
0
|
|
|
|
|
|
broadcast( 'message', $context, $channel, $resp ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
return PLUGIN_EAT_NONE; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |