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.004'; |
4
|
1
|
|
|
1
|
|
14516
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
382
|
use Bot::Cobalt; |
|
1
|
|
|
|
|
8782
|
|
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
1392
|
use Bot::Cobalt::Common; |
|
1
|
|
|
|
|
274485
|
|
|
1
|
|
|
|
|
10
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
11034
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
274008
|
|
|
1
|
|
|
|
|
10
|
|
11
|
1
|
|
|
1
|
|
563
|
use HTML::Entities qw(decode_entities); |
|
1
|
|
|
|
|
4718
|
|
|
1
|
|
|
|
|
112
|
|
12
|
1
|
|
|
1
|
|
481
|
use List::AllUtils qw(first); |
|
1
|
|
|
|
|
8840
|
|
|
1
|
|
|
|
|
75
|
|
13
|
1
|
|
|
1
|
|
449
|
use Text::Unidecode qw(unidecode); |
|
1
|
|
|
|
|
963
|
|
|
1
|
|
|
|
|
54
|
|
14
|
1
|
|
|
1
|
|
427
|
use URI::Find::Simple qw(list_uris); |
|
1
|
|
|
|
|
6323
|
|
|
1
|
|
|
|
|
385
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
0
|
95
|
sub new { bless {}, shift } |
17
|
0
|
|
|
0
|
0
|
|
sub ua { shift->{useragent} } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub Cobalt_register { |
20
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
21
|
0
|
|
|
|
|
|
my $core = shift; |
22
|
0
|
|
|
|
|
|
my $conf = $core->get_plugin_cfg($self); |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
$self->{useragent} = Mojo::UserAgent->new; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
register( $self, 'SERVER', 'public_msg' ); |
27
|
0
|
|
|
|
|
|
logger->info("Registered"); |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
return PLUGIN_EAT_NONE; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub Cobalt_unregister { |
33
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
34
|
0
|
|
|
|
|
|
my $core = shift; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
logger->info("Unregistered"); |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
return PLUGIN_EAT_NONE; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub Bot_public_msg { |
42
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
43
|
0
|
|
|
|
|
|
my $core = shift; |
44
|
0
|
|
|
|
|
|
my $msg = ${ shift() }; |
|
0
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $context = $msg->context; |
47
|
0
|
|
|
|
|
|
my $channel = $msg->target; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
foreach my $uri ( list_uris($msg->message) ) { |
50
|
0
|
0
|
|
|
|
|
next if not $uri; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
my $text = $self->ua->get($uri)->result->dom->at('title')->text or next; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my @split = split /\n/, unidecode($text); # Remove unicode characters and split on newlines |
55
|
0
|
|
|
0
|
|
|
my $title = first { /\S/ } @split; # Grab first element with non-space characters |
|
0
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Remove leading and trailing whitespace |
58
|
0
|
|
|
|
|
|
$title =~ s/^\s+(.+)/$1/; |
59
|
0
|
|
|
|
|
|
$title =~ s/(.+)\s+$/$1/; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $resp = sprintf('[ %s ]', $title); |
62
|
0
|
|
|
|
|
|
broadcast( 'message', $context, $channel, $resp ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return PLUGIN_EAT_NONE; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |