#
# Displays messages in status window, unless a window irssi-feed exists
# Add one with /window new hidden /window name irssi-feed
+# If a channel parameter is specified when adding a feed, announces it to a channel.
#
# Command format:
-# /feed {add|set|list|rm} [--uri <address>] [--id <short name>] [--color %<color>] [--newid <new short name>] [--interval <seconds>]
+# /feed {add|set|list|rm} [--uri <address>] [--id <short name>] [--color %<color>] [--newid <new short name>] [--interval <seconds>] [--channel <channel>]
#
# Note: Since XML::Feed's HTTP doesn't support async usage, I implemented an
# an own HTTP client. It won't do anything sensible when redirected and does
);
use Irssi qw(command_bind timeout_add INPUT_READ INPUT_WRITE);
+{ package Irssi::Nick }
+
sub save_config {
our @feeds;
my $str = '';
$str .= " --uri $feed->{uri}";
$str .= " --interval $feed->{configtimeout} " if($feed->{configtimeout});
$str .= " --color $feed->{color} " if($feed->{color});
+ $str .= " --channel $feed->{channel} " if($feed->{channel});
+ $str .= " --servtag $feed->{servtag} " if($feed->{servtag});
$str .= "\n";
}
}
my $feed_uri;
my $feed_timeout = 0;
my $feed_color = 'NOMODIFY';
+ my $feed_channel;
+ my $feed_servtag = $server->{tag};
my $feed_newid;
if(!GetOptionsFromString($args,
'uri=s' => \$feed_uri,
'id=s' => \$feed_id,
'interval=i' => \$feed_timeout,
'color=s' => \$feed_color,
+ 'channel=s' => \$feed_channel,
+ 'servtag=s' => \$feed_servtag,
'newid=s' => \$feed_newid)
) {
feedprint("Could not parse options of $data");
feedprint("Failed to add feed. No uri given.");
} else {
$feed_color = '' if($feed_color eq 'NOMODIFY');
- $feed = feed_new($feed_uri, $feed_timeout, $feed_id, $feed_color);
+ $feed = feed_new($feed_uri, $feed_timeout, $feed_id, $feed_color, $feed_channel, $feed_servtag);
feedprint("Added feed " . feed_stringrepr($feed, 'long')) if($window_item);
save_config();
check_feeds();
$feed->{timeout} = valid_timeout($feed->{configtimeout});
$feed->{uri} = $feed_uri if($feed_uri && $feed_id);
$feed->{color} = $feed_color unless($feed_color eq 'NOMODIFY');
+ $feed->{channel} = $feed_channel if($feed_channel);
+ $feed->{servtag} = $feed_servtag if($feed_servtag);
$feed->{timeout} = $feed_timeout if($feed_timeout);
$feed->{id} = $feed_newid if($feed_newid);
save_config();
}
sub feed_new {
- my $uri = shift;
- my $timeout = shift;
- my $id = shift;
- my $color = shift;
+ my ($uri, $timeout, $id, $color, $channel, $servtag) = @_;
state $nextfid = 1;
my $feed = {
id => $id // "$nextfid",
uri => URI->new($uri),
name => $uri,
color => $color,
+ channel => $channel,
+ servtag => $servtag,
lastcheck => clock_gettime(CLOCK_MONOTONIC) - 86400,
timeout => valid_timeout($timeout), # next actual timeout. Doubled on error
configtimeout => $timeout,
$space =~ s//' ' x ((length $feed->{id}) + 3)/e;
my $titleline = $news->title;
$titleline =~ s/\s*\n\s*/ | /g;
- feedprint('<' . feed_stringrepr($feed) . '> ' . $titleline . "\n" . $space . $news->link, Irssi::MSGLEVEL_PUBLIC);
+ feed_announce_item_print($feed, '<' . feed_stringrepr($feed) . '> ' . $titleline . "\n" . $space . $news->link, Irssi::MSGLEVEL_PUBLIC);
}
sub finished_load_message {
}
}
+sub feed_announce_item_print {
+ my ($feed, $msg) = @_;
+ my $channel = $feed->{channel};
+ my $server = Irssi::server_find_tag( $feed->{servtag} );
+ if($channel) {
+ $server->command("/notice $channel $msg");
+ } else {
+ feedprint($msg);
+ }
+}
+
+
Irssi::command_bind('feed', \&feedreader_cmd);
Irssi::settings_add_str('feedreader', 'feedlist', '');
our $initial_skips = 0;