/[irc-logger]/trunk/bin/irc-logger.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/bin/irc-logger.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 28 by dpavlin, Fri Jun 16 20:51:32 2006 UTC revision 33 by dpavlin, Sat Jun 24 22:15:47 2006 UTC
# Line 18  log all conversation on irc channel Line 18  log all conversation on irc channel
18    
19  ## CONFIG  ## CONFIG
20    
21  my $NICK = 'irc-logger-dev';  my $HOSTNAME = `hostname`;
22    
23    my $NICK = 'irc-logger';
24    $NICK .= '-dev' if ($HOSTNAME =~ m/llin/);
25  my $CONNECT =  my $CONNECT =
26    {Server => 'irc.freenode.net',    {Server => 'irc.freenode.net',
27     Nick => $NICK,     Nick => $NICK,
28     Ircname => "try /msg $NICK help",     Ircname => "try /msg $NICK help",
29    };    };
30  my $CHANNEL = '#razmjenavjestina';  my $CHANNEL = '#razmjenavjestina';
31    $CHANNEL = '#irc-logger' if ($HOSTNAME =~ m/llin/);
32  my $IRC_ALIAS = "log";  my $IRC_ALIAS = "log";
33    
34  my %FOLLOWS =  my %FOLLOWS =
# Line 44  my $ENCODING = 'ISO-8859-2'; Line 48  my $ENCODING = 'ISO-8859-2';
48  use POE qw(Component::IRC Wheel::FollowTail Component::Server::HTTP);  use POE qw(Component::IRC Wheel::FollowTail Component::Server::HTTP);
49  use HTTP::Status;  use HTTP::Status;
50  use DBI;  use DBI;
51  use Encode qw/from_to/;  use Encode qw/from_to is_utf8/;
52  use Regexp::Common qw /URI/;  use Regexp::Common qw /URI/;
53  use CGI::Simple;  use CGI::Simple;
54  use HTML::TagCloud;  use HTML::TagCloud;
# Line 83  values (?,?,?,?) Line 87  values (?,?,?,?)
87  });  });
88    
89  my $tags;  my $tags;
90    my $tag_regex = '\b([\w-_]+)//';
91    
92  =head2 get_from_log  =head2 get_from_log
93    
# Line 290  POE::Session->create Line 295  POE::Session->create
295    
296                  print "$channel: <$nick> $msg\n";                  print "$channel: <$nick> $msg\n";
297                  $sth->execute($channel, 0, $nick, $msg);                  $sth->execute($channel, 0, $nick, $msg);
298                    add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef),
299                            message => $msg);
300      },      },
301      irc_ctcp_action => sub {      irc_ctcp_action => sub {
302                  my $kernel = $_[KERNEL];                  my $kernel = $_[KERNEL];
# Line 301  POE::Session->create Line 308  POE::Session->create
308    
309                  print "$channel ***$nick $msg\n";                  print "$channel ***$nick $msg\n";
310                  $sth->execute($channel, 1, $nick, $msg);                  $sth->execute($channel, 1, $nick, $msg);
311                    add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef),
312                            message => $msg);
313      },      },
314          irc_msg => sub {          irc_msg => sub {
315                  my $kernel = $_[KERNEL];                  my $kernel = $_[KERNEL];
# Line 494  sub add_tag { Line 503  sub add_tag {
503    
504          return unless ($arg->{id} && $arg->{message});          return unless ($arg->{id} && $arg->{message});
505    
506          while ($arg->{message} =~ s#\b(\S+)//##s) {          my $m = $arg->{message};
507            from_to('UTF-8', 'iso-8859-2', $m) if (is_utf8($m));
508    
509            while ($m =~ s#$tag_regex##s) {
510                  my $tag = $1;                  my $tag = $1;
511                  next if (! $tag || $tag =~ m/https?:/i);                  next if (! $tag || $tag =~ m/https?:/i);
512                  push @{ $tags->{$tag} }, $arg->{id};                  push @{ $tags->{$tag} }, $arg->{id};
513                    #warn "+tag $tag: $arg->{id}\n";
514                    $cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1);
515          }          }
516  }  }
517    
# Line 544  p { margin: 0; padding: 0.1em; } Line 558  p { margin: 0; padding: 0.1em; }
558  .col-2 { background: #99ff99 }  .col-2 { background: #99ff99 }
559  .col-3 { background: #ff9999 }  .col-3 { background: #ff9999 }
560  .col-4 { background: #ff66ff }  .col-4 { background: #ff66ff }
561    a:link.tag, a:visited.tag { border: 1px dashed #ccc; backgound: #ccc; text-decoration: none }
562    a:hover.tag { border: 1px solid #eee }
563  _END_OF_STYLE_  _END_OF_STYLE_
564    
565  my $max_color = 4;  my $max_color = 4;
# Line 572  sub root_handler { Line 588  sub root_handler {
588                  $cloud->css .                  $cloud->css .
589                  qq{</style></head><body>} .                  qq{</style></head><body>} .
590                  qq{                  qq{
591                  <form method="post" class="search">                  <form method="post" class="search" action="/">
592                  <input type="text" name="search" value="$search" size="10">                  <input type="text" name="search" value="$search" size="10">
593                  <input type="submit" value="search">                  <input type="submit" value="search">
594                  </form>                  </form>
595                  } .                  } .
596                  qq{<div>} . $cloud->html(500) . qq{</div>} .                  $cloud->html(500) .
597                  qq{<p>} .                  qq{<p>} .
598                  join("</p><p>",                  join("</p><p>",
599                          get_from_log(                          get_from_log(
600                                  limit => $q->param('last') || 100,                                  limit => $q->param('last') || 100,
601                                  search => $search || undef,                                  search => $search || undef,
602                                  tag => $q->param('tag'),                                  tag => $q->param('tag') || undef,
603                                  fmt => {                                  fmt => {
604                                          date => '<hr size="1" style="clear: both;"/><div class="date">%s</div> ',                                          date => '<hr size="1" style="clear: both;"/><div class="date">%s</div> ',
605                                          time => '<span class="time">%s</span> ',                                          time => '<span class="time">%s</span> ',
# Line 597  sub root_handler { Line 613  sub root_handler {
613                                                  my $m = shift || return;                                                  my $m = shift || return;
614                                                  $m =~ s/($escape_re)/$escape{$1}/gs;                                                  $m =~ s/($escape_re)/$escape{$1}/gs;
615                                                  $m =~ s#($RE{URI}{HTTP})#<a href="$1">$1</a>#gs;                                                  $m =~ s#($RE{URI}{HTTP})#<a href="$1">$1</a>#gs;
616                                                    $m =~ s#$tag_regex#<a href="?tag=$1" class="tag">$1</a>#g;
617                                                  return $m;                                                  return $m;
618                                          },                                          },
619                                          nick => sub {                                          nick => sub {

Legend:
Removed from v.28  
changed lines
  Added in v.33

  ViewVC Help
Powered by ViewVC 1.1.26