112 |
# confess "fatal error"; |
# confess "fatal error"; |
113 |
#}; |
#}; |
114 |
|
|
|
open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!"; |
|
|
|
|
115 |
sub _log { |
sub _log { |
116 |
print strftime($TIMESTAMP,localtime()) . ' ' . join(" ",@_) . $/; |
print strftime($TIMESTAMP,localtime()) . ' ' . join(" ",map { ref($_) ? dump( $_ ) : $_ } @_) . $/; |
117 |
} |
} |
118 |
|
|
119 |
|
open(STDOUT, '>', $log_path) && warn "log to $log_path: $!\n"; |
120 |
|
|
121 |
# HTML formatters |
# HTML formatters |
122 |
|
|
123 |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
665 |
return; |
return; |
666 |
} |
} |
667 |
|
|
668 |
|
$_stat->{rss}->{url2link}->{ $args->{url} } = $feed->link; |
669 |
|
|
670 |
my ( $total, $updates ) = ( 0, 0 ); |
my ( $total, $updates ) = ( 0, 0 ); |
671 |
for my $entry ($feed->entries) { |
for my $entry ($feed->entries) { |
672 |
$total++; |
$total++; |
701 |
if ( my $tags = $entry->category ) { |
if ( my $tags = $entry->category ) { |
702 |
$tags =~ s!^\s+!!; |
$tags =~ s!^\s+!!; |
703 |
$tags =~ s!\s*$! !; |
$tags =~ s!\s*$! !; |
704 |
$tags =~ s!\s+!// !g; |
$tags =~ s!,?\s+!// !g; |
705 |
$msg .= prefix( ' ' , $tags ); |
$msg .= prefix( ' ' , $tags ); |
706 |
} |
} |
707 |
|
|
957 |
} |
} |
958 |
} elsif ($msg =~ m/^rss-update/) { |
} elsif ($msg =~ m/^rss-update/) { |
959 |
$res = rss_fetch_all( $_[KERNEL] ); |
$res = rss_fetch_all( $_[KERNEL] ); |
|
} elsif ($msg =~ m/^rss-clean/) { |
|
|
$_stat->{rss} = undef; |
|
|
$dbh->do( qq{ update feeds set last_update = now() - delay } ); |
|
|
$res = "OK, cleaned RSS cache"; |
|
960 |
} elsif ($msg =~ m/^rss-list/) { |
} elsif ($msg =~ m/^rss-list/) { |
961 |
my $sth = $dbh->prepare(qq{ select url,name,last_update,active,channel,nick,private from feeds }); |
my $sth = $dbh->prepare(qq{ select url,name,last_update,active,channel,nick,private from feeds }); |
962 |
$sth->execute; |
$sth->execute; |
964 |
$_[KERNEL]->post( $irc => privmsg => $nick, join(' | ',@row) ); |
$_[KERNEL]->post( $irc => privmsg => $nick, join(' | ',@row) ); |
965 |
} |
} |
966 |
$res = ''; |
$res = ''; |
967 |
} elsif ($msg =~ m!^rss-(add|remove|stop|start)(?:-(private))?\s+(http://\S+)\s*(.*)!) { |
} elsif ($msg =~ m!^rss-(add|remove|stop|start|clean)(?:-(private))?\s+(http://\S+)\s*(.*)!) { |
968 |
my ( $command, $sub, $url, $arg ) = ( $1,$2,$3,$4 ); |
my ( $command, $sub, $url, $arg ) = ( $1,$2,$3,$4 ); |
969 |
|
|
970 |
my $channel = $1 if ( $arg =~ s/\s*(#\S+)\s*// ); |
my $channel = $1 if ( $arg =~ s/\s*(#\S+)\s*// ); |
975 |
# remove => qq{ delete from feeds where url = ? and name = ? }, |
# remove => qq{ delete from feeds where url = ? and name = ? }, |
976 |
start => qq{ update feeds set active = true where url = ? }, |
start => qq{ update feeds set active = true where url = ? }, |
977 |
stop => qq{ update feeds set active = false where url = ? }, |
stop => qq{ update feeds set active = false where url = ? }, |
978 |
|
clean => qq{ update feeds set last_update = now() - delay where url = ? }, |
979 |
}; |
}; |
980 |
|
|
981 |
if ( $command eq 'add' && ! $channel ) { |
if ( $command eq 'add' && ! $channel ) { |
991 |
if ($@) { |
if ($@) { |
992 |
$res = "ERROR: $@"; |
$res = "ERROR: $@"; |
993 |
} else { |
} else { |
994 |
$res = "OK, RSS [$command|$sub|$url|$arg]"; |
$res = "OK, RSS executed $command " . ( $sub ? "-$sub" : '' ) ."on $channel url $url"; |
995 |
|
if ( $command eq 'clean' ) { |
996 |
|
my $seen = $_stat->{rss}->{seen} || die "no seen?"; |
997 |
|
my $want_link = $_stat->{rss}->{url2link}->{$url} || warn "no url2link($url)"; |
998 |
|
foreach my $c ( keys %$seen ) { |
999 |
|
my $c_hash = $seen->{$c} || die "no seen->{$c}"; |
1000 |
|
die "not HASH with rss links but ", dump($c_hash) unless ref($c_hash) eq 'HASH'; |
1001 |
|
foreach my $link ( keys %$c_hash ) { |
1002 |
|
next unless $link eq $want_link; |
1003 |
|
_log "RSS removed seen $c $url $link"; |
1004 |
|
} |
1005 |
|
} |
1006 |
|
} |
1007 |
} |
} |
1008 |
} else { |
} else { |
1009 |
$res = "ERROR: don't know what to do with: $msg"; |
$res = "ERROR: don't know what to do with: $msg"; |
1010 |
} |
} |
1011 |
|
} elsif ($msg =~ m/^rss-clean/) { |
1012 |
|
# this makes sense because we didn't catch rss-clean http://... before! |
1013 |
|
$_stat->{rss} = undef; |
1014 |
|
$dbh->do( qq{ update feeds set last_update = now() - delay } ); |
1015 |
|
$res = "OK, cleaned RSS cache"; |
1016 |
} |
} |
1017 |
|
|
1018 |
if ($res) { |
if ($res) { |
1064 |
$_[KERNEL]->post( $irc => connect => {} ); |
$_[KERNEL]->post( $irc => connect => {} ); |
1065 |
}, |
}, |
1066 |
irc_notice => sub { |
irc_notice => sub { |
1067 |
_log "<< notice",$_[ARG0],dump($_[ARG1]); |
_log "<< notice from ", $_[ARG0], $_[ARG1], $_[ARG2]; |
1068 |
if ( $_[ARG0] =~ m!/msg\s+NickServ\s+IDENTIFY!i ) { |
my $m = $_[ARG2]; |
1069 |
_log ">> IDENTIFY"; |
if ( $m =~ m!/msg.*(NickServ).*(IDENTIFY)!i ) { |
1070 |
|
_log ">> suggested to $1 $2"; |
1071 |
|
$_[KERNEL]->post( $irc => privmsg => $1, "$2 $NICK" ); |
1072 |
|
} elsif ( $m =~ m!\Q$NICK\E.*registered!i ) { |
1073 |
|
_log ">> registreted, so IDENTIFY"; |
1074 |
$_[KERNEL]->post( $irc => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
$_[KERNEL]->post( $irc => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
1075 |
|
} else { |
1076 |
|
warn "## ignore $m\n"; |
1077 |
} |
} |
1078 |
}, |
}, |
1079 |
irc_snotice => sub { |
irc_snotice => sub { |
1080 |
_log "<< snotice",$_[ARG0]; |
_log "<< snotice", $_[ARG0]; #dump( $_[ARG0],$_[ARG1], $_[ARG2] ); |
1081 |
if ( $_[ARG0] =~ m!/(QUOTE)\s+(PASS\s+\d+)!i ) { |
if ( $_[ARG0] =~ m!/(QUOTE)\s+(PASS\s+\d+)!i ) { |
1082 |
warn ">> $1 | $2\n"; |
warn ">> $1 | $2\n"; |
1083 |
$_[KERNEL]->post( $irc => lc($1) => $2); |
$_[KERNEL]->post( $irc => lc($1) => $2); |