/[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 85 by dpavlin, Thu Mar 6 22:16:27 2008 UTC revision 86 by dpavlin, Thu Mar 6 22:57:16 2008 UTC
# Line 55  my $follows_path = 'follows.log'; Line 55  my $follows_path = 'follows.log';
55    
56  my $DSN = 'DBI:Pg:dbname=' . $NICK;  my $DSN = 'DBI:Pg:dbname=' . $NICK;
57    
58    # log output encoding
59  my $ENCODING = 'ISO-8859-2';  my $ENCODING = 'ISO-8859-2';
60  my $TIMESTAMP = '%Y-%m-%d %H:%M:%S';  my $TIMESTAMP = '%Y-%m-%d %H:%M:%S';
61    
# Line 110  $SIG{__DIE__} = sub { Line 111  $SIG{__DIE__} = sub {
111  open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!";  open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!";
112    
113  sub _log {  sub _log {
114          print strftime($TIMESTAMP,localtime()), ' ', join(" ",@_), $/;          my $out = strftime($TIMESTAMP,localtime()) . ' ' . join(" ",@_) . $/;
115            from_to( $out, 'UTF-8', $ENCODING );
116            print $out;
117  }  }
118    
119  # LOG following  # LOG following
# Line 174  my $filter = { Line 177  my $filter = {
177  };  };
178    
179  my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr;  my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr;
180    $dbh->do( qq{ set client_encoding = 'UTF-8' } );
181    
182  my $sql_schema = {  my $sql_schema = {
183          log => qq{          log => qq{
# Line 206  create table feeds ( Line 210  create table feeds (
210          id serial,          id serial,
211          url text not null,          url text not null,
212          name text,          name text,
213          delay interval not null default '30 sec', --'5 min',          delay interval not null default '5 min',
214          active boolean default true,          active boolean default true,
215          last_update timestamp default 'now()',          last_update timestamp default 'now()',
216          polls int default 0,          polls int default 0,
# Line 599  sub save_message { Line 603  sub save_message {
603                  $a->{me} ? "***" . $a->{nick} : "<" . $a->{nick} . ">",                  $a->{me} ? "***" . $a->{nick} : "<" . $a->{nick} . ">",
604                  " " . $a->{message};                  " " . $a->{message};
605    
         from_to($a->{message}, 'UTF-8', $ENCODING);  
   
606          $sth->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time});          $sth->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time});
607          add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), %$a );          add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), %$a );
608  }  }
# Line 676  sub rss_fetch { Line 678  sub rss_fetch {
678                  $msg .= prefix( ' -- ' , $entry->link );                  $msg .= prefix( ' -- ' , $entry->link );
679  #               $msg .= prefix( ' id ' , $entry->id );  #               $msg .= prefix( ' id ' , $entry->id );
680    
                 _log('RSS', $msg);  
   
681                  if ( $args->{kernel} && $send_rss_msgs ) {                  if ( $args->{kernel} && $send_rss_msgs ) {
682                          warn "# sending to $CHANNEL\n";                          warn "# sending to $CHANNEL\n";
683                          $send_rss_msgs--;                          $send_rss_msgs--;
684                          $args->{kernel}->post( $IRC_ALIAS => notice => $CHANNEL, $msg );                          $args->{kernel}->post( $IRC_ALIAS => notice => $CHANNEL, $msg );
685                          $updates++;                          $updates++;
686                            save_message( channel => $CHANNEL, me => 1, nick => $NICK, message => $msg );
687                            _log('RSS', $msg);
688                  }                  }
689          }          }
690    
691          my $sql = qq{ update feeds set last_update = now(), polls = polls + 1 };          my $sql = qq{ update feeds set last_update = now(), polls = polls + 1 };
692          $sql .= qq{, updates = updates + $updates } if $updates;          $sql .= qq{, updates = updates + $updates } if $updates;
693          $sql .= qq{where id = } . $args->{id};          $sql .= qq{where id = } . $args->{id};
694          $dbh->do( $sql );          eval { $dbh->do( $sql ) };
695    
696          return $updates;          return $updates;
697  }  }
# Line 799  POE::Session->create( inline_states => { Line 801  POE::Session->create( inline_states => {
801                  my $nick = (split /!/, $_[ARG0])[0];                  my $nick = (split /!/, $_[ARG0])[0];
802                  my $msg = $_[ARG2];                  my $msg = $_[ARG2];
803                  my $channel = $_[ARG1]->[0];                  my $channel = $_[ARG1]->[0];
                 from_to($msg, 'UTF-8', $ENCODING);  
804    
805                  my $res = "unknown command '$msg', try /msg $NICK help!";                  my $res = "unknown command '$msg', try /msg $NICK help!";
806                  my @out;                  my @out;
# Line 843  POE::Session->create( inline_states => { Line 844  POE::Session->create( inline_states => {
844    
845                          foreach my $res (get_from_log( limit => $limit )) {                          foreach my $res (get_from_log( limit => $limit )) {
846                                  _log "last: $res";                                  _log "last: $res";
                                 from_to($res, $ENCODING, 'UTF-8');  
847                                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );                                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );
848                          }                          }
849    
# Line 858  POE::Session->create( inline_states => { Line 858  POE::Session->create( inline_states => {
858                                          search => $what,                                          search => $what,
859                                  )) {                                  )) {
860                                  _log "search [$what]: $res";                                  _log "search [$what]: $res";
                                 from_to($res, $ENCODING, 'UTF-8');  
861                                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );                                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );
862                          }                          }
863    
# Line 952  POE::Session->create( inline_states => { Line 951  POE::Session->create( inline_states => {
951    
952                  if ($res) {                  if ($res) {
953                          _log ">> [$nick] $res";                          _log ">> [$nick] $res";
                         from_to($res, $ENCODING, 'UTF-8');  
954                          $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );                          $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );
955                  }                  }
956    
# Line 1183  sub root_handler { Line 1181  sub root_handler {
1181                                  my $message = $filter->{message}->( $m->{message} );                                  my $message = $filter->{message}->( $m->{message} );
1182                                  $message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!;                                  $message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!;
1183  #                               warn "## message = $message\n";  #                               warn "## message = $message\n";
                                 from_to( $message, $ENCODING, 'UTF-8' );  
1184    
1185                                  #$feed_entry->summary(                                  #$feed_entry->summary(
1186                                  $feed_entry->content(                                  $feed_entry->content(
# Line 1227  sub root_handler { Line 1224  sub root_handler {
1224                  warn "$@";                  warn "$@";
1225          }          }
1226    
1227          $response->content_type("text/html; charset=$ENCODING");          $response->content_type("text/html; charset=UTF-8");
1228    
1229          my $html =          my $html =
1230                  qq{<html><head><title>$NICK</title><style type="text/css">$style}                  qq{<html><head><title>$NICK</title><style type="text/css">$style}

Legend:
Removed from v.85  
changed lines
  Added in v.86

  ViewVC Help
Powered by ViewVC 1.1.26