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 |
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 { |
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 |
); |
); |
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 |
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) { |