| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Games::Lacuna::Task::Action::Vote; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1513
|
use 5.010; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
85
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = $Games::Lacuna::Task::VERSION; |
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
401
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
extends qw(Games::Lacuna::Task::Action); |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $BUILDING_COORDINATES_RE = qr/\(-?\d+,-?\d+\)/; |
|
10
|
|
|
|
|
|
|
our $NAME_RE = qr/[[:space:][:alnum:]]+/; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'accept_proposition' => ( |
|
13
|
|
|
|
|
|
|
isa => 'RegexpRef', |
|
14
|
|
|
|
|
|
|
is => 'rw', |
|
15
|
|
|
|
|
|
|
required => 1, |
|
16
|
|
|
|
|
|
|
documentation => 'Propositions matching this regexp should accepted', |
|
17
|
|
|
|
|
|
|
default => sub { qr/^( |
|
18
|
|
|
|
|
|
|
(Upgrade|Install) \s $NAME_RE |
|
19
|
|
|
|
|
|
|
| |
|
20
|
|
|
|
|
|
|
Demolish \s (Dent|Bleeder) |
|
21
|
|
|
|
|
|
|
| |
|
22
|
|
|
|
|
|
|
Rename \s $NAME_RE |
|
23
|
|
|
|
|
|
|
| |
|
24
|
|
|
|
|
|
|
Repair \s $NAME_RE |
|
25
|
|
|
|
|
|
|
| |
|
26
|
|
|
|
|
|
|
Seize \s $NAME_RE |
|
27
|
|
|
|
|
|
|
| |
|
28
|
|
|
|
|
|
|
Transfer \s Station |
|
29
|
|
|
|
|
|
|
)/xi }, |
|
30
|
|
|
|
|
|
|
); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has 'reject_proposition' => ( |
|
33
|
|
|
|
|
|
|
isa => 'RegexpRef', |
|
34
|
|
|
|
|
|
|
is => 'rw', |
|
35
|
|
|
|
|
|
|
required => 1, |
|
36
|
|
|
|
|
|
|
documentation => 'Propositions matching this regexp should be rejected', |
|
37
|
|
|
|
|
|
|
default => sub { qr//xi }, |
|
38
|
|
|
|
|
|
|
); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub description { |
|
41
|
|
|
|
|
|
|
return q[Parliament voting based on rules]; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub run { |
|
45
|
|
|
|
|
|
|
my ($self) = @_; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
PLANETS: |
|
48
|
|
|
|
|
|
|
foreach my $body_stats ($self->my_stations) { |
|
49
|
|
|
|
|
|
|
$self->log('info',"Processing space station %s",$body_stats->{name}); |
|
50
|
|
|
|
|
|
|
$self->process_space_station($body_stats); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $inbox_object = $self->build_object('Inbox'); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my @trash_messages; |
|
56
|
|
|
|
|
|
|
my $page_number = 1; |
|
57
|
|
|
|
|
|
|
while (1) { |
|
58
|
|
|
|
|
|
|
# Get inbox for parliament |
|
59
|
|
|
|
|
|
|
my $inbox_data = $self->request( |
|
60
|
|
|
|
|
|
|
object => $inbox_object, |
|
61
|
|
|
|
|
|
|
method => 'view_inbox', |
|
62
|
|
|
|
|
|
|
params => [{ tags => ['Parliament'],page_number => $page_number }], |
|
63
|
|
|
|
|
|
|
); |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
MESSAGES: |
|
66
|
|
|
|
|
|
|
foreach my $message (@{$inbox_data->{messages}}) { |
|
67
|
|
|
|
|
|
|
if ($message->{subject} =~ m/^(Pass|Reject):\s+/ |
|
68
|
|
|
|
|
|
|
|| $message->{subject} =~ $self->accept_proposition |
|
69
|
|
|
|
|
|
|
|| $message->{subject} =~ $self->reject_proposition) { |
|
70
|
|
|
|
|
|
|
push(@trash_messages,$message->{id}); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
last |
|
75
|
|
|
|
|
|
|
if scalar(@{$inbox_data->{messages}}) < 25; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$page_number++; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Archive |
|
81
|
|
|
|
|
|
|
if (scalar @trash_messages) { |
|
82
|
|
|
|
|
|
|
$self->log('notice',"Trashing %i messages",scalar @trash_messages); |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$self->request( |
|
85
|
|
|
|
|
|
|
object => $inbox_object, |
|
86
|
|
|
|
|
|
|
method => 'trash_messages', |
|
87
|
|
|
|
|
|
|
params => [\@trash_messages], |
|
88
|
|
|
|
|
|
|
); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub process_space_station { |
|
93
|
|
|
|
|
|
|
my ($self,$station_stats) = @_; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# Get parliament ministry |
|
96
|
|
|
|
|
|
|
my ($parliament) = $self->find_building($station_stats->{id},'Parliament'); |
|
97
|
|
|
|
|
|
|
return |
|
98
|
|
|
|
|
|
|
unless $parliament; |
|
99
|
|
|
|
|
|
|
my $parliament_object = $self->build_object($parliament); |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $proposition_data = $self->request( |
|
102
|
|
|
|
|
|
|
object => $parliament_object, |
|
103
|
|
|
|
|
|
|
method => 'view_propositions', |
|
104
|
|
|
|
|
|
|
); |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
PROPOSITION: |
|
107
|
|
|
|
|
|
|
foreach my $proposition (@{$proposition_data->{propositions}}) { |
|
108
|
|
|
|
|
|
|
next PROPOSITION |
|
109
|
|
|
|
|
|
|
if defined $proposition->{my_vote}; |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my $vote; |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
if ($proposition->{name} =~ $self->accept_proposition) { |
|
114
|
|
|
|
|
|
|
$vote = 1; |
|
115
|
|
|
|
|
|
|
} elsif ($proposition->{name} =~ $self->reject_proposition) { |
|
116
|
|
|
|
|
|
|
$vote = 0; |
|
117
|
|
|
|
|
|
|
} else { |
|
118
|
|
|
|
|
|
|
next PROPOSITION; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
$self->log('notice','Voting %s on proposition %s',($vote ? 'Yes':'No'),$proposition->{name}); |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
$self->request( |
|
124
|
|
|
|
|
|
|
object => $parliament_object, |
|
125
|
|
|
|
|
|
|
method => 'cast_vote', |
|
126
|
|
|
|
|
|
|
params => [$proposition->{id},$vote], |
|
127
|
|
|
|
|
|
|
); |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
133
|
|
|
|
|
|
|
no Moose; |
|
134
|
|
|
|
|
|
|
1; |