--- trunk/irc-logger.pl 2006/03/12 13:33:20 12 +++ trunk/irc-logger.pl 2006/03/12 14:19:00 13 @@ -39,7 +39,8 @@ -use POE qw(Component::IRC Wheel::FollowTail); +use POE qw(Component::IRC Wheel::FollowTail Component::Server::HTTP); +use HTTP::Status; use DBI; use Encode qw/from_to/; @@ -77,6 +78,12 @@ my @messages = get_from_log( limit => 42, search => '%what to stuff in ilike%', + fmt => { + time => '{%s} ', + time_channel => '{%s %s} ', + nick => '%s: ', + message => '%s', + }, ); =cut @@ -86,6 +93,13 @@ $args->{limit} ||= 10; + $args->{fmt} ||= { + time => '{%s} ', + time_channel => '{%s %s} ', + nick => '%s: ', + message => '%s', + }; + my $sql = qq{ select time::date as date, @@ -130,18 +144,20 @@ my $msg = ''; - $msg .= "{$t"; - $msg .= ' ' . $row->{channel} if ($last_row->{channel} ne $row->{channel}); - $msg .= "} "; + if ($last_row->{channel} ne $row->{channel}) { + $msg .= sprintf($args->{fmt}->{time_channel}, $t, $row->{channel}); + } else { + $msg .= sprintf($args->{fmt}->{time}, $t); + } my $append = 1; if ($last_row->{nick} ne $row->{nick}) { - $msg .= $row->{nick} . ': '; + $msg .= sprintf($args->{fmt}->{nick}, $row->{nick}); $append = 0; } - $msg .= $row->{message}; + $msg .= sprintf($args->{fmt}->{message}, $row->{message}); if ($append && @msgs) { $msgs[$#msgs] .= " " . $msg; @@ -359,4 +375,41 @@ }, ); +# http server + +my $httpd = POE::Component::Server::HTTP->new( + Port => 8000, + ContentHandler => { '/' => \&root_handler }, + Headers => { Server => 'irc-logger' }, +); + +my $style = <<'_END_OF_STYLE_'; +.time, .channel { color: #808080; font-size: 60%; } +.nick { color: #0000ff; font-size: 80%; } +.message { color: #000000; font-size: 100%; } +_END_OF_STYLE_ + +sub root_handler { + my ($request, $response) = @_; + $response->code(RC_OK); + $response->content_type('text/html'); + $response->content( + qq{$NICK} . + "irc-logger url: " . $request->uri . '
' . + join("
", + get_from_log( + limit => 100, + fmt => { + time => '%s ', + time_channel => '%s %s ', + nick => '%s: ', + message => '%s', + }, + ) + ) . + qq{} + ); + return RC_OK; +} + POE::Kernel->run;