Bot-Cobalt-Plugin-RSS

 view release on metacpan or  search on metacpan

lib/Bot/Cobalt/Plugin/RSS.pm  view on Meta::CPAN

      
      for my $channel ( @{ $a_heap->{$context} } ) {
        my $tid = core()->timer_set( 1 + $spcount,
          {
           Type => 'msg',
           Context => $context,
           Target  => $channel,
           Text    => $str,
          },
        );
        $self->{MSGTIMERS}->{$tid} = $name;
      }

    } ## CONTEXT

    $spcount += $spacing;

  } ## HEAD
}

sub _create_feed {
  ## _create_feed($name)
  ## create (and return) new XML::RSS::Feed based on get_feed_meta
  my ($self, $feedname) = @_;

  my $feedmeta = $self->get_feed_meta($feedname);

  my %feedopts = (
    name => $feedname,
    url  => $feedmeta->{url},
    delay  => $feedmeta->{delay},
    init_headlines_seen => 0,

    ## tmpdir caching seems to result in memory leaks:
    # tmpdir => File::Spec->tmpdir(),
  );
  
  if ( my $rss = XML::RSS::Feed->new(%feedopts) ) {
    $feedmeta->{obj} = $rss;
  } else {
    logger->warn(
      "Could not create XML::RSS::Feed obj for $feedname"
    );
  }
  
  return $feedmeta->{obj}  
}

sub _request {
  my ($self, $feedname) = @_;

  my $feedmeta = $self->get_feed_meta($feedname);
  
  unless (core()->Provided->{www_request}) {
    logger->warn("You seem to be missing Bot::Cobalt::Plugin::WWW!");
    return PLUGIN_EAT_NONE
  }

  ## send request tagged w/ feedname  
  my $url = $feedmeta->{url};
  my $req = HTTP::Request->new( 'GET', $url );
  broadcast( 'www_request',
    $req,
    'rssplug_got_resp',
    [ $feedname ],
  );
  
  return 1
}

1;
__END__

=pod

=head1 NAME

Bot::Cobalt::Plugin::RSS - Monitor RSS feeds via IRC

=head1 SYNOPSIS

  ## In plugins.conf:
  RSS:
    Module: Bot::Cobalt::Plugin::RSS
    Config: plugins/rss.conf

  ## Requires properly configured rss.conf
  !plugin load RSS

=head1 DESCRIPTION

A L<Bot::Cobalt> plugin.

Monitors an arbitrary number of RSS feeds, reporting new headlines to
configured contexts/channels.

Uses L<XML::RSS::Feed> to track and parse feeds.

=head1 EXAMPLE CONF

An example configuration file can be installed via the L<Bot::Cobalt> 
tool C<cobalt2-plugin-installcf>:

  $ cobalt2-plugin-installcf --plugin="Bot::Cobalt::Plugin::RSS" \
      --dest="cobalt2/etc/plugins/rss.conf"

If you'd rather write one manually, it might look something like this:

  ---
  ## example etc/plugins/rss.conf
  Feeds:
    MyFeed:
      URL: 'http://rss.slashdot.org/Slashdot/slashdot'
      Delay: 300
      ## If your feed publishes a lot in one go, add delays (sec):
      Spaced: 30
      AnnounceTo:
        Main:
          - '#eris'
          - '#otw'



( run in 1.407 second using v1.01-cache-2.11-cpan-5b529ec07f3 )