Bot-Cobalt-Plugin-RSS

 view release on metacpan or  search on metacpan

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

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  $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

152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
  } 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

272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
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.239 second using v1.01-cache-2.11-cpan-87723dcf8b7 )