/[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 41 by dpavlin, Tue Oct 24 12:51:49 2006 UTC revision 42 by dpavlin, Fri Feb 2 21:37:52 2007 UTC
# Line 128  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 135  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 204  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 260  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 519  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) {

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

  ViewVC Help
Powered by ViewVC 1.1.26