summaryrefslogtreecommitdiffstats
path: root/lib/Crawl/Bot/Plugin/Mantis.pm
blob: 5498bc961488520370fd21e53a9f56e93e762d16 (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
37
38
39
40
41
42
43
44
45
46
47
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 said {
    my $self = shift;
    my ($args) = @_;
    
    my @keys = (who => $args->{who}, channel => $args->{channel}, "body");

    if ($args->{body} =~ /^%bug (\d+)$/) {
        $self->say(@keys, "https://crawl.develz.org/mantis/view.php?id=$1");
    }
}

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;