line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::BasicBot::Pluggable::Module::SimpleBlog; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
709
|
use strict; |
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
|
1
|
|
|
|
|
39469
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
5
|
use vars qw( $VERSION ); |
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
60
|
|
5
|
|
|
|
|
|
|
$VERSION = '0.03'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use base qw(Bot::BasicBot::Pluggable::Module::Base); |
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
|
|
456
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
269
|
use Carp; |
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
64
|
|
10
|
1
|
|
|
1
|
|
5
|
use Regexp::Common 'RE_URI'; |
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
11
|
1
|
|
|
1
|
|
1038
|
use Time::Piece; |
|
1
|
|
|
1
|
|
7239
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
683
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Bot::BasicBot::Pluggable::Module::SimpleBlog - A simple URL collector for Bot::BasicBot::Pluggable. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Bot::BasicBot::Pluggable; |
20
|
|
|
|
|
|
|
use Bot::BasicBot::Pluggable::Module::SimpleBlog::Store::SQLite; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $bot = Bot::BasicBot::Pluggable->new( ... ); |
23
|
|
|
|
|
|
|
$bot->load( "SimpleBlog" ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $blog_handler = $bot->handler( "SimpleBlog" ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$blog_handler->set_store( |
28
|
|
|
|
|
|
|
Bot::BasicBot::Pluggable::Module::SimpleBlog::Store::SQLite |
29
|
|
|
|
|
|
|
->new( "/home/bot/brane.db" ) |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$blog_handler->set_blogurl( "http://example.com/simpleblog.cgi" ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$bot->run; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 DESCRIPTION |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
A plugin module for L<Bot::BasicBot::Pluggable> to grab, store and |
39
|
|
|
|
|
|
|
output URLs from IRC channels. It is intentionally simplistic - see |
40
|
|
|
|
|
|
|
L<Bot::BasicBot::Pluggable::Module::Blog> for a more complicated |
41
|
|
|
|
|
|
|
chump-like thing. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 IMPORTANT NOTE WHEN UPGRADING FROM PRE-0.02 VERSIONS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
I'd made a thinko in version 0.01 in one of the column names in the |
46
|
|
|
|
|
|
|
table used to store the URLs in the database, so you'll have to delete |
47
|
|
|
|
|
|
|
your store file and start again. It didn't seem worth automatically |
48
|
|
|
|
|
|
|
detecting and fixing this since I only released 0.01 yesterday and I |
49
|
|
|
|
|
|
|
don't expect anyone to have installed it yet. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 METHODS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=over 4 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub help { |
58
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
59
|
0
|
|
|
|
|
0
|
my $helptext = "Simple URL collector for Bot::BasicBot::Pluggable. Requires direct addressing. Usage: 'http://foo.com/ # the foo website'."; |
60
|
0
|
|
|
|
|
0
|
my $blogurl = $self->{blogurl}; |
61
|
0
|
0
|
|
|
|
0
|
$helptext .= " The URLs can be viewed at $blogurl" if $blogurl; |
62
|
0
|
|
|
|
|
0
|
return $helptext; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub said { |
66
|
0
|
|
|
0
|
1
|
0
|
my ($self, $mess, $pri) = @_; |
67
|
0
|
0
|
0
|
|
|
0
|
return unless $mess->{address} and $pri == 2; # require direct addressing |
68
|
|
|
|
|
|
|
my $store = $self->{store} |
69
|
0
|
0
|
|
|
|
0
|
or return "Error: no store configured."; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
0
|
my $body = $mess->{body}; |
72
|
0
|
|
|
|
|
0
|
my $who = $mess->{who}; |
73
|
0
|
|
|
|
|
0
|
my $channel = $mess->{channel}; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
my ($url, $comment) = split(/\s+\#*\s*/, $body, 2); |
76
|
0
|
|
0
|
|
|
0
|
$comment ||= ""; |
77
|
0
|
|
|
|
|
0
|
my $url_re = RE_URI; |
78
|
0
|
0
|
|
|
|
0
|
unless ( $url =~ /^$url_re$/ ) { |
79
|
0
|
|
|
|
|
0
|
($url, $comment) = ("", $body); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
0
|
my $now = localtime; |
83
|
0
|
|
|
|
|
0
|
my $timestamp = $now->strftime("%Y-%m-%d %H:%M:%S"); |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
0
|
$store->store( timestamp => $timestamp, |
86
|
|
|
|
|
|
|
name => $who, |
87
|
|
|
|
|
|
|
channel => $channel, |
88
|
|
|
|
|
|
|
url => $url, |
89
|
|
|
|
|
|
|
comment => $comment ); |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
0
|
$self->{Bot}->say( who => $who, |
92
|
|
|
|
|
|
|
channel => "msg", |
93
|
|
|
|
|
|
|
body => "Stored URL '$url'" |
94
|
|
|
|
|
|
|
. ($comment ? " and comment '$comment'" : "" ) |
95
|
|
|
|
|
|
|
); |
96
|
0
|
|
|
|
|
0
|
return; # nice quiet bot |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item B<set_store> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $blog_store = |
102
|
|
|
|
|
|
|
Bot::BasicBot::Pluggable::Module::SimpleBlog::Store::SQLite->new( |
103
|
|
|
|
|
|
|
"/home/bot/brane.db" ); |
104
|
|
|
|
|
|
|
$blog_handler->set_store( $blog_store ); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Supply a C<Bot::BasicBot::Pluggable::Module::SimpleBlog::Store::*> object. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub set_store { |
111
|
1
|
|
|
1
|
1
|
3
|
my ($self, $store) = @_; |
112
|
1
|
50
|
|
|
|
4
|
croak "ERROR: No store specified" unless $store; |
113
|
|
|
|
|
|
|
|
114
|
1
|
|
|
|
|
3
|
$self->{store} = $store; |
115
|
1
|
|
|
|
|
3
|
return $self; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item B<set_blogurl> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$blog_handler->set_blogurl( "http://example.com/simpleblog.cgi" ); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Supply the URL for your CGI script to view the stored URLs. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub set_blogurl { |
127
|
0
|
|
|
0
|
1
|
|
my ($self, $blogurl) = @_; |
128
|
0
|
0
|
|
|
|
|
croak "ERROR: No blogurl specified" unless $blogurl; |
129
|
0
|
|
|
|
|
|
$self->{blogurl} = $blogurl; |
130
|
0
|
|
|
|
|
|
return $self; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 EXAMPLES |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
use strict; |
136
|
|
|
|
|
|
|
use warnings; |
137
|
|
|
|
|
|
|
use Bot::BasicBot::Pluggable; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
my $bot = Bot::BasicBot::Pluggable->new(channels => [ "#test" ], |
140
|
|
|
|
|
|
|
server => "irc.example.com", |
141
|
|
|
|
|
|
|
port => "6667", |
142
|
|
|
|
|
|
|
nick => "bot", |
143
|
|
|
|
|
|
|
username => "bot", |
144
|
|
|
|
|
|
|
name => "bot", |
145
|
|
|
|
|
|
|
); |
146
|
|
|
|
|
|
|
$bot->load( "SimpleBlog" ); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
my $blog_handler = $bot->handler( "SimpleBlog" ); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
$blog_handler->set_store( |
151
|
|
|
|
|
|
|
Bot::BasicBot::Pluggable::Module::SimpleBlog::Store::SQLite |
152
|
|
|
|
|
|
|
->new( "/home/bot/brane.db" ) |
153
|
|
|
|
|
|
|
); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
$blog_handler->set_blogurl( "http://example.com/simpleblog.cgi" ); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
$bot->run; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Yes, this is your entire program. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
The file supplied as an argument to the constructor of |
162
|
|
|
|
|
|
|
L<Bot::BasicBot::Pluggable::Module::SimpleBlog::Store::SQLite> need |
163
|
|
|
|
|
|
|
not already exist; it will be created and the correct database schema |
164
|
|
|
|
|
|
|
set up as necessary. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Talk to the bot on IRC for help: |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
17:37 <nou> kakebot: help SimpleBlog |
169
|
|
|
|
|
|
|
<kakebot> nou: Simple URL collector for Bot::BasicBot::Pluggable. |
170
|
|
|
|
|
|
|
Requires direct addressing. Usage: |
171
|
|
|
|
|
|
|
'http://foo.com/ # the foo website'. The URLs can be viewed at |
172
|
|
|
|
|
|
|
http://example.com/simpleblog.cgi |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Get stuff out of the database in your favoured fashion, for example: |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
use strict; |
177
|
|
|
|
|
|
|
use warnings; |
178
|
|
|
|
|
|
|
use CGI; |
179
|
|
|
|
|
|
|
use DBI; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
my $sqlite_db = "/home/bot/brane.db"; |
182
|
|
|
|
|
|
|
my $q = CGI->new; |
183
|
|
|
|
|
|
|
my $dbh = DBI->connect("dbi:SQLite:dbname=$sqlite_db", "", "") |
184
|
|
|
|
|
|
|
or die DBI->errstr; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
print $q->header; |
187
|
|
|
|
|
|
|
print <<EOF; |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
<html> |
190
|
|
|
|
|
|
|
<head><title>simpleblogbot</title></head> |
191
|
|
|
|
|
|
|
<body><h1 align="center">simpleblogbot</h1> |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
EOF |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
my $sql = "SELECT timestamp, name, channel, url, comment FROM blogged |
196
|
|
|
|
|
|
|
ORDER BY timestamp DESC"; |
197
|
|
|
|
|
|
|
my $sth = $dbh->prepare($sql) or die $dbh->errstr; |
198
|
|
|
|
|
|
|
$sth->execute; |
199
|
|
|
|
|
|
|
my ($timestamp, $name, $channel, $url, $comment); |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
while ( ($timestamp, $name, $channel, $url, $comment) |
202
|
|
|
|
|
|
|
= $sth->fetchrow_array ) { |
203
|
|
|
|
|
|
|
print "<br><i>$timestamp</i>: <b>$name/$channel</b>: "; |
204
|
|
|
|
|
|
|
print "<a href=\"$url\">$url</a> " if $url; |
205
|
|
|
|
|
|
|
print $q->escapeHTML($comment) if $comment; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
print "</body></html>\n"; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
(This will just print everything ever; being more discriminating and |
211
|
|
|
|
|
|
|
adding prettiness is left as an exercise for people who don't hate |
212
|
|
|
|
|
|
|
writing CGI scripts.) |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
At some point there will be |
215
|
|
|
|
|
|
|
C<Bot::BasicBot::Pluggable::Module::Store::*> methods for retrieving |
216
|
|
|
|
|
|
|
as well as storing the data. Probably. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 WARNING |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Unstable API - L<Bot::BasicBot::Pluggable> is liable to change and |
221
|
|
|
|
|
|
|
hence so is this. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 BUGS |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
More tests would be nice. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 SEE ALSO |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=over 4 |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item * L<Bot::BasicBot::Pluggable> |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=item * L<Bot::BasicBot::Pluggable::Module::Blog> |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=item * L<Bot::BasicBot::Pluggable::Module::SimpleBlog::Store::SQLite> |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=back |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 AUTHOR |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Kake Pugh (kake@earth.li). |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head1 COPYRIGHT |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Copyright (C) 2003 Kake Pugh. All Rights Reserved. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it |
248
|
|
|
|
|
|
|
under the same terms as Perl itself. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head1 CREDITS |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Tom Insam, author of L<Bot::BasicBot::Pluggable>, answered my dumb |
253
|
|
|
|
|
|
|
questions on how to get it working. Mark Fowler fixed my bad SQL, and |
254
|
|
|
|
|
|
|
told me off until I agreed to abstract out the storage and retrieval bits. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=cut |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
1; |