| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Bot::Cobalt::Plugin::SeenURL; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Bot::Cobalt plugin for detecting re-linked URLs |
|
3
|
|
|
|
|
|
|
$Bot::Cobalt::Plugin::SeenURL::VERSION = '0.003'; |
|
4
|
1
|
|
|
1
|
|
19584
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
34
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
25
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
344
|
use Bot::Cobalt; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Bot::Cobalt::Common; |
|
9
|
|
|
|
|
|
|
use Bot::Cobalt::DB; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use DateTime::Tiny; |
|
12
|
|
|
|
|
|
|
use File::Spec; |
|
13
|
|
|
|
|
|
|
use URI::Find::Simple qw(list_uris); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { bless {}, shift } |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub db { shift->{db} } |
|
18
|
|
|
|
|
|
|
sub allow_relink { shift->{allow_relink} } |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub linked { |
|
21
|
|
|
|
|
|
|
my $self = shift; |
|
22
|
|
|
|
|
|
|
my $url = shift; |
|
23
|
|
|
|
|
|
|
my $nick = shift; |
|
24
|
|
|
|
|
|
|
my $channel = shift; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $links; |
|
27
|
|
|
|
|
|
|
my $linked; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$self->db->dbopen; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
if ( $links = $self->db->get($url) ) { |
|
32
|
|
|
|
|
|
|
foreach my $link (@$links) { |
|
33
|
|
|
|
|
|
|
if ($link->{channel} eq $channel) { |
|
34
|
|
|
|
|
|
|
$linked = $link; |
|
35
|
|
|
|
|
|
|
last; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
if ( not defined $linked ) { |
|
41
|
|
|
|
|
|
|
my $link = { |
|
42
|
|
|
|
|
|
|
datetime => DateTime::Tiny->now->as_string, |
|
43
|
|
|
|
|
|
|
channel => $channel, |
|
44
|
|
|
|
|
|
|
nick => $nick, |
|
45
|
|
|
|
|
|
|
}; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
if ( defined $links ) { |
|
48
|
|
|
|
|
|
|
push @$links, $link; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
else { |
|
51
|
|
|
|
|
|
|
$links = [ $link ]; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
$self->db->put($url => $links); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$self->db->dbclose; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
return $linked; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub Cobalt_register { |
|
62
|
|
|
|
|
|
|
my $self = shift; |
|
63
|
|
|
|
|
|
|
my $core = shift; |
|
64
|
|
|
|
|
|
|
my $conf = $core->get_plugin_cfg($self); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$self->{allow_relink} = $conf->{allow_relink} // 1; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $dbfile = $conf->{dbfile} || 'seenurl.db'; |
|
69
|
|
|
|
|
|
|
my $db = File::Spec->catfile( $core->var, $dbfile ); |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$self->{db} = Bot::Cobalt::DB->new( File => $db ); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
register( $self, 'SERVER', 'public_msg' ); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
logger->info("Registered"); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
return PLUGIN_EAT_NONE; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub Cobalt_unregister { |
|
81
|
|
|
|
|
|
|
my $self = shift; |
|
82
|
|
|
|
|
|
|
my $core = shift; |
|
83
|
|
|
|
|
|
|
return PLUGIN_EAT_NONE; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub Bot_public_msg { |
|
87
|
|
|
|
|
|
|
my $self = shift; |
|
88
|
|
|
|
|
|
|
my $core = shift; |
|
89
|
|
|
|
|
|
|
my $msg = ${ shift() }; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $context = $msg->context; |
|
92
|
|
|
|
|
|
|
my $channel = $msg->target; |
|
93
|
|
|
|
|
|
|
my $nick = $msg->src_nick; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $relink = 0; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
foreach my $uri ( list_uris($msg->message) ) { |
|
98
|
|
|
|
|
|
|
next if not $uri; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
if ( my $link = $self->linked($uri, $nick, $channel) ) { |
|
101
|
|
|
|
|
|
|
if ( $nick eq $link->{nick} ) { |
|
102
|
|
|
|
|
|
|
$relink++; |
|
103
|
|
|
|
|
|
|
next if $self->allow_relink; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $dt = DateTime::Tiny->from_string($link->{datetime}); |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $resp = sprintf( |
|
109
|
|
|
|
|
|
|
"OLD! ( linked on %04d-%02d-%02d at %02d:%02d:%02d by %s )", |
|
110
|
|
|
|
|
|
|
$dt->year, $dt->month, $dt->day, |
|
111
|
|
|
|
|
|
|
$dt->hour, $dt->minute, $dt->second, |
|
112
|
|
|
|
|
|
|
$link->{nick}, |
|
113
|
|
|
|
|
|
|
); |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
broadcast( 'message', $context, $channel, $resp ); |
|
116
|
|
|
|
|
|
|
$relink++; |
|
117
|
|
|
|
|
|
|
next; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
return $relink ? PLUGIN_EAT_ALL : PLUGIN_EAT_NONE; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |