Bot-Cobalt-Plugin-RSS
view release on metacpan or search on metacpan
lib/Bot/Cobalt/Plugin/RSS.pm view on Meta::CPAN
697071727374757677787980818283848586878889
$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
152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
}
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
272273274275276277278279280281282283284285286287288289290291my
$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.239 second using v1.01-cache-2.11-cpan-87723dcf8b7 )