/[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 50 by dpavlin, Sun Mar 18 15:37:05 2007 UTC revision 65 by dpavlin, Fri Jun 8 12:17:35 2007 UTC
# Line 73  use POSIX qw/strftime/; Line 73  use POSIX qw/strftime/;
73  use HTML::CalendarMonthSimple;  use HTML::CalendarMonthSimple;
74  use Getopt::Long;  use Getopt::Long;
75  use DateTime;  use DateTime;
76    use URI::Escape;
77  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
78    use DateTime::Format::ISO8601;
79    
80    my $use_twitter = 1;
81    eval { require Net::Twitter; };
82    $use_twitter = 0 if ($@);
83    
84  my $import_dircproxy;  my $import_dircproxy;
85  my $log_path;  my $log_path;
# Line 256  sub get_from_log { Line 262  sub get_from_log {
262    
263          $sql .= " where message ilike ? or nick ilike ? " if ($args->{search});          $sql .= " where message ilike ? or nick ilike ? " if ($args->{search});
264          $sql .= " where id in (" . join(",", @{ $tags->{ $args->{tag} } }) . ") " if ($args->{tag} && $tags->{ $args->{tag} });          $sql .= " where id in (" . join(",", @{ $tags->{ $args->{tag} } }) . ") " if ($args->{tag} && $tags->{ $args->{tag} });
265          $sql .= " where date(time) = ? " if ($args->{date});          if ($args->{date}) {
266                    my $date = eval { DateTime::Format::ISO8601->parse_datetime( $args->{date} )->ymd; };
267                    if ( $@ ) {
268                            warn "invalid date ", $args->{date}, $/;
269                            $date = DateTime->now->ymd;
270                    }
271                    $sql .= " where date(time) = ? ";
272                    $args->{date} = $date;
273            }
274          $sql .= " order by log.time desc";          $sql .= " order by log.time desc";
275          $sql .= " limit " . $args->{limit} if ($args->{limit});          $sql .= " limit " . $args->{limit} if ($args->{limit});
276    
# Line 545  POE::Session->create( inline_states => Line 559  POE::Session->create( inline_states =>
559    
560                  save_message( channel => $channel, me => 1, nick => $nick, msg => $msg);                  save_message( channel => $channel, me => 1, nick => $nick, msg => $msg);
561    
562                  if ( my $twitter = ( $nick, $channel, 'twitter' ) ) {                  if ( $use_twitter ) {
563                          _log("FIXME: send twitter for $nick on $channel [$twitter]");                          if ( my $twitter = meta( $nick, $NICK, 'twitter' ) ) {
564                                    my ($login,$passwd) = split(/\s+/,$twitter,2);
565                                    _log("sending twitter for $nick/$login on $channel ");
566                                    my $bot = Net::Twitter->new( username=>$login, password=>$passwd );
567                                    $bot->update("<${channel}> $msg");
568                            }
569                  }                  }
570    
571      },      },
# Line 593  POE::Session->create( inline_states => Line 612  POE::Session->create( inline_states =>
612    
613                          my $sth = $dbh->prepare(qq{                          my $sth = $dbh->prepare(qq{
614                                  select                                  select
615                                          nick,                                          trim(both '_' from nick) as nick,
616                                          count(*) as count,                                          count(*) as count,
617                                          sum(length(message)) as len                                          sum(length(message)) as len
618                                  from log                                  from log
619                                  group by nick                                  group by trim(both '_' from nick)
620                                  order by len desc,count desc                                  order by len desc,count desc
621                                  limit $nr                                  limit $nr
622                          });                          });
# Line 669  POE::Session->create( inline_states => Line 688  POE::Session->create( inline_states =>
688    
689                  } elsif ($msg =~ m/^ping/) {                  } elsif ($msg =~ m/^ping/) {
690                          $res = "ping = " . dump( $ping );                          $res = "ping = " . dump( $ping );
691                  } elsif ($msg =~ m/^(?:twitter)\s+(\S+)\s+(.*?)/) {                  } elsif ($msg =~ m/^conf(?:ig)*\s*(last-size|twitter)*\s*(.*)/) {
                         if ( defined( $2 ) ) {  
                                 meta($nick, $channel, 'twitter', "$1\t$2");  
                                 $res = "saved twitter auth for $1 -- /me on $channel will auto-update twitter status";  
                         } else {  
                                 meta($nick, $channel, 'twitter', '' );  
                                 $res = "removed twitter status update for /me on $channel";  
                         }  
                 } elsif ($msg =~ m/^conf(?:ig)*\s*(last-size)*\s*(\d*)/) {  
692                          if ( ! defined( $1 ) ) {                          if ( ! defined( $1 ) ) {
693                                  my $sth = $dbh->prepare(qq{ select name,value,changed from meta where nick = ? and channel = ? });                                  my $sth = $dbh->prepare(qq{ select name,value,changed from meta where nick = ? and channel = ? });
694                                  $sth->execute( $nick, $channel );                                  $sth->execute( $nick, $channel );
695                                  $res = "config for $nick ";                                  $res = "config for $nick on $channel";
696                                  while ( my ($n,$v) = $sth->fetchrow_array ) {                                  while ( my ($n,$v) = $sth->fetchrow_array ) {
697                                          $res .= "| $n = $v";                                          $res .= " | $n = $v";
698                                  }                                  }
699                          } elsif ( defined( $2 ) ) {                          } elsif ( ! $2 ) {
                                 meta( $nick, $channel, $1, $2 );  
                                 $res = "saved $1 = $2";  
                         } else {  
700                                  my $val = meta( $nick, $channel, $1 );                                  my $val = meta( $nick, $channel, $1 );
701                                  $res = "current $1 = " . ( $val ? $val : 'undefined' );                                  $res = "current $1 = " . ( $val ? $val : 'undefined' );
702                            } else {
703                                    my $validate = {
704                                            'last-size' => qr/^\d+/,
705                                            'twitter' => qr/^\w+\s+\w+/,
706                                    };
707    
708                                    my ( $op, $val ) = ( $1, $2 );
709    
710                                    if ( my $regex = $validate->{$op} ) {
711                                            if ( $val =~ $regex ) {
712                                                    meta( $nick, $channel, $op, $val );
713                                                    $res = "saved $op = $val";
714                                            } else {
715                                                    $res = "config option $op = $val doesn't validate against $regex";
716                                            }
717                                    } else {
718                                            $res = "config option $op doesn't exist";
719                                    }
720                          }                          }
721                  }                  }
722    
# Line 819  p { margin: 0; padding: 0.1em; } Line 845  p { margin: 0; padding: 0.1em; }
845  .nick { color: #000000; font-size: 80%; padding: 2px; font-family: courier, courier new, monospace ; }  .nick { color: #000000; font-size: 80%; padding: 2px; font-family: courier, courier new, monospace ; }
846  .message { color: #000000; font-size: 100%; }  .message { color: #000000; font-size: 100%; }
847  .search { float: right; }  .search { float: right; }
848    a:link.tag, a:visited.tag { border: 1px dashed #ccc; backgound: #ccc; text-decoration: none }
849    a:hover.tag { border: 1px solid #eee }
850    hr { border: 1px dashed #ccc; height: 1px; clear: both; }
851    /*
852  .col-0 { background: #ffff66 }  .col-0 { background: #ffff66 }
853  .col-1 { background: #a0ffff }  .col-1 { background: #a0ffff }
854  .col-2 { background: #99ff99 }  .col-2 { background: #99ff99 }
855  .col-3 { background: #ff9999 }  .col-3 { background: #ff9999 }
856  .col-4 { background: #ff66ff }  .col-4 { background: #ff66ff }
857  a:link.tag, a:visited.tag { border: 1px dashed #ccc; backgound: #ccc; text-decoration: none }  */
858  a:hover.tag { border: 1px solid #eee }  .calendar { border: 1px solid red; width: 100%; }
859  hr { border: 1px dashed #ccc; height: 1px; clear: both; }  .month { border: 0px; width: 100%; }
860  _END_OF_STYLE_  _END_OF_STYLE_
861    
862  my $max_color = 4;  my $max_color = 4;
863    
864    my @cols = qw(
865            #ffcccc #ccffe6 #ccccff #e6ccff #ffccff #ffcce6 #ff9999 #ffcc99 #ffff99
866            #ccff99 #99ff99 #99ffcc #99ccff #9999ff #cc99ff #ff6666 #ffb366 #ffff66
867            #66ff66 #66ffb3 #66b3ff #6666ff #ff3333 #33ff33 #3399ff #3333ff #ff3399
868            #a0a0a0 #ff0000 #ffff00 #80ff00 #0000ff #8000ff #ff00ff #ff0080 #994d00
869            #999900 #009900 #cc0066 #c0c0c0 #ccff99 #99ff33 #808080 #660033 #ffffff
870    );
871    
872    $max_color = 0;
873    foreach my $c (@cols) {
874            $style .= ".col-${max_color} { background: $c }\n";
875            $max_color++;
876    }
877    warn "defined $max_color colors for users...\n";
878    
879  my %nick_enumerator;  my %nick_enumerator;
880    
881  sub root_handler {  sub root_handler {
# Line 864  sub root_handler { Line 909  sub root_handler {
909                  qq{<p>};                  qq{<p>};
910          if ($request->url =~ m#/history#) {          if ($request->url =~ m#/history#) {
911                  my $sth = $dbh->prepare(qq{                  my $sth = $dbh->prepare(qq{
912                          select date(time) as date,count(*) as nr                          select date(time) as date,count(*) as nr,sum(length(message)) as len
913                                  from log                                  from log
914                                  group by date(time)                                  group by date(time)
915                                  order by date(time) desc                                  order by date(time) desc
916                  });                  });
917                  $sth->execute();                  $sth->execute();
918                  my ($l_yyyy,$l_mm) = (0,0);                  my ($l_yyyy,$l_mm) = (0,0);
919                    $html .= qq{<table class="calendar"><tr>};
920                  my $cal;                  my $cal;
921                    my $ord = 0;
922                  while (my $row = $sth->fetchrow_hashref) {                  while (my $row = $sth->fetchrow_hashref) {
923                          # this is probably PostgreSQL specific, expects ISO date                          # this is probably PostgreSQL specific, expects ISO date
924                          my ($yyyy,$mm,$dd) = split(/-/, $row->{date});                          my ($yyyy,$mm,$dd) = split(/-/, $row->{date});
925                          if ($yyyy != $l_yyyy || $mm != $l_mm) {                          if ($yyyy != $l_yyyy || $mm != $l_mm) {
926                                  $html .= $cal->as_HTML() if ($cal);                                  if ( $cal ) {
927                                            $html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td>};
928                                            $ord++;
929                                            $html .= qq{</tr><tr>} if ( $ord % 3 == 0 );
930                                    }
931                                  $cal = new HTML::CalendarMonthSimple('month'=>$mm,'year'=>$yyyy);                                  $cal = new HTML::CalendarMonthSimple('month'=>$mm,'year'=>$yyyy);
932                                  $cal->border(2);                                  $cal->border(1);
933                                    $cal->width('30%');
934                                    $cal->cellheight('5em');
935                                    $cal->tableclass('month');
936                                    #$cal->cellclass('day');
937                                    $cal->sunday('SUN');
938                                    $cal->saturday('SAT');
939                                    $cal->weekdays('MON','TUE','WED','THU','FRI');
940                                  ($l_yyyy,$l_mm) = ($yyyy,$mm);                                  ($l_yyyy,$l_mm) = ($yyyy,$mm);
941                          }                          }
942                          $cal->setcontent($dd, qq{                          $cal->setcontent($dd, qq{
943                                  <a href="/?date=$row->{date}">$row->{nr}</a>                                  <a href="/?date=$row->{date}">$row->{nr}</a><br/>$row->{len}
944                          });                          });
945                            
946                  }                  }
947                  $html .= $cal->as_HTML() if ($cal);                  $html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>};
948    
949          } else {          } else {
950                  $html .= join("</p><p>",                  $html .= join("</p><p>",
# Line 908  sub root_handler { Line 967  sub root_handler {
967                                  filter => {                                  filter => {
968                                          message => sub {                                          message => sub {
969                                                  my $m = shift || return;                                                  my $m = shift || return;
970    
971                                                    # protect HTML from wiki modifications
972                                                    sub e {
973                                                            my $t = shift;
974                                                            return 'uri_unescape{' . uri_escape($t) . '}';
975                                                    }
976    
977                                                  $m =~ s/($escape_re)/$escape{$1}/gs;                                                  $m =~ s/($escape_re)/$escape{$1}/gs;
978                                                  $m =~ s#($RE{URI}{HTTP})#<a href="$1">$1</a>#gs;                                                  $m =~ s#($RE{URI}{HTTP})#e(qq{<a href="$1">$1</a>})#egs;
979                                                  $m =~ s#$tag_regex#<a href="?tag=$1" class="tag">$1</a>#g;                                                  $m =~ s#$tag_regex#e(qq{<a href="?tag=$1" class="tag">$1</a>})#egs;
980                                                    $m =~ s#\*(\w+)\*#<b>$1</b>#gs;
981                                                    $m =~ s#_(\w+)_#<u>$1</u>#gs;
982                                                    $m =~ s#\/(\w+)\/#<i>$1</i>#gs;
983    
984                                                    $m =~ s#uri_unescape{([^}]+)}#uri_unescape($1)#egs;
985                                                  return $m;                                                  return $m;
986                                          },                                          },
987                                          nick => sub {                                          nick => sub {

Legend:
Removed from v.50  
changed lines
  Added in v.65

  ViewVC Help
Powered by ViewVC 1.1.26