178 |
name text, |
name text, |
179 |
delay interval not null default '5 min', |
delay interval not null default '5 min', |
180 |
active boolean default true, |
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()', |
last_update timestamp default 'now()', |
185 |
polls int default 0, |
polls int default 0, |
186 |
updates int default 0 |
updates int default 0 |
187 |
); |
); |
188 |
create unique index feeds_url on feeds(url); |
create unique index feeds_url on feeds(url); |
189 |
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'); |
190 |
}, |
}, |
191 |
}; |
}; |
192 |
|
|
636 |
$total++; |
$total++; |
637 |
|
|
638 |
# seen allready? |
# seen allready? |
639 |
next if $_rss->{$feed->link}->{seen}->{$entry->id}++ > 0; |
next if $_rss->{$args->{channel}}->{$feed->link}->{$entry->id}++ > 0; |
640 |
|
|
641 |
sub prefix { |
sub prefix { |
642 |
my ($txt,$var) = @_; |
my ($txt,$var) = @_; |
666 |
|
|
667 |
if ( $args->{kernel} && $send_rss_msgs ) { |
if ( $args->{kernel} && $send_rss_msgs ) { |
668 |
$send_rss_msgs--; |
$send_rss_msgs--; |
669 |
_log('>>', $msg); |
$sth_insert_log->execute( $args->{channel}, 1, $NICK, $msg, 'now()' ); |
670 |
$sth_insert_log->execute( $CHANNEL, 1, $NICK, $msg, 'now()' ); |
my ( $type, $to ) = ( 'notice', $args->{channel} ); |
671 |
$args->{kernel}->post( $IRC_ALIAS => notice => $CHANNEL, $msg ); |
( $type, $to ) = ( 'privmsg', $args->{nick} ) if $args->{private}; |
672 |
|
_log(">> $type $to |", $msg); |
673 |
|
$args->{kernel}->post( $IRC_ALIAS => $type => $to, $msg ); |
674 |
$updates++; |
$updates++; |
675 |
} |
} |
676 |
} |
} |
688 |
sub rss_fetch_all { |
sub rss_fetch_all { |
689 |
my $kernel = shift; |
my $kernel = shift; |
690 |
my $sql = qq{ |
my $sql = qq{ |
691 |
select id, url, name |
select id, url, name, channel, nick, private |
692 |
from feeds |
from feeds |
693 |
where active is true |
where active is true |
694 |
}; |
}; |
919 |
$dbh->do( qq{ update feeds set last_update = now() - delay } ); |
$dbh->do( qq{ update feeds set last_update = now() - delay } ); |
920 |
$res = "OK, cleaned RSS cache"; |
$res = "OK, cleaned RSS cache"; |
921 |
} elsif ($msg =~ m/^rss-list/) { |
} elsif ($msg =~ m/^rss-list/) { |
922 |
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 }); |
923 |
$sth->execute; |
$sth->execute; |
924 |
while (my @row = $sth->fetchrow_array) { |
while (my @row = $sth->fetchrow_array) { |
925 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, join(' | ',@row) ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, join(' | ',@row) ); |
926 |
} |
} |
927 |
$res = ''; |
$res = ''; |
928 |
} 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*(.*)!) { |
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 = { |
my $sql = { |
935 |
add => qq{ insert into feeds (url,name) values (?,?) }, |
add => qq{ insert into feeds (url,name,channel,nick,private) values (?,?,?,?,?) }, |
936 |
# remove => qq{ delete from feeds where url = ? and name = ? }, |
# remove => qq{ delete from feeds where url = ? and name = ? }, |
937 |
start => qq{ update feeds set active = true where url = ? }, |
start => qq{ update feeds set active = true where url = ? }, |
938 |
stop => qq{ update feeds set active = false where url = ? }, |
stop => qq{ update feeds set active = false where url = ? }, |
939 |
}; |
}; |
940 |
if (my $q = $sql->{$1} ) { |
|
941 |
|
if (my $q = $sql->{$command} ) { |
942 |
my $sth = $dbh->prepare( $q ); |
my $sth = $dbh->prepare( $q ); |
943 |
my @data = ( $2 ); |
my @data = ( $url ); |
944 |
push @data, $3 if ( $q =~ s/\?//g == 2 ); |
if ( $command eq 'add' ) { |
945 |
warn "## $1 SQL $q with ",dump( @data ),"\n"; |
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 ) }; |
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 |
|
|
|
$res = "OK, RSS $1 : $2 - $3"; |
|
958 |
} |
} |
959 |
|
|
960 |
if ($res) { |
if ($res) { |
1158 |
$feed->add_entry( $feed_entry ); |
$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 |
_log "unknown rss request ",$request->url; |
_log "unknown rss request ",$request->url; |
1170 |
return RC_DENY; |
return RC_DENY; |