--- trunk/irc-logger.pl 2006/06/25 16:37:39 36 +++ trunk/irc-logger.pl 2006/06/25 17:40:59 37 @@ -10,6 +10,14 @@ ./irc-logger.pl +=head2 Options + +=over 4 + +=item --import-dircproxy=filename + +Import log from C to C database + =head1 DESCRIPTION log all conversation on irc channel @@ -55,6 +63,13 @@ use HTML::TagCloud; use POSIX qw/strftime/; use HTML::CalendarMonthSimple; +use Getopt::Long; +use DateTime; + +my $import_dircproxy; +GetOptions( + 'import-dircproxy:s' => \$import_dircproxy, +); my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; @@ -85,8 +100,8 @@ my $sth = $dbh->prepare(qq{ insert into log - (channel, me, nick, message) -values (?,?,?,?) + (channel, me, nick, message, time) +values (?,?,?,?,?) }); my $tags; @@ -281,26 +296,131 @@ return @msgs; } +# tags support -my $SKIPPING = 0; # if skipping, how many we've done -my $SEND_QUEUE; # cache +my $cloud = HTML::TagCloud->new; + +=head2 add_tag + + add_tag( id => 42, message => 'irc message' ); + +=cut + +sub add_tag { + my $arg = {@_}; + + return unless ($arg->{id} && $arg->{message}); + + my $m = $arg->{message}; + from_to('UTF-8', 'iso-8859-2', $m) if (is_utf8($m)); + + while ($m =~ s#$tag_regex##s) { + my $tag = $1; + next if (! $tag || $tag =~ m/https?:/i); + push @{ $tags->{$tag} }, $arg->{id}; + #warn "+tag $tag: $arg->{id}\n"; + $cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1); + } +} + +=head2 seed_tags + +Read all tags from database and create in-memory cache for tags + +=cut + +sub seed_tags { + my $sth = $dbh->prepare(qq{ select id,message from log where message like '%//%' }); + $sth->execute; + while (my $row = $sth->fetchrow_hashref) { + add_tag( %$row ); + } + + foreach my $tag (keys %$tags) { + $cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1); + } +} + +seed_tags; -POE::Component::IRC->new($IRC_ALIAS); =head2 save_message - save_message($channel,$me,$nick,$msg); + save_message( + channel => '#foobar', + me => 0, + nick => 'dpavlin', + msg => 'test message', + time => '2006-06-25 18:57:18', + ); + +C