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 |
|
|
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 |
489 |
my $nr = $1 || 10; |
my $nr = $1 || 10; |
490 |
|
|
491 |
my $sth = $dbh->prepare(qq{ |
my $sth = $dbh->prepare(qq{ |
492 |
select nick,count(*) from log group by nick order by count desc limit $nr |
select |
493 |
|
nick, |
494 |
|
count(*) as count, |
495 |
|
sum(length(message)) as len |
496 |
|
from log |
497 |
|
group by nick |
498 |
|
order by len desc,count desc |
499 |
|
limit $nr |
500 |
}); |
}); |
501 |
$sth->execute(); |
$sth->execute(); |
502 |
$res = "Top $nr users: "; |
$res = "Top $nr users: "; |
503 |
my @users; |
my @users; |
504 |
while (my $row = $sth->fetchrow_hashref) { |
while (my $row = $sth->fetchrow_hashref) { |
505 |
push @users,$row->{nick} . ': ' . $row->{count}; |
push @users,$row->{nick} . ': ' . $row->{count} . '/' . $row->{len} . '=' . sprintf("%.2f", $row->{len}/$row->{count}); |
506 |
} |
} |
507 |
$res .= join(" | ", @users); |
$res .= join(" | ", @users); |
508 |
} elsif ($msg =~ m/^last.*?\s*(\d*)/i) { |
} elsif ($msg =~ m/^last.*?\s*(\d*)/i) { |
509 |
|
|
510 |
foreach my $res (get_from_log( limit => $1 )) { |
foreach my $res (get_from_log( limit => ($1 || 100) )) { |
511 |
print "last: $res\n"; |
print "last: $res\n"; |
512 |
from_to($res, $ENCODING, 'UTF-8'); |
from_to($res, $ENCODING, 'UTF-8'); |
513 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
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) { |
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"; |