Bot::BasicBot::Pluggable::Module::SimpleBlog - A simple URL collector for Bot::BasicBot::Pluggable.
use Bot::BasicBot::Pluggable; use Bot::BasicBot::Pluggable::Module::SimpleBlog::Store::SQLite; my $bot = Bot::BasicBot::Pluggable->new( ... ); $bot->load( "SimpleBlog" ); my $blog_handler = $bot->handler( "SimpleBlog" ); $blog_handler->set_store( Bot::BasicBot::Pluggable::Module::SimpleBlog::Store::SQLite ->new( "/home/bot/brane.db" ) ); $blog_handler->set_blogurl( "http://example.com/simpleblog.cgi" ); $bot->run;
A plugin module for Bot::BasicBot::Pluggable to grab, store and output URLs from IRC channels. It is intentionally simplistic - see Bot::BasicBot::Pluggable::Module::Blog for a more complicated chump-like thing.
I'd made a thinko in version 0.01 in one of the column names in the table used to store the URLs in the database, so you'll have to delete your store file and start again. It didn't seem worth automatically detecting and fixing this since I only released 0.01 yesterday and I don't expect anyone to have installed it yet.
my $blog_store = Bot::BasicBot::Pluggable::Module::SimpleBlog::Store::SQLite->new( "/home/bot/brane.db" ); $blog_handler->set_store( $blog_store );
Supply a Bot::BasicBot::Pluggable::Module::SimpleBlog::Store::* object.
Bot::BasicBot::Pluggable::Module::SimpleBlog::Store::*
$blog_handler->set_blogurl( "http://example.com/simpleblog.cgi" );
Supply the URL for your CGI script to view the stored URLs.
use strict; use warnings; use Bot::BasicBot::Pluggable; my $bot = Bot::BasicBot::Pluggable->new(channels => [ "#test" ], server => "irc.example.com", port => "6667", nick => "bot", username => "bot", name => "bot", ); $bot->load( "SimpleBlog" ); my $blog_handler = $bot->handler( "SimpleBlog" ); $blog_handler->set_store( Bot::BasicBot::Pluggable::Module::SimpleBlog::Store::SQLite ->new( "/home/bot/brane.db" ) ); $blog_handler->set_blogurl( "http://example.com/simpleblog.cgi" ); $bot->run;
Yes, this is your entire program.
The file supplied as an argument to the constructor of Bot::BasicBot::Pluggable::Module::SimpleBlog::Store::SQLite need not already exist; it will be created and the correct database schema set up as necessary.
Talk to the bot on IRC for help:
17:37 <nou> kakebot: help SimpleBlog <kakebot> nou: Simple URL collector for Bot::BasicBot::Pluggable. Requires direct addressing. Usage: 'http://foo.com/ # the foo website'. The URLs can be viewed at http://example.com/simpleblog.cgi
Get stuff out of the database in your favoured fashion, for example:
use strict; use warnings; use CGI; use DBI; my $sqlite_db = "/home/bot/brane.db"; my $q = CGI->new; my $dbh = DBI->connect("dbi:SQLite:dbname=$sqlite_db", "", "") or die DBI->errstr; print $q->header; print <<EOF; <html> <head><title>simpleblogbot</title></head> <body><h1 align="center">simpleblogbot</h1> EOF my $sql = "SELECT timestamp, name, channel, url, comment FROM blogged ORDER BY timestamp DESC"; my $sth = $dbh->prepare($sql) or die $dbh->errstr; $sth->execute; my ($timestamp, $name, $channel, $url, $comment); while ( ($timestamp, $name, $channel, $url, $comment) = $sth->fetchrow_array ) { print "<br><i>$timestamp</i>: <b>$name/$channel</b>: "; print "<a href=\"$url\">$url</a> " if $url; print $q->escapeHTML($comment) if $comment; } print "</body></html>\n";
(This will just print everything ever; being more discriminating and adding prettiness is left as an exercise for people who don't hate writing CGI scripts.)
At some point there will be Bot::BasicBot::Pluggable::Module::Store::* methods for retrieving as well as storing the data. Probably.
Bot::BasicBot::Pluggable::Module::Store::*
Unstable API - Bot::BasicBot::Pluggable is liable to change and hence so is this.
More tests would be nice.
Bot::BasicBot::Pluggable
Bot::BasicBot::Pluggable::Module::Blog
Bot::BasicBot::Pluggable::Module::SimpleBlog::Store::SQLite
Kake Pugh (kake@earth.li).
Copyright (C) 2003 Kake Pugh. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Tom Insam, author of Bot::BasicBot::Pluggable, answered my dumb questions on how to get it working. Mark Fowler fixed my bad SQL, and told me off until I agreed to abstract out the storage and retrieval bits.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
To install Bot::BasicBot::Pluggable::Module::SimpleBlog, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Bot::BasicBot::Pluggable::Module::SimpleBlog
CPAN shell
perl -MCPAN -e shell install Bot::BasicBot::Pluggable::Module::SimpleBlog
For more information on module installation, please visit the detailed CPAN module installation guide.