Bot-Cobalt-Plugin-RSS
view release on metacpan or search on metacpan
lib/Bot/Cobalt/Plugin/RSS.pm view on Meta::CPAN
$p_heap->{$feedname} = {
hasrun => 0,
url => $url,
delay => $delay,
space => $spacing,
};
## Can create our XML::RSS:Feed now (requires proper hash above):
$p_heap->{obj} = $self->_create_feed($feedname);
## add to timer pool
my $pool = $self->pending;
$pool->{$feedname} = {
LastRun => 0,
};
return $feedname
}
sub list_feed_names {
## list_feed_names()
lib/Bot/Cobalt/Plugin/RSS.pm view on Meta::CPAN
} else {
logger->warn(
"There are no RSS feeds configured; doing nothing.",
"You may want to inspect this plugin's Config: file.",
"See perldoc Bot::Cobalt::Plugin::RSS",
);
}
register( $self, 'SERVER',
[
'executed_timer',
'rssplug_check_timer_pool',
'rssplug_got_resp',
],
);
$self->{POOLTIMERID} = $core->timer_set( 6,
{ Event => 'rssplug_check_timer_pool' }
);
my $count = $self->list_feed_names;
logger->info("Loaded - $VERSION - watching $count feeds");
return PLUGIN_EAT_NONE
}
sub Cobalt_unregister {
my ($self, $core) = splice @_, 0, 2;
$core->timer_del($self->{POOLTIMERID});
$core->timer_del($_) for keys %{$self->{MSGTIMERS}};
delete $self->{HEAP};
logger->info("Unloaded");
return PLUGIN_EAT_NONE
}
sub Bot_executed_timer {
my ($self, $core) = splice @_, 0, 2;
my $id = ${ $_[0] };
delete $self->{MSGTIMERS}->{$id};
return PLUGIN_EAT_NONE
}
sub Bot_rssplug_check_timer_pool {
my ($self, $core) = splice @_, 0, 2;
my $pool = $self->pending;
## check timestamps on pool (keyed on name)
## if ts is up, execute _request, schedule new
for my $feedname (keys %$pool) {
my $feedmeta = $self->get_feed_meta($feedname)
|| return PLUGIN_EAT_NONE;
my $thistimer = $pool->{$feedname};
my $lastts = $thistimer->{LastRun} || 0;
my $delay = $feedmeta->{delay};
if (time - $lastts >= $delay) {
$self->_request($feedname);
$thistimer->{LastRun} = time;
}
}
$self->{POOLTIMERID} = $core->timer_set( 3,
{ Event => 'rssplug_check_timer_pool' }
);
return PLUGIN_EAT_NONE
}
sub Bot_rssplug_got_resp {
my ($self, $core) = splice @_, 0, 2;
my $response = ${ $_[1] };
my $args = ${ $_[2] };
my ($feedname) = @$args;
lib/Bot/Cobalt/Plugin/RSS.pm view on Meta::CPAN
my $this_line = $headline->headline;
my $this_url = $headline->url;
my $str = "RSS: "
.color('bold', $name)
.": $this_line ( $this_url )" ;
CONTEXT: for my $context (keys %$a_heap) {
my $irc = irc_object($context) || next CONTEXT;
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;
}
( run in 0.597 second using v1.01-cache-2.11-cpan-49f99fa48dc )