Bot::BasicBot::Pluggable::Module::SimpleBlog - A simple URL collector for Bot::BasicBot::Pluggable.


Bot-BasicBot-Pluggable-Module-SimpleBlog documentation  | view source Contained in the Bot-BasicBot-Pluggable-Module-SimpleBlog distribution.

Index


NAME

Top

Bot::BasicBot::Pluggable::Module::SimpleBlog - A simple URL collector for Bot::BasicBot::Pluggable.

SYNOPSIS

Top

  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;

DESCRIPTION

Top

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.

IMPORTANT NOTE WHEN UPGRADING FROM PRE-0.02 VERSIONS

Top

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.

METHODS

Top

set_store
  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.

set_blogurl
  $blog_handler->set_blogurl( "http://example.com/simpleblog.cgi" );

Supply the URL for your CGI script to view the stored URLs.

EXAMPLES

Top

  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.

WARNING

Top

Unstable API - Bot::BasicBot::Pluggable is liable to change and hence so is this.

BUGS

Top

More tests would be nice.

SEE ALSO

Top

* Bot::BasicBot::Pluggable
* Bot::BasicBot::Pluggable::Module::Blog
* Bot::BasicBot::Pluggable::Module::SimpleBlog::Store::SQLite

AUTHOR

Top

Kake Pugh (kake@earth.li).

COPYRIGHT

Top

CREDITS

Top

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.


Bot-BasicBot-Pluggable-Module-SimpleBlog documentation  | view source Contained in the Bot-BasicBot-Pluggable-Module-SimpleBlog distribution.