mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-24 11:42:35 +01:00
Spinach: add keep
command to vote to prevent question from being skipped
This commit is contained in:
parent
f8d8cac7d4
commit
f7825b996e
@ -225,7 +225,7 @@ sub spinach_cmd {
|
|||||||
my ($self, $from, $nick, $user, $host, $arguments) = @_;
|
my ($self, $from, $nick, $user, $host, $arguments) = @_;
|
||||||
$arguments =~ s/^\s+|\s+$//g;
|
$arguments =~ s/^\s+|\s+$//g;
|
||||||
|
|
||||||
my $usage = "Usage: spinach join|exit|ready|unready|choose|lie|reroll|skip|score|show|rank|categories|filter|set|unset|kick|abort; for more information about a command: spinach help <command>";
|
my $usage = "Usage: spinach join|exit|ready|unready|choose|lie|reroll|skip|keep|score|show|rank|categories|filter|set|unset|kick|abort; for more information about a command: spinach help <command>";
|
||||||
|
|
||||||
my $command;
|
my $command;
|
||||||
($command, $arguments) = split / /, $arguments, 2;
|
($command, $arguments) = split / /, $arguments, 2;
|
||||||
@ -256,6 +256,10 @@ sub spinach_cmd {
|
|||||||
return "Use `skip` to skip a question and return to the \"choose category\" stage. A majority of the players must agree to skip.";
|
return "Use `skip` to skip a question and return to the \"choose category\" stage. A majority of the players must agree to skip.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
when ('keep') {
|
||||||
|
return "Use `keep` to vote to prevent the current question from being rerolled or skipped.";
|
||||||
|
}
|
||||||
|
|
||||||
when ('abort') {
|
when ('abort') {
|
||||||
return "Help is coming soon.";
|
return "Help is coming soon.";
|
||||||
}
|
}
|
||||||
@ -558,13 +562,17 @@ sub spinach_cmd {
|
|||||||
|
|
||||||
my $player;
|
my $player;
|
||||||
my $rerolled = 0;
|
my $rerolled = 0;
|
||||||
|
my $keep;
|
||||||
foreach my $i (@{$self->{state_data}->{players}}) {
|
foreach my $i (@{$self->{state_data}->{players}}) {
|
||||||
if ($i->{id} == $id) {
|
if ($i->{id} == $id) {
|
||||||
$i->{reroll} = 1;
|
$i->{reroll} = 1;
|
||||||
|
delete $i->{keep};
|
||||||
$rerolled++;
|
$rerolled++;
|
||||||
$player = $i;
|
$player = $i;
|
||||||
} elsif ($i->{reroll}) {
|
} elsif ($i->{reroll}) {
|
||||||
$rerolled++;
|
$rerolled++;
|
||||||
|
} elsif ($i->{keep}) {
|
||||||
|
$keep++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -574,6 +582,7 @@ sub spinach_cmd {
|
|||||||
|
|
||||||
my $needed = int (@{$self->{state_data}->{players}} / 2) + 1;
|
my $needed = int (@{$self->{state_data}->{players}} / 2) + 1;
|
||||||
$needed -= $rerolled;
|
$needed -= $rerolled;
|
||||||
|
$needed += $keep;
|
||||||
|
|
||||||
my $votes_needed;
|
my $votes_needed;
|
||||||
if ($needed == 1) {
|
if ($needed == 1) {
|
||||||
@ -596,13 +605,17 @@ sub spinach_cmd {
|
|||||||
|
|
||||||
my $player;
|
my $player;
|
||||||
my $skipped = 0;
|
my $skipped = 0;
|
||||||
|
my $keep = 0;
|
||||||
foreach my $i (@{$self->{state_data}->{players}}) {
|
foreach my $i (@{$self->{state_data}->{players}}) {
|
||||||
if ($i->{id} == $id) {
|
if ($i->{id} == $id) {
|
||||||
$i->{skip} = 1;
|
$i->{skip} = 1;
|
||||||
|
delete $i->{keep};
|
||||||
$skipped++;
|
$skipped++;
|
||||||
$player = $i;
|
$player = $i;
|
||||||
} elsif ($i->{skip}) {
|
} elsif ($i->{skip}) {
|
||||||
$skipped++;
|
$skipped++;
|
||||||
|
} elsif ($i->{keep}) {
|
||||||
|
$keep++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,6 +625,7 @@ sub spinach_cmd {
|
|||||||
|
|
||||||
my $needed = int (@{$self->{state_data}->{players}} / 2) + 1;
|
my $needed = int (@{$self->{state_data}->{players}} / 2) + 1;
|
||||||
$needed -= $skipped;
|
$needed -= $skipped;
|
||||||
|
$needed += $keep;
|
||||||
|
|
||||||
my $votes_needed;
|
my $votes_needed;
|
||||||
if ($needed == 1) {
|
if ($needed == 1) {
|
||||||
@ -628,6 +642,31 @@ sub spinach_cmd {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
when ('keep') {
|
||||||
|
if ($self->{current_state} =~ /getlies$/) {
|
||||||
|
my $id = $self->{pbot}->{messagehistory}->{database}->get_message_account($nick, $user, $host);
|
||||||
|
|
||||||
|
my $player;
|
||||||
|
foreach my $i (@{$self->{state_data}->{players}}) {
|
||||||
|
if ($i->{id} == $id) {
|
||||||
|
$i->{keep} = 1;
|
||||||
|
delete $i->{skip};
|
||||||
|
delete $i->{reroll};
|
||||||
|
$player = $i;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not $player) {
|
||||||
|
return "$nick: You are not playing in this game. Use `j` to start playing now!";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "/msg $self->{channel} $color{green}$nick has voted to keep playing the current question!";
|
||||||
|
} else {
|
||||||
|
return "$nick: This command can be used only during the \"submit lies\" stage.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
when ($_ eq 'lie' or $_ eq 'truth' or $_ eq 'choose') {
|
when ($_ eq 'lie' or $_ eq 'truth' or $_ eq 'choose') {
|
||||||
$arguments = lc $arguments;
|
$arguments = lc $arguments;
|
||||||
if ($self->{current_state} =~ /choosecategory$/) {
|
if ($self->{current_state} =~ /choosecategory$/) {
|
||||||
@ -1693,6 +1732,7 @@ sub getnewquestion {
|
|||||||
delete $player->{deceived};
|
delete $player->{deceived};
|
||||||
delete $player->{skip};
|
delete $player->{skip};
|
||||||
delete $player->{reroll};
|
delete $player->{reroll};
|
||||||
|
delete $player->{keep};
|
||||||
}
|
}
|
||||||
$state->{current_choices_text} = "";
|
$state->{current_choices_text} = "";
|
||||||
return 'next';
|
return 'next';
|
||||||
@ -1734,15 +1774,27 @@ sub getlies {
|
|||||||
|
|
||||||
return 'next' if not @nolies;
|
return 'next' if not @nolies;
|
||||||
|
|
||||||
|
my @keeps;
|
||||||
my @rerolls;
|
my @rerolls;
|
||||||
|
my @skips;
|
||||||
foreach my $player (@{$state->{players}}) {
|
foreach my $player (@{$state->{players}}) {
|
||||||
if ($player->{reroll}) {
|
if ($player->{reroll}) {
|
||||||
push @rerolls, $player->{name};
|
push @rerolls, $player->{name};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($player->{skip}) {
|
||||||
|
push @skips, $player->{name};
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($player->{keep}) {
|
||||||
|
push @keeps, $player->{name};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (@rerolls) {
|
|
||||||
my $needed = int (@{$state->{players}} / 2) + 1;
|
my $needed = int (@{$state->{players}} / 2) + 1;
|
||||||
|
$needed += @keeps;
|
||||||
|
|
||||||
|
if (@rerolls) {
|
||||||
$needed -= @rerolls;
|
$needed -= @rerolls;
|
||||||
if ($needed <= 0) {
|
if ($needed <= 0) {
|
||||||
$state->{reroll_question} = 1;
|
$state->{reroll_question} = 1;
|
||||||
@ -1750,13 +1802,6 @@ sub getlies {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my @skips;
|
|
||||||
foreach my $player (@{$state->{players}}) {
|
|
||||||
if ($player->{skip}) {
|
|
||||||
push @skips, $player->{name};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (@skips) {
|
if (@skips) {
|
||||||
my $needed = int (@{$state->{players}} / 2) + 1;
|
my $needed = int (@{$state->{players}} / 2) + 1;
|
||||||
$needed -= @skips;
|
$needed -= @skips;
|
||||||
|
Loading…
Reference in New Issue
Block a user