line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Lacuna::Task::Report::Inbox; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1633
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
61
|
|
4
|
|
|
|
|
|
|
our $VERSION = $Games::Lacuna::Task::VERSION; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
462
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'archive' => ( |
9
|
|
|
|
|
|
|
is => 'rw', |
10
|
|
|
|
|
|
|
isa => 'RegexpRef', |
11
|
|
|
|
|
|
|
documentation => 'Message subjects matching this pattern will be archived', |
12
|
|
|
|
|
|
|
default => sub { |
13
|
|
|
|
|
|
|
qr/^ ( |
14
|
|
|
|
|
|
|
Trade \s Accepted | |
15
|
|
|
|
|
|
|
Mission \s completed |
16
|
|
|
|
|
|
|
) $/x; |
17
|
|
|
|
|
|
|
}, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'delete' => ( |
21
|
|
|
|
|
|
|
is => 'rw', |
22
|
|
|
|
|
|
|
isa => 'RegexpRef', |
23
|
|
|
|
|
|
|
documentation => 'Message subjects matching this pattern will be deleted', |
24
|
|
|
|
|
|
|
default => sub { |
25
|
|
|
|
|
|
|
qr/^ ( |
26
|
|
|
|
|
|
|
Target \s Neutralized | |
27
|
|
|
|
|
|
|
Glyph \s Discovered! | |
28
|
|
|
|
|
|
|
Control \s Changed \s Hands | |
29
|
|
|
|
|
|
|
Mining \s Platform \s Deployed | |
30
|
|
|
|
|
|
|
Probe \s Detected! | |
31
|
|
|
|
|
|
|
Trade \s Withdrawn | |
32
|
|
|
|
|
|
|
Excavator \s Results | |
33
|
|
|
|
|
|
|
Excavator \s Deployed | |
34
|
|
|
|
|
|
|
Excavator \s Uncovered \s Plan |
35
|
|
|
|
|
|
|
) $/x; |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub report_inbox { |
40
|
|
|
|
|
|
|
my ($self) = @_; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $inbox_object = $self->build_object('Inbox'); |
43
|
|
|
|
|
|
|
my $has_new_messages = $self->get_stash('has_new_messages'); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $page = int($has_new_messages / 25 ) + ( $has_new_messages % 25 ? 1:0); |
46
|
|
|
|
|
|
|
$page //= 1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my (@archive,@delete,%counter,%action); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
PAGES: |
51
|
|
|
|
|
|
|
while ($page > 0) { |
52
|
|
|
|
|
|
|
# Get inbox for attacks |
53
|
|
|
|
|
|
|
my $inbox_data = $self->request( |
54
|
|
|
|
|
|
|
object => $inbox_object, |
55
|
|
|
|
|
|
|
method => 'view_inbox', |
56
|
|
|
|
|
|
|
params => [ { page_number => $page } ], |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
MESSAGES: |
61
|
|
|
|
|
|
|
foreach my $message (@{$inbox_data->{messages}}) { |
62
|
|
|
|
|
|
|
next MESSAGES |
63
|
|
|
|
|
|
|
unless $message->{from_id} == $message->{to_id}; |
64
|
|
|
|
|
|
|
my $subject = $message->{subject}; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
if ($subject =~ $self->delete) { |
67
|
|
|
|
|
|
|
push(@delete,$message->{id}); |
68
|
|
|
|
|
|
|
$action{$subject} = 'delete'; |
69
|
|
|
|
|
|
|
} elsif ($subject =~ $self->archive) { |
70
|
|
|
|
|
|
|
push(@archive,$message->{id}); |
71
|
|
|
|
|
|
|
$action{$subject} = 'archive'; |
72
|
|
|
|
|
|
|
} else { |
73
|
|
|
|
|
|
|
next MESSAGES |
74
|
|
|
|
|
|
|
if $message->{has_read}; |
75
|
|
|
|
|
|
|
$action{$subject} = 'keep'; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$counter{$subject} ||= 0; |
79
|
|
|
|
|
|
|
$counter{$subject} ++; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$page --; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $empire_name = $self->empire_name; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $table = Games::Lacuna::Task::Table->new( |
88
|
|
|
|
|
|
|
headline=> 'Inbox Digest', |
89
|
|
|
|
|
|
|
columns => ['Subject','Count','Action'], |
90
|
|
|
|
|
|
|
); |
91
|
|
|
|
|
|
|
while (my ($subject,$count) = each %counter) { |
92
|
|
|
|
|
|
|
$table->add_row({ |
93
|
|
|
|
|
|
|
subject => $subject, |
94
|
|
|
|
|
|
|
count => $count, |
95
|
|
|
|
|
|
|
action => $action{$subject}, |
96
|
|
|
|
|
|
|
}); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
if (scalar @archive) { |
100
|
|
|
|
|
|
|
$self->log('debug','Archiveing %i messages',(scalar @archive)); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$self->request( |
103
|
|
|
|
|
|
|
object => $inbox_object, |
104
|
|
|
|
|
|
|
method => 'archive_messages', |
105
|
|
|
|
|
|
|
params => [\@archive], |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
if (scalar @delete) { |
110
|
|
|
|
|
|
|
$self->log('debug','Deleting %i messages',(scalar @delete)); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$self->request( |
113
|
|
|
|
|
|
|
object => $inbox_object, |
114
|
|
|
|
|
|
|
method => 'trash_messages', |
115
|
|
|
|
|
|
|
params => [\@delete], |
116
|
|
|
|
|
|
|
); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
return $table; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
no Moose::Role; |
123
|
|
|
|
|
|
|
1; |