--- trunk/irc-logger.pl 2006/02/27 11:54:38 4 +++ trunk/irc-logger.pl 2006/02/27 12:10:07 5 @@ -2,6 +2,20 @@ use strict; $|++; +=head1 NAME + +irc-logger.pl + +=head1 SYNOPSIS + +./irc-logger.pl + +=head1 DESCRIPTION + +log all conversation on irc channel + +=cut + ## CONFIG my $NICK = 'irc-logger'; @@ -19,12 +33,47 @@ ERROR => "/var/log/apache/error.log", ); +my $DSN = 'DBI:Pg:dbname=irc-logger'; + ## END CONFIG -my $SKIPPING = 0; # if skipping, how many we've done -my $SEND_QUEUE; # cache + use POE qw(Component::IRC Wheel::FollowTail); +use DBI; + + +my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; + +=for SQL schema + +$dbh->do(qq{ +create table log ( + id serial, + time timestamp default now(), + channel text not null, + nick text not null, + message text not null, + primary key(id) +); + +create index log_time on log(time); +create index log_channel on log(channel); +create index log_nick on log(nick); + +}); + +=cut + +my $sth = $dbh->prepare(qq{ +insert into log + (channel, nick, message) +values (?,?,?) +}); + + +my $SKIPPING = 0; # if skipping, how many we've done +my $SEND_QUEUE; # cache POE::Component::IRC->new($IRC_ALIAS); @@ -47,6 +96,7 @@ my $msg = $_[ARG2]; print "$channel: <$nick> $msg\n"; + $sth->execute($channel, $nick, $msg); }, (map { @@ -56,7 +106,9 @@ connected snotice ctcp_action ping notice mode part quit 001 002 003 004 005 250 251 252 253 254 265 266 - 332 333 353 366 372 375 376)), + 332 333 353 366 372 375 376 + 477 + )), _child => sub {}, _default => sub { printf "%s: session %s caught an unhandled %s event.\n",