line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::BasicBot::Pluggable::Module::Delicious; |
2
|
1
|
|
|
1
|
|
30551
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
115
|
|
5
|
1
|
|
|
1
|
|
5
|
use vars qw( $VERSION ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
74
|
|
6
|
|
|
|
|
|
|
$VERSION = '0.011'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
547
|
use Bot::BasicBot::Pluggable::Module; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use base qw(Bot::BasicBot::Pluggable::Module); |
10
|
|
|
|
|
|
|
use Net::Delicious; |
11
|
|
|
|
|
|
|
use Regexp::Common 'RE_URI'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Bot::BasicBot::Pluggable::Module::Delicious - A Simple URL catcher for Bot::BasciBot::Pluggable |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Bot::BasicBot::Pluggable::Module::Delicious |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $bot = Bot::BasicBot::Pluggable->new(...); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$bot->load("Delicious"); |
24
|
|
|
|
|
|
|
my $delicious_handler = $bot->handler("Delicious"); |
25
|
|
|
|
|
|
|
$delicious_handler->set($url, $user, $pswd); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
A plugin module for L to grab, and store URLs from |
30
|
|
|
|
|
|
|
and IRC channel to a delicious account. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 USAGE |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 BUGS |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 SUPPORT |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 AUTHOR |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Franck Cuny |
44
|
|
|
|
|
|
|
CPAN ID: FRANCKC |
45
|
|
|
|
|
|
|
tirnanog |
46
|
|
|
|
|
|
|
franck@breizhdev.net |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 COPYRIGHT |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This program is free software; you can redistribute |
51
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
The full text of the license can be found in the |
54
|
|
|
|
|
|
|
LICENSE file included with this module. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SEE ALSO |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=over 4 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item * L |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item * L |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=back |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub init { |
70
|
|
|
|
|
|
|
my $self = shift; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub said { |
74
|
|
|
|
|
|
|
my ($self, $mess, $pri) = @_; |
75
|
|
|
|
|
|
|
my ($url, $tags, @url); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
return unless $pri == 2; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$self->{body} = $mess->{body}; |
80
|
|
|
|
|
|
|
$self->{who} = $mess->{who}; |
81
|
|
|
|
|
|
|
$self->{channel} = $mess->{channel}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
if ($self->{body} =~ /^!addurl/) { |
84
|
|
|
|
|
|
|
$self->find_url_and_tags($self->{body}); |
85
|
|
|
|
|
|
|
} elsif ( $self->{body} =~ /^!tag\s([^\s]+)\s?(\d+)?$/) { |
86
|
|
|
|
|
|
|
$self->search_tags($1, $2); |
87
|
|
|
|
|
|
|
} else { |
88
|
|
|
|
|
|
|
$self->find_url($self->{body}); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub help { |
93
|
|
|
|
|
|
|
my ($self) = @_; |
94
|
|
|
|
|
|
|
my $mess; |
95
|
|
|
|
|
|
|
$mess = "I find url(s) in text and add them to the delicious account(".$self->{delicious_url}.")\n"; |
96
|
|
|
|
|
|
|
$mess .=": !addurl url tag1 tag2\n"; |
97
|
|
|
|
|
|
|
$mess .=": !tag tagname\n"; |
98
|
|
|
|
|
|
|
$mess .=": I can catch url on the fly, if they are followed by a ([tag]) I add a tag, if there is a nolog I don't log the url\n"; |
99
|
|
|
|
|
|
|
return $mess; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub search_tags{ |
103
|
|
|
|
|
|
|
my ($self, $tag, $limit) = @_; |
104
|
|
|
|
|
|
|
$limit = ($limit && $limit < 10) ? $limit : 5; |
105
|
|
|
|
|
|
|
foreach my $post ($self->{delicious}->recent_posts({ |
106
|
|
|
|
|
|
|
tag => $tag, |
107
|
|
|
|
|
|
|
count => $limit, |
108
|
|
|
|
|
|
|
})){ |
109
|
|
|
|
|
|
|
$self->tell($self->{channel}, $self->{who}.": ".$post); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
sleep 1; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub find_url_and_tags { |
115
|
|
|
|
|
|
|
my ($self, $body) = @_; |
116
|
|
|
|
|
|
|
my $url_re = RE_URI; |
117
|
|
|
|
|
|
|
$body =~ s/^!addurl\s//; |
118
|
|
|
|
|
|
|
my ($url, $tags) = split " ", $body, 2; |
119
|
|
|
|
|
|
|
if ($url =~ /($url_re)/) { |
120
|
|
|
|
|
|
|
$self->add_to_delicious($1, $tags); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub find_url { |
125
|
|
|
|
|
|
|
my ($self, $body) = @_; |
126
|
|
|
|
|
|
|
my $url_re = RE_URI; |
127
|
|
|
|
|
|
|
my @url; |
128
|
|
|
|
|
|
|
while ($body =~ /($url_re)/g) { |
129
|
|
|
|
|
|
|
my $url = $1; |
130
|
|
|
|
|
|
|
return if ($body =~ /nolog/); |
131
|
|
|
|
|
|
|
if ($body =~ /(?:\[|\()(.*)(?:\]|\))/) { |
132
|
|
|
|
|
|
|
my $tags = $1; |
133
|
|
|
|
|
|
|
$self->add_to_delicious($url, $tags); |
134
|
|
|
|
|
|
|
} else { |
135
|
|
|
|
|
|
|
$self->add_to_delicious($url); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub add_to_delicious { |
141
|
|
|
|
|
|
|
my ($self, $url , $tags) = @_; |
142
|
|
|
|
|
|
|
warn "on a $url et $tags"; |
143
|
|
|
|
|
|
|
$tags = "fromirc" unless $tags; |
144
|
|
|
|
|
|
|
$self->{delicious}->add_post({ |
145
|
|
|
|
|
|
|
url => $url, |
146
|
|
|
|
|
|
|
tags => $tags." by_".$self->{who}, |
147
|
|
|
|
|
|
|
description => $url, |
148
|
|
|
|
|
|
|
}); |
149
|
|
|
|
|
|
|
sleep 1; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub set { |
153
|
|
|
|
|
|
|
my ($self, $delicious_url, $user, $pswd) = @_; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
croak "Error: no delicious url specified" unless $delicious_url; |
156
|
|
|
|
|
|
|
croak "Error: no delicious user specied" unless $user; |
157
|
|
|
|
|
|
|
croak "Error: no delicious password specied" unless $pswd; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
$self->{delicious_url} = $delicious_url; |
160
|
|
|
|
|
|
|
$self->{delicious} = Net::Delicious->new({ |
161
|
|
|
|
|
|
|
user => $user, |
162
|
|
|
|
|
|
|
pswd => $pswd, |
163
|
|
|
|
|
|
|
debug=> 1, |
164
|
|
|
|
|
|
|
}); |
165
|
|
|
|
|
|
|
return $self; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
1; |