summaryrefslogtreecommitdiffstats
path: root/lib/Crawl/Bot/Plugin/Mantis.pm
blob: 4ea2db9a2aad0ef9e7702f7e031293ac4fccdddd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package Crawl::Bot::Plugin::Mantis;
use Moose;
extends 'Crawl::Bot::Plugin';

with 'Crawl::Bot::Role::RSS';

sub rss_feed { 'http://crawl.develz.org/mantis/issues_rss.php' }

sub item_to_id {
    my $self = shift;
    my ($item) = @_;
    my $link = $item->identifier;
    (my $id = $link) =~ s/.*=(\d+)$/$1/;
    return $id;
}

sub tick {
    my $self = shift;
    $self->each_current_item(sub {
        my $item = shift;
        my $id = $self->item_to_id($item);
        return if $self->has_item($id);
        warn "New issue! ($id)";
        (my $title = $item->title) =~ s/\d+: //;
        my $link = $item->link;
        (my $user = $item->creator) =~ s/ <.*?>$//;
        $self->say_all("$title ($link) by $user");
        $self->add_item($id);
    });
    $self->save_item_cache;
}

__PACKAGE__->meta->make_immutable;
no Moose;

1;