20 |
|
|
21 |
=item --log=irc-logger.log |
=item --log=irc-logger.log |
22 |
|
|
|
Name of log file |
|
|
|
|
23 |
=back |
=back |
24 |
|
|
25 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
44 |
$CHANNEL = '#irc-logger' if ($HOSTNAME =~ m/llin/); |
$CHANNEL = '#irc-logger' if ($HOSTNAME =~ m/llin/); |
45 |
my $IRC_ALIAS = "log"; |
my $IRC_ALIAS = "log"; |
46 |
|
|
|
my %FOLLOWS = |
|
|
( |
|
|
ACCESS => "/var/log/apache/access.log", |
|
|
ERROR => "/var/log/apache/error.log", |
|
|
); |
|
|
|
|
47 |
my $DSN = 'DBI:Pg:dbname=' . $NICK; |
my $DSN = 'DBI:Pg:dbname=' . $NICK; |
48 |
|
|
|
my $ENCODING = 'ISO-8859-2'; |
|
49 |
my $TIMESTAMP = '%Y-%m-%d %H:%M:%S'; |
my $TIMESTAMP = '%Y-%m-%d %H:%M:%S'; |
50 |
|
|
51 |
my $sleep_on_error = 5; |
my $sleep_on_error = 5; |
53 |
# number of last tags to keep in circular buffer |
# number of last tags to keep in circular buffer |
54 |
my $last_x_tags = 50; |
my $last_x_tags = 50; |
55 |
|
|
56 |
|
# don't pull rss feeds more often than this |
57 |
|
my $rss_min_delay = 60; |
58 |
|
|
59 |
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000; |
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000; |
60 |
|
|
61 |
my $url = "http://$HOSTNAME:$http_port"; |
my $url = "http://$HOSTNAME:$http_port"; |
62 |
|
|
63 |
## END CONFIG |
## END CONFIG |
64 |
|
|
65 |
|
use POE qw(Component::IRC Component::Server::HTTP); |
|
|
|
|
use POE qw(Component::IRC Wheel::FollowTail Component::Server::HTTP); |
|
66 |
use HTTP::Status; |
use HTTP::Status; |
67 |
use DBI; |
use DBI; |
|
use Encode qw/from_to is_utf8/; |
|
68 |
use Regexp::Common qw /URI/; |
use Regexp::Common qw /URI/; |
69 |
use CGI::Simple; |
use CGI::Simple; |
70 |
use HTML::TagCloud; |
use HTML::TagCloud; |
90 |
'log:s' => \$log_path, |
'log:s' => \$log_path, |
91 |
); |
); |
92 |
|
|
93 |
$SIG{__DIE__} = sub { |
#$SIG{__DIE__} = sub { |
94 |
confess "fatal error"; |
# confess "fatal error"; |
95 |
}; |
#}; |
96 |
|
|
97 |
open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!"; |
open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!"; |
98 |
|
|
99 |
sub _log { |
sub _log { |
100 |
print strftime($TIMESTAMP,localtime()), ' ', join(" ",@_), $/; |
print strftime($TIMESTAMP,localtime()) . ' ' . join(" ",@_) . $/; |
101 |
} |
} |
102 |
|
|
103 |
# HTML formatters |
# HTML formatters |
143 |
}; |
}; |
144 |
|
|
145 |
my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; |
my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; |
146 |
|
$dbh->do( qq{ set client_encoding = 'UTF-8' } ); |
147 |
|
|
148 |
my $sql_schema = { |
my $sql_schema = { |
149 |
log => ' |
log => qq{ |
150 |
create table log ( |
create table log ( |
151 |
id serial, |
id serial, |
152 |
time timestamp default now(), |
time timestamp default now(), |
160 |
create index log_time on log(time); |
create index log_time on log(time); |
161 |
create index log_channel on log(channel); |
create index log_channel on log(channel); |
162 |
create index log_nick on log(nick); |
create index log_nick on log(nick); |
163 |
', |
}, |
164 |
meta => ' |
meta => q{ |
165 |
create table meta ( |
create table meta ( |
166 |
nick text not null, |
nick text not null, |
167 |
channel text not null, |
channel text not null, |
168 |
name text not null, |
name text not null, |
169 |
value text, |
value text, |
170 |
changed timestamp default now(), |
changed timestamp default 'now()', |
171 |
primary key(nick,channel,name) |
primary key(nick,channel,name) |
172 |
); |
); |
173 |
', |
}, |
174 |
|
feeds => qq{ |
175 |
|
create table feeds ( |
176 |
|
id serial, |
177 |
|
url text not null, |
178 |
|
name text, |
179 |
|
delay interval not null default '5 min', |
180 |
|
active boolean default true, |
181 |
|
channel text not null, |
182 |
|
nick text not null, |
183 |
|
private boolean default false, |
184 |
|
last_update timestamp default 'now()', |
185 |
|
polls int default 0, |
186 |
|
updates int default 0 |
187 |
|
); |
188 |
|
create unique index feeds_url on feeds(url); |
189 |
|
insert into feeds (url,name,channel,nick) values ('http://wiki.razmjenavjestina.org/feed/workspace/razmjenavjestina?category=Recent%20Changes','wiki','$CHANNEL','dpavlin'); |
190 |
|
}, |
191 |
}; |
}; |
192 |
|
|
193 |
foreach my $table ( keys %$sql_schema ) { |
foreach my $table ( keys %$sql_schema ) { |
230 |
if ( $@ || ! $sth->rows ) { |
if ( $@ || ! $sth->rows ) { |
231 |
$sth = $dbh->prepare(qq{ insert into meta (value,nick,channel,name,changed) values (?,?,?,?,now()) }); |
$sth = $dbh->prepare(qq{ insert into meta (value,nick,channel,name,changed) values (?,?,?,?,now()) }); |
232 |
$sth->execute( $value, $nick, $channel, $name ); |
$sth->execute( $value, $nick, $channel, $name ); |
233 |
_log "created $nick/$channel/$name = $value"; |
warn "## created $nick/$channel/$name = $value\n"; |
234 |
} else { |
} else { |
235 |
_log "updated $nick/$channel/$name = $value "; |
warn "## updated $nick/$channel/$name = $value\n"; |
236 |
} |
} |
237 |
|
|
238 |
return $value; |
return $value; |
242 |
my $sth = $dbh->prepare(qq{ select value,changed from meta where nick = ? and channel = ? and name = ? }); |
my $sth = $dbh->prepare(qq{ select value,changed from meta where nick = ? and channel = ? and name = ? }); |
243 |
$sth->execute( $nick, $channel, $name ); |
$sth->execute( $nick, $channel, $name ); |
244 |
my ($v,$c) = $sth->fetchrow_array; |
my ($v,$c) = $sth->fetchrow_array; |
245 |
_log "fetched $nick/$channel/$name = $v [$c]"; |
warn "## fetched $nick/$channel/$name = $v [$c]\n"; |
246 |
return ($v,$c) if wantarray; |
return ($v,$c) if wantarray; |
247 |
return $v; |
return $v; |
248 |
|
|
251 |
|
|
252 |
|
|
253 |
|
|
254 |
my $sth = $dbh->prepare(qq{ |
my $sth_insert_log = $dbh->prepare(qq{ |
255 |
insert into log |
insert into log |
256 |
(channel, me, nick, message, time) |
(channel, me, nick, message, time) |
257 |
values (?,?,?,?,?) |
values (?,?,?,?,?) |
503 |
return unless ($arg->{id} && $arg->{message}); |
return unless ($arg->{id} && $arg->{message}); |
504 |
|
|
505 |
my $m = $arg->{message}; |
my $m = $arg->{message}; |
|
from_to('UTF-8', 'iso-8859-2', $m) if (is_utf8($m)); |
|
506 |
|
|
507 |
my @tags; |
my @tags; |
508 |
|
|
571 |
$a->{me} ? "***" . $a->{nick} : "<" . $a->{nick} . ">", |
$a->{me} ? "***" . $a->{nick} : "<" . $a->{nick} . ">", |
572 |
" " . $a->{message}; |
" " . $a->{message}; |
573 |
|
|
574 |
from_to($a->{message}, 'UTF-8', $ENCODING); |
$sth_insert_log->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time}); |
|
|
|
|
$sth->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time}); |
|
575 |
add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), %$a ); |
add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), %$a ); |
576 |
} |
} |
577 |
|
|
610 |
exit; |
exit; |
611 |
} |
} |
612 |
|
|
613 |
|
# |
614 |
|
# RSS follow |
615 |
|
# |
616 |
|
|
617 |
|
my $_rss; |
618 |
|
|
619 |
|
|
620 |
|
sub rss_fetch { |
621 |
|
my ($args) = @_; |
622 |
|
|
623 |
|
# how many messages to send out when feed is seen for the first time? |
624 |
|
my $send_rss_msgs = 1; |
625 |
|
|
626 |
|
_log "RSS fetch", $args->{url}; |
627 |
|
|
628 |
|
my $feed = XML::Feed->parse(URI->new( $args->{url} )); |
629 |
|
if ( ! $feed ) { |
630 |
|
_log("can't fetch RSS ", $args->{url}); |
631 |
|
return; |
632 |
|
} |
633 |
|
|
634 |
|
my ( $total, $updates ) = ( 0, 0 ); |
635 |
|
for my $entry ($feed->entries) { |
636 |
|
$total++; |
637 |
|
|
638 |
|
# seen allready? |
639 |
|
next if $_rss->{$args->{channel}}->{$feed->link}->{$entry->id}++ > 0; |
640 |
|
|
641 |
|
sub prefix { |
642 |
|
my ($txt,$var) = @_; |
643 |
|
$var =~ s/\s+/ /gs; |
644 |
|
$var =~ s/^\s+//g; |
645 |
|
$var =~ s/\s+$//g; |
646 |
|
return $txt . $var if $var; |
647 |
|
} |
648 |
|
|
649 |
|
# fix absolute and relative links to feed entries |
650 |
|
my $link = $entry->link; |
651 |
|
if ( $link =~ m!^/! ) { |
652 |
|
my $host = $args->{url}; |
653 |
|
$host =~ s!^(http://[^/]+).*$!$1!; #!vim |
654 |
|
$link = "$host/$link"; |
655 |
|
} elsif ( $link !~ m!^http! ) { |
656 |
|
$link = $args->{url} . $link; |
657 |
|
} |
658 |
|
$link =~ s!//+!/!g; |
659 |
|
|
660 |
|
my $msg; |
661 |
|
$msg .= prefix( 'From: ' , $args->{name} || $feed->title ); |
662 |
|
$msg .= prefix( ' by ' , $entry->author ); |
663 |
|
$msg .= prefix( ' | ' , $entry->title ); |
664 |
|
$msg .= prefix( ' | ' , $link ); |
665 |
|
# $msg .= prefix( ' id ' , $entry->id ); |
666 |
|
|
667 |
|
if ( $args->{kernel} && $send_rss_msgs ) { |
668 |
|
$send_rss_msgs--; |
669 |
|
$sth_insert_log->execute( $args->{channel}, 1, $NICK, $msg, 'now()' ); |
670 |
|
my ( $type, $to ) = ( 'notice', $args->{channel} ); |
671 |
|
( $type, $to ) = ( 'privmsg', $args->{nick} ) if $args->{private}; |
672 |
|
_log(">> $type $to |", $msg); |
673 |
|
$args->{kernel}->post( $IRC_ALIAS => $type => $to, $msg ); |
674 |
|
$updates++; |
675 |
|
} |
676 |
|
} |
677 |
|
|
678 |
|
my $sql = qq{ update feeds set last_update = now(), polls = polls + 1 }; |
679 |
|
$sql .= qq{, updates = updates + $updates } if $updates; |
680 |
|
$sql .= qq{where id = } . $args->{id}; |
681 |
|
eval { $dbh->do( $sql ) }; |
682 |
|
|
683 |
|
_log "RSS got $total items of which $updates new"; |
684 |
|
|
685 |
|
return $updates; |
686 |
|
} |
687 |
|
|
688 |
|
sub rss_fetch_all { |
689 |
|
my $kernel = shift; |
690 |
|
my $sql = qq{ |
691 |
|
select id, url, name, channel, nick, private |
692 |
|
from feeds |
693 |
|
where active is true |
694 |
|
}; |
695 |
|
# limit to newer feeds only if we are not sending messages out |
696 |
|
$sql .= qq{ and last_update + delay < now() } if $kernel; |
697 |
|
my $sth = $dbh->prepare( $sql ); |
698 |
|
$sth->execute(); |
699 |
|
warn "# ",$sth->rows," active RSS feeds\n"; |
700 |
|
my $count = 0; |
701 |
|
while (my $row = $sth->fetchrow_hashref) { |
702 |
|
$row->{kernel} = $kernel if $kernel; |
703 |
|
$count += rss_fetch( $row ); |
704 |
|
} |
705 |
|
return "OK, fetched $count posts from " . $sth->rows . " feeds"; |
706 |
|
} |
707 |
|
|
708 |
|
|
709 |
|
sub rss_check_updates { |
710 |
|
my $kernel = shift; |
711 |
|
$_rss->{last_poll} ||= time(); |
712 |
|
my $dt = time() - $_rss->{last_poll}; |
713 |
|
warn "## rss_check_updates $dt > $rss_min_delay\n"; |
714 |
|
if ( $dt > $rss_min_delay ) { |
715 |
|
$_rss->{last_poll} = time(); |
716 |
|
_log rss_fetch_all( $kernel ); |
717 |
|
} |
718 |
|
} |
719 |
|
|
720 |
|
# seed rss seen cache so we won't send out all items on startup |
721 |
|
_log rss_fetch_all; |
722 |
|
|
723 |
# |
# |
724 |
# POE handing part |
# POE handing part |
725 |
# |
# |
726 |
|
|
|
my $SKIPPING = 0; # if skipping, how many we've done |
|
|
my $SEND_QUEUE; # cache |
|
727 |
my $ping; # ping stats |
my $ping; # ping stats |
728 |
|
|
729 |
POE::Component::IRC->new($IRC_ALIAS); |
POE::Component::IRC->new($IRC_ALIAS); |
730 |
|
|
731 |
POE::Session->create( inline_states => |
POE::Session->create( inline_states => { |
732 |
{_start => sub { |
_start => sub { |
733 |
$_[KERNEL]->post($IRC_ALIAS => register => 'all'); |
$_[KERNEL]->post($IRC_ALIAS => register => 'all'); |
734 |
$_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT); |
$_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT); |
735 |
}, |
}, |
736 |
irc_255 => sub { # server is done blabbing |
irc_255 => sub { # server is done blabbing |
737 |
$_[KERNEL]->post($IRC_ALIAS => join => $CHANNEL); |
$_[KERNEL]->post($IRC_ALIAS => join => $CHANNEL); |
|
$_[KERNEL]->post($IRC_ALIAS => join => '#logger'); |
|
|
$_[KERNEL]->yield("heartbeat"); # start heartbeat |
|
|
# $_[KERNEL]->yield("my_add", $_) for keys %FOLLOWS; |
|
738 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
739 |
}, |
}, |
740 |
irc_public => sub { |
irc_public => sub { |
745 |
|
|
746 |
save_message( channel => $channel, me => 0, nick => $nick, message => $msg); |
save_message( channel => $channel, me => 0, nick => $nick, message => $msg); |
747 |
meta( $nick, $channel, 'last-msg', $msg ); |
meta( $nick, $channel, 'last-msg', $msg ); |
748 |
|
rss_check_updates( $kernel ); |
749 |
}, |
}, |
750 |
irc_ctcp_action => sub { |
irc_ctcp_action => sub { |
751 |
my $kernel = $_[KERNEL]; |
my $kernel = $_[KERNEL]; |
766 |
|
|
767 |
}, |
}, |
768 |
irc_ping => sub { |
irc_ping => sub { |
769 |
warn "pong ", $_[ARG0], $/; |
_log( "pong ", $_[ARG0] ); |
770 |
$ping->{ $_[ARG0] }++; |
$ping->{ $_[ARG0] }++; |
771 |
|
rss_check_updates( $_[KERNEL] ); |
772 |
}, |
}, |
773 |
irc_invite => sub { |
irc_invite => sub { |
774 |
my $kernel = $_[KERNEL]; |
my $kernel = $_[KERNEL]; |
775 |
my $nick = (split /!/, $_[ARG0])[0]; |
my $nick = (split /!/, $_[ARG0])[0]; |
776 |
my $channel = $_[ARG1]; |
my $channel = $_[ARG1]; |
777 |
|
|
778 |
warn "invited to $channel by $nick"; |
_log "invited to $channel by $nick"; |
779 |
|
|
780 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, "how nice of you to invite me to $channel, I'll be right there..." ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, "how nice of you to invite me to $channel, I'll be right there..." ); |
781 |
$_[KERNEL]->post($IRC_ALIAS => join => $channel); |
$_[KERNEL]->post($IRC_ALIAS => join => $channel); |
786 |
my $nick = (split /!/, $_[ARG0])[0]; |
my $nick = (split /!/, $_[ARG0])[0]; |
787 |
my $msg = $_[ARG2]; |
my $msg = $_[ARG2]; |
788 |
my $channel = $_[ARG1]->[0]; |
my $channel = $_[ARG1]->[0]; |
|
from_to($msg, 'UTF-8', $ENCODING); |
|
789 |
|
|
790 |
my $res = "unknown command '$msg', try /msg $NICK help!"; |
my $res = "unknown command '$msg', try /msg $NICK help!"; |
791 |
my @out; |
my @out; |
829 |
|
|
830 |
foreach my $res (get_from_log( limit => $limit )) { |
foreach my $res (get_from_log( limit => $limit )) { |
831 |
_log "last: $res"; |
_log "last: $res"; |
|
from_to($res, $ENCODING, 'UTF-8'); |
|
832 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
833 |
} |
} |
834 |
|
|
843 |
search => $what, |
search => $what, |
844 |
)) { |
)) { |
845 |
_log "search [$what]: $res"; |
_log "search [$what]: $res"; |
|
from_to($res, $ENCODING, 'UTF-8'); |
|
846 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
847 |
} |
} |
848 |
|
|
912 |
$res = "config option $op doesn't exist"; |
$res = "config option $op doesn't exist"; |
913 |
} |
} |
914 |
} |
} |
915 |
|
} elsif ($msg =~ m/^rss-update/) { |
916 |
|
$res = rss_fetch_all( $_[KERNEL] ); |
917 |
|
} elsif ($msg =~ m/^rss-clean/) { |
918 |
|
$_rss = undef; |
919 |
|
$dbh->do( qq{ update feeds set last_update = now() - delay } ); |
920 |
|
$res = "OK, cleaned RSS cache"; |
921 |
|
} elsif ($msg =~ m/^rss-list/) { |
922 |
|
my $sth = $dbh->prepare(qq{ select url,name,last_update,active,channel,nick,private from feeds }); |
923 |
|
$sth->execute; |
924 |
|
while (my @row = $sth->fetchrow_array) { |
925 |
|
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, join(' | ',@row) ); |
926 |
|
} |
927 |
|
$res = ''; |
928 |
|
} elsif ($msg =~ m!^rss-(add|remove|stop|start)(?:-(private))?\s+(http://\S+)\s*(.*)!) { |
929 |
|
my ( $command, $sub, $url, $arg ) = ( $1,$2,$3,$4 ); |
930 |
|
|
931 |
|
my $channel = $1 if ( $arg =~ s/\s*(#\S+)\s*// ); |
932 |
|
$channel = $nick if $sub eq 'private'; |
933 |
|
|
934 |
|
my $sql = { |
935 |
|
add => qq{ insert into feeds (url,name,channel,nick,private) values (?,?,?,?,?) }, |
936 |
|
# remove => qq{ delete from feeds where url = ? and name = ? }, |
937 |
|
start => qq{ update feeds set active = true where url = ? }, |
938 |
|
stop => qq{ update feeds set active = false where url = ? }, |
939 |
|
}; |
940 |
|
|
941 |
|
if (my $q = $sql->{$command} ) { |
942 |
|
my $sth = $dbh->prepare( $q ); |
943 |
|
my @data = ( $url ); |
944 |
|
if ( $command eq 'add' ) { |
945 |
|
push @data, ( $arg, $channel, $nick, $sub eq 'private' ? 1 : 0 ); |
946 |
|
} |
947 |
|
warn "## $command SQL $q with ",dump( @data ),"\n"; |
948 |
|
eval { $sth->execute( @data ) }; |
949 |
|
if ($@) { |
950 |
|
$res = "ERROR: $@"; |
951 |
|
} else { |
952 |
|
$res = "OK, RSS [$command|$sub|$url|$arg]"; |
953 |
|
} |
954 |
|
} else { |
955 |
|
$res = "ERROR: don't know what to do with: $msg"; |
956 |
|
} |
957 |
|
|
958 |
} |
} |
959 |
|
|
960 |
if ($res) { |
if ($res) { |
961 |
_log ">> [$nick] $res"; |
_log ">> [$nick] $res"; |
|
from_to($res, $ENCODING, 'UTF-8'); |
|
962 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
963 |
} |
} |
964 |
|
|
965 |
|
rss_check_updates( $_[KERNEL] ); |
966 |
}, |
}, |
967 |
irc_477 => sub { |
irc_477 => sub { |
968 |
_log "# irc_477: ",$_[ARG1]; |
_log "# irc_477: ",$_[ARG1]; |
1001 |
""; |
""; |
1002 |
0; # false for signals |
0; # false for signals |
1003 |
}, |
}, |
|
my_add => sub { |
|
|
my $trailing = $_[ARG0]; |
|
|
my $session = $_[SESSION]; |
|
|
POE::Session->create |
|
|
(inline_states => |
|
|
{_start => sub { |
|
|
$_[HEAP]->{wheel} = |
|
|
POE::Wheel::FollowTail->new |
|
|
( |
|
|
Filename => $FOLLOWS{$trailing}, |
|
|
InputEvent => 'got_line', |
|
|
); |
|
|
}, |
|
|
got_line => sub { |
|
|
$_[KERNEL]->post($session => my_tailed => |
|
|
time, $trailing, $_[ARG0]); |
|
|
}, |
|
|
}, |
|
|
); |
|
|
|
|
|
}, |
|
|
my_tailed => sub { |
|
|
my ($time, $file, $line) = @_[ARG0..ARG2]; |
|
|
## $time will be undef on a probe, or a time value if a real line |
|
|
|
|
|
## PoCo::IRC has throttling built in, but no external visibility |
|
|
## so this is reaching "under the hood" |
|
|
$SEND_QUEUE ||= |
|
|
$_[KERNEL]->alias_resolve($IRC_ALIAS)->get_heap->{send_queue}; |
|
|
|
|
|
## handle "no need to keep skipping" transition |
|
|
if ($SKIPPING and @$SEND_QUEUE < 1) { |
|
|
$_[KERNEL]->post($IRC_ALIAS => privmsg => $CHANNEL => |
|
|
"[discarded $SKIPPING messages]"); |
|
|
$SKIPPING = 0; |
|
|
} |
|
|
|
|
|
## handle potential message display |
|
|
if ($time) { |
|
|
if ($SKIPPING or @$SEND_QUEUE > 3) { # 3 msgs per 10 seconds |
|
|
$SKIPPING++; |
|
|
} else { |
|
|
my @time = localtime $time; |
|
|
$_[KERNEL]->post($IRC_ALIAS => privmsg => $CHANNEL => |
|
|
sprintf "%02d:%02d:%02d: %s: %s", |
|
|
($time[2] + 11) % 12 + 1, $time[1], $time[0], |
|
|
$file, $line); |
|
|
} |
|
|
} |
|
|
|
|
|
## handle re-probe/flush if skipping |
|
|
if ($SKIPPING) { |
|
|
$_[KERNEL]->delay($_[STATE] => 0.5); # $time will be undef |
|
|
} |
|
|
|
|
|
}, |
|
|
my_heartbeat => sub { |
|
|
$_[KERNEL]->yield(my_tailed => time, "heartbeat", "beep"); |
|
|
$_[KERNEL]->delay($_[STATE] => 10); |
|
|
} |
|
1004 |
}, |
}, |
1005 |
); |
); |
1006 |
|
|
1075 |
|
|
1076 |
my $search = $q->param('search') || $q->param('grep') || ''; |
my $search = $q->param('search') || $q->param('grep') || ''; |
1077 |
|
|
1078 |
if ($request->url =~ m#/rss(?:/(tags|last-tag)\w*(?:=(\d+))?)?#i) { |
if ($request->url =~ m#/rss(?:/(tags|last-tag|follow.*)\w*(?:=(\d+))?)?#i) { |
1079 |
my $show = lc($1); |
my $show = lc($1); |
1080 |
my $nr = $2; |
my $nr = $2; |
1081 |
|
|
1087 |
#warn "create $type feed from ",dump( @last_tags ); |
#warn "create $type feed from ",dump( @last_tags ); |
1088 |
|
|
1089 |
my $feed = XML::Feed->new( $type ); |
my $feed = XML::Feed->new( $type ); |
1090 |
|
$feed->link( $url ); |
1091 |
|
|
1092 |
if ( $show eq 'tags' ) { |
if ( $show eq 'tags' ) { |
1093 |
$nr ||= 50; |
$nr ||= 50; |
1114 |
$nr = $last_x_tags if $nr > $last_x_tags; |
$nr = $last_x_tags if $nr > $last_x_tags; |
1115 |
|
|
1116 |
$feed->title( "last $nr tagged messages from $CHANNEL" ); |
$feed->title( "last $nr tagged messages from $CHANNEL" ); |
|
$feed->link( $url ); |
|
1117 |
$feed->description( "collects messages which have tags// in them" ); |
$feed->description( "collects messages which have tags// in them" ); |
1118 |
|
|
1119 |
foreach my $m ( @last_tags ) { |
foreach my $m ( @last_tags ) { |
1128 |
my $message = $filter->{message}->( $m->{message} ); |
my $message = $filter->{message}->( $m->{message} ); |
1129 |
$message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!; |
$message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!; |
1130 |
# warn "## message = $message\n"; |
# warn "## message = $message\n"; |
|
from_to( $message, $ENCODING, 'UTF-8' ); |
|
1131 |
|
|
1132 |
#$feed_entry->summary( |
#$feed_entry->summary( |
1133 |
$feed_entry->content( |
$feed_entry->content( |
1141 |
|
|
1142 |
} |
} |
1143 |
|
|
1144 |
|
} elsif ( $show =~ m/^follow/ ) { |
1145 |
|
|
1146 |
|
$feed->title( "Feeds which this bot follows" ); |
1147 |
|
|
1148 |
|
my $sth = $dbh->prepare( qq{ select * from feeds order by last_update desc } ); |
1149 |
|
$sth->execute; |
1150 |
|
while (my $row = $sth->fetchrow_hashref) { |
1151 |
|
my $feed_entry = XML::Feed::Entry->new($type); |
1152 |
|
$feed_entry->title( $row->{name} ); |
1153 |
|
$feed_entry->link( $row->{url} ); |
1154 |
|
$feed_entry->issued( DateTime::Format::Flexible->build( $row->{last_update} ) ); |
1155 |
|
$feed_entry->content( |
1156 |
|
'<![CDATA[<pre>' . dump( $row ) . '</pre>]]>' |
1157 |
|
); |
1158 |
|
$feed->add_entry( $feed_entry ); |
1159 |
|
} |
1160 |
|
|
1161 |
|
my $feed_entry = XML::Feed::Entry->new($type); |
1162 |
|
$feed_entry->title( "Internal stats" ); |
1163 |
|
$feed_entry->content( |
1164 |
|
'<![CDATA[<pre>' . dump( $_rss ) . '</pre>]]>' |
1165 |
|
); |
1166 |
|
$feed->add_entry( $feed_entry ); |
1167 |
|
|
1168 |
} else { |
} else { |
1169 |
warn "!! unknown rss request for $show\n"; |
_log "unknown rss request ",$request->url; |
1170 |
return RC_DENY; |
return RC_DENY; |
1171 |
} |
} |
1172 |
|
|
1178 |
warn "$@"; |
warn "$@"; |
1179 |
} |
} |
1180 |
|
|
1181 |
$response->content_type("text/html; charset=$ENCODING"); |
$response->content_type("text/html; charset=UTF-8"); |
1182 |
|
|
1183 |
my $html = |
my $html = |
1184 |
qq{<html><head><title>$NICK</title><style type="text/css">$style} |
qq{<html><head><title>$NICK</title><style type="text/css">$style} |
1229 |
} |
} |
1230 |
$cal->setcontent($dd, qq[ |
$cal->setcontent($dd, qq[ |
1231 |
<a href="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
<a href="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
1232 |
]); |
]) if $cal; |
1233 |
|
|
1234 |
} |
} |
1235 |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |