/[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 40 by dpavlin, Tue Oct 24 12:50:41 2006 UTC revision 42 by dpavlin, Fri Feb 2 21:37:52 2007 UTC
# Line 50  my $DSN = 'DBI:Pg:dbname=' . $NICK; Line 50  my $DSN = 'DBI:Pg:dbname=' . $NICK;
50  my $ENCODING = 'ISO-8859-2';  my $ENCODING = 'ISO-8859-2';
51  my $TIMESTAMP = '%Y-%m-%d %H:%M:%S';  my $TIMESTAMP = '%Y-%m-%d %H:%M:%S';
52    
53    my $sleep_on_error = 5;
54    
55  ## END CONFIG  ## END CONFIG
56    
57    
# Line 126  my $tag_regex = '\b([\w-_]+)//'; Line 128  my $tag_regex = '\b([\w-_]+)//';
128                  }                  }
129          },          },
130          context => 5,          context => 5,
131            full_rows => 1,
132   );   );
133    
134  Order is important. Fields are first passed through C<filter> (if available) and  Order is important. Fields are first passed through C<filter> (if available) and
# Line 133  then throgh C<< sprintf($fmt->{message}, Line 136  then throgh C<< sprintf($fmt->{message},
136    
137  C<context> defines number of messages around each search hit for display.  C<context> defines number of messages around each search hit for display.
138    
139    C<full_rows> will return database rows for each result with C<date>, C<time>, C<channel>,
140    C<me>, C<nick> and C<message> keys.
141    
142  =cut  =cut
143    
144  sub get_from_log {  sub get_from_log {
# Line 202  sub get_from_log { Line 208  sub get_from_log {
208                  unshift @rows, $row;                  unshift @rows, $row;
209          }          }
210    
211            # normalize nick names
212            map {
213                    $_->{nick} =~ s/^_*(.*?)_*$/$1/
214            } @rows;
215    
216            return @rows if ($args->{full_rows});
217    
218          my @msgs = (          my @msgs = (
219                  "Showing " . ($#rows + 1) . " messages..."                  "Showing " . ($#rows + 1) . " messages..."
220          );          );
# Line 258  sub get_from_log { Line 271  sub get_from_log {
271                  my $append = 1;                  my $append = 1;
272    
273                  my $nick = $row->{nick};                  my $nick = $row->{nick};
274                  if ($nick =~ s/^_*(.*?)_*$/$1/) {  #               if ($nick =~ s/^_*(.*?)_*$/$1/) {
275                          $row->{nick} = $nick;  #                       $row->{nick} = $nick;
276                  }  #               }
277    
278                  if ($last_row->{nick} ne $nick) {                  if ($last_row->{nick} ne $nick) {
279                          # obfu way to find format for me_nick if needed or fallback to default                          # obfu way to find format for me_nick if needed or fallback to default
# Line 517  POE::Session->create( inline_states => Line 530  POE::Session->create( inline_states =>
530    
531                          $res = '';                          $res = '';
532    
533                    } elsif ($msg =~ m/^(?:count|poll)\s+(.*)(?:\s+(\d+))?\s*$/i) {
534    
535                            my ($what,$limit) = ($1,$2);
536                            $limit ||= 100;
537    
538                            my $stat;
539    
540                            foreach my $res (get_from_log(
541                                            limit => $limit,
542                                            search => $what,
543                                            full_rows => 1,
544                                    )) {
545                                    while ($res->{message} =~ s/\Q$what\E(\+|\-)//) {
546                                            $stat->{vote}->{$1}++;
547                                            $stat->{from}->{ $res->{nick} }++;
548                                    }
549                            }
550    
551                            my @nicks;
552                            foreach my $nick (sort { $stat->{from}->{$a} cmp $stat->{from}->{$b} } keys %{ $stat->{from} }) {
553                                    push @nicks, $nick . $stat->{from}->{$nick} == 1 ? '' :
554                                            "(" . $stat->{from}->{$nick} . ")";
555                            }
556    
557                            $res =
558                                    "+ " . ( $stat->{vote}->{'+'} || 0 ) . " : " .
559                                    "- " . ( $stat->{vote}->{'-'} || 0 ) .
560                                    " from " . ( join(", ", @nicks) || 'nobody' );
561    
562                  }                  }
563    
564                  if ($res) {                  if ($res) {
# Line 540  POE::Session->create( inline_states => Line 582  POE::Session->create( inline_states =>
582                  warn "## indetify $NICK\n";                  warn "## indetify $NICK\n";
583                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" );                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" );
584          },          },
585            irc_disconnected => sub {
586                    warn "## disconnected, reconnecting again\n";
587                    $_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT);
588            },
589            irc_socketerr => sub {
590                    warn "## socket error... sleeping for $sleep_on_error seconds and retry";
591                    sleep($sleep_on_error);
592                    $_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT);
593            },
594  #       irc_433 => sub {  #       irc_433 => sub {
595  #               print "# irc_433: ",$_[ARG1], "\n";  #               print "# irc_433: ",$_[ARG1], "\n";
596  #               warn "## indetify $NICK\n";  #               warn "## indetify $NICK\n";

Legend:
Removed from v.40  
changed lines
  Added in v.42

  ViewVC Help
Powered by ViewVC 1.1.26