55 |
|
|
56 |
# don't pull rss feeds more often than this |
# don't pull rss feeds more often than this |
57 |
my $rss_min_delay = 60; |
my $rss_min_delay = 60; |
|
$rss_min_delay = 15; |
|
58 |
|
|
59 |
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000; |
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000; |
60 |
|
|
227 |
if ( $@ || ! $sth->rows ) { |
if ( $@ || ! $sth->rows ) { |
228 |
$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()) }); |
229 |
$sth->execute( $value, $nick, $channel, $name ); |
$sth->execute( $value, $nick, $channel, $name ); |
230 |
_log "created $nick/$channel/$name = $value"; |
warn "## created $nick/$channel/$name = $value\n"; |
231 |
} else { |
} else { |
232 |
_log "updated $nick/$channel/$name = $value "; |
warn "## updated $nick/$channel/$name = $value\n"; |
233 |
} |
} |
234 |
|
|
235 |
return $value; |
return $value; |
239 |
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 = ? }); |
240 |
$sth->execute( $nick, $channel, $name ); |
$sth->execute( $nick, $channel, $name ); |
241 |
my ($v,$c) = $sth->fetchrow_array; |
my ($v,$c) = $sth->fetchrow_array; |
242 |
_log "fetched $nick/$channel/$name = $v [$c]"; |
warn "## fetched $nick/$channel/$name = $v [$c]\n"; |
243 |
return ($v,$c) if wantarray; |
return ($v,$c) if wantarray; |
244 |
return $v; |
return $v; |
245 |
|
|
637 |
|
|
638 |
sub prefix { |
sub prefix { |
639 |
my ($txt,$var) = @_; |
my ($txt,$var) = @_; |
640 |
|
$var =~ s/\s+/ /gs; |
641 |
$var =~ s/^\s+//g; |
$var =~ s/^\s+//g; |
642 |
|
$var =~ s/\s+$//g; |
643 |
return $txt . $var if $var; |
return $txt . $var if $var; |
644 |
} |
} |
645 |
|
|
646 |
|
# fix absolute and relative links to feed entries |
647 |
|
my $link = $entry->link; |
648 |
|
if ( $link =~ m!^/! ) { |
649 |
|
my $host = $args->{url}; |
650 |
|
$host =~ s!^(http://[^/]+).*$!$1!; #!vim |
651 |
|
$link = "$host/$link"; |
652 |
|
} elsif ( $link !~ m!^http! ) { |
653 |
|
$link = $args->{url} . $link; |
654 |
|
} |
655 |
|
$link =~ s!//+!/!g; |
656 |
|
|
657 |
my $msg; |
my $msg; |
658 |
$msg .= prefix( 'From: ' , $args->{name} || $feed->title ); |
$msg .= prefix( 'From: ' , $args->{name} || $feed->title ); |
659 |
$msg .= prefix( ' by ' , $entry->author ); |
$msg .= prefix( ' by ' , $entry->author ); |
660 |
$msg .= prefix( ' | ' , $entry->title ); |
$msg .= prefix( ' | ' , $entry->title ); |
661 |
$msg .= prefix( ' | ' , $entry->link ); |
$msg .= prefix( ' | ' , $link ); |
662 |
# $msg .= prefix( ' id ' , $entry->id ); |
# $msg .= prefix( ' id ' , $entry->id ); |
663 |
|
|
664 |
if ( $args->{kernel} && $send_rss_msgs ) { |
if ( $args->{kernel} && $send_rss_msgs ) { |
703 |
|
|
704 |
sub rss_check_updates { |
sub rss_check_updates { |
705 |
my $kernel = shift; |
my $kernel = shift; |
706 |
my $last_t = $_rss->{last_poll} || time(); |
$_rss->{last_poll} ||= time(); |
707 |
my $t = time(); |
my $dt = time() - $_rss->{last_poll}; |
708 |
if ( $t - $last_t > $rss_min_delay ) { |
warn "## rss_check_updates $dt > $rss_min_delay\n"; |
709 |
$_rss->{last_poll} = $t; |
if ( $dt > $rss_min_delay ) { |
710 |
|
$_rss->{last_poll} = time(); |
711 |
_log rss_fetch_all( $kernel ); |
_log rss_fetch_all( $kernel ); |
712 |
} |
} |
713 |
} |
} |
740 |
|
|
741 |
save_message( channel => $channel, me => 0, nick => $nick, message => $msg); |
save_message( channel => $channel, me => 0, nick => $nick, message => $msg); |
742 |
meta( $nick, $channel, 'last-msg', $msg ); |
meta( $nick, $channel, 'last-msg', $msg ); |
743 |
|
rss_check_updates( $kernel ); |
744 |
}, |
}, |
745 |
irc_ctcp_action => sub { |
irc_ctcp_action => sub { |
746 |
my $kernel = $_[KERNEL]; |
my $kernel = $_[KERNEL]; |
926 |
# remove => qq{ delete from feeds where url = ? and name = ? }, |
# remove => qq{ delete from feeds where url = ? and name = ? }, |
927 |
start => qq{ update feeds set active = true where url = ? }, |
start => qq{ update feeds set active = true where url = ? }, |
928 |
stop => qq{ update feeds set active = false where url = ? }, |
stop => qq{ update feeds set active = false where url = ? }, |
|
|
|
929 |
}; |
}; |
930 |
if (my $q = $sql->{$1} ) { |
if (my $q = $sql->{$1} ) { |
931 |
my $sth = $dbh->prepare( $q ); |
my $sth = $dbh->prepare( $q ); |