--- trunk/bin/irc-logger.pl 2008/03/07 15:16:17 96 +++ trunk/bin/irc-logger.pl 2008/03/07 15:49:23 97 @@ -178,12 +178,15 @@ name text, delay interval not null default '5 min', active boolean default true, + channel text not null, + nick text not null, + private boolean default false, last_update timestamp default 'now()', polls int default 0, updates int default 0 ); create unique index feeds_url on feeds(url); -insert into feeds (url,name) values ('http://wiki.razmjenavjestina.org/feed/workspace/razmjenavjestina?category=Recent%20Changes','wiki'); +insert into feeds (url,name,channel,nick) values ('http://wiki.razmjenavjestina.org/feed/workspace/razmjenavjestina?category=Recent%20Changes','wiki','$CHANNEL','dpavlin'); }, }; @@ -633,7 +636,7 @@ $total++; # seen allready? - next if $_rss->{$feed->link}->{seen}->{$entry->id}++ > 0; + next if $_rss->{$args->{channel}}->{$feed->link}->{$entry->id}++ > 0; sub prefix { my ($txt,$var) = @_; @@ -663,9 +666,11 @@ if ( $args->{kernel} && $send_rss_msgs ) { $send_rss_msgs--; - _log('>>', $msg); - $sth_insert_log->execute( $CHANNEL, 1, $NICK, $msg, 'now()' ); - $args->{kernel}->post( $IRC_ALIAS => notice => $CHANNEL, $msg ); + $sth_insert_log->execute( $args->{channel}, 1, $NICK, $msg, 'now()' ); + my ( $type, $to ) = ( 'notice', $args->{channel} ); + ( $type, $to ) = ( 'privmsg', $args->{nick} ) if $args->{private}; + _log(">> $type $to |", $msg); + $args->{kernel}->post( $IRC_ALIAS => $type => $to, $msg ); $updates++; } } @@ -683,7 +688,7 @@ sub rss_fetch_all { my $kernel = shift; my $sql = qq{ - select id, url, name + select id, url, name, channel, nick, private from feeds where active is true }; @@ -914,28 +919,42 @@ $dbh->do( qq{ update feeds set last_update = now() - delay } ); $res = "OK, cleaned RSS cache"; } elsif ($msg =~ m/^rss-list/) { - my $sth = $dbh->prepare(qq{ select url,name,last_update,active from feeds }); + my $sth = $dbh->prepare(qq{ select url,name,last_update,active,channel,nick,private from feeds }); $sth->execute; while (my @row = $sth->fetchrow_array) { $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, join(' | ',@row) ); } $res = ''; - } elsif ($msg =~ m!^rss-(add|remove|stop|start)\s+(http://\S+)\s*(.*)!) { + } elsif ($msg =~ m!^rss-(add|remove|stop|start)(?:-(private))?\s+(http://\S+)\s*(.*)!) { + my ( $command, $sub, $url, $arg ) = ( $1,$2,$3,$4 ); + + my $channel = $1 if ( $arg =~ s/\s*(#\S+)\s*// ); + $channel = $nick if $sub eq 'private'; + my $sql = { - add => qq{ insert into feeds (url,name) values (?,?) }, + add => qq{ insert into feeds (url,name,channel,nick,private) values (?,?,?,?,?) }, # remove => qq{ delete from feeds where url = ? and name = ? }, start => qq{ update feeds set active = true where url = ? }, stop => qq{ update feeds set active = false where url = ? }, }; - if (my $q = $sql->{$1} ) { + + if (my $q = $sql->{$command} ) { my $sth = $dbh->prepare( $q ); - my @data = ( $2 ); - push @data, $3 if ( $q =~ s/\?//g == 2 ); - warn "## $1 SQL $q with ",dump( @data ),"\n"; + my @data = ( $url ); + if ( $command eq 'add' ) { + push @data, ( $arg, $channel, $nick, $sub eq 'private' ? 1 : 0 ); + } + warn "## $command SQL $q with ",dump( @data ),"\n"; eval { $sth->execute( @data ) }; + if ($@) { + $res = "ERROR: $@"; + } else { + $res = "OK, RSS [$command|$sub|$url|$arg]"; + } + } else { + $res = "ERROR: don't know what to do with: $msg"; } - $res = "OK, RSS $1 : $2 - $3"; } if ($res) { @@ -1139,6 +1158,13 @@ $feed->add_entry( $feed_entry ); } + my $feed_entry = XML::Feed::Entry->new($type); + $feed_entry->title( "Internal stats" ); + $feed_entry->content( + '' . dump( $_rss ) . ']]>' + ); + $feed->add_entry( $feed_entry ); + } else { _log "unknown rss request ",$request->url; return RC_DENY;