mirror of
https://github.com/pragma-/pbot.git
synced 2025-02-02 15:34:05 +01:00
Quality of life improvements
`lie`, `truth` and `choose` can now all be use interchangibly regardless of game state. No more needing to switch between commands. `players` and `score` can now both be used interchangibly and will do the right thing depending on game state. `ready` and `unready` are now more game-state aware.
This commit is contained in:
parent
e2f9810d91
commit
5ebb84c18b
@ -201,7 +201,7 @@ sub spinach_cmd {
|
||||
$arguments = lc $arguments;
|
||||
$arguments =~ s/^\s+|\s+$//g;
|
||||
|
||||
my $usage = "Usage: spinach start|stop|abort|join|exit|ready|unready|players|kick|choose|lie|truth|score|show; for more information about a command: spinach help <command>";
|
||||
my $usage = "Usage: spinach start|stop|abort|join|exit|ready|unready|players|kick|choose|lie|score|show; for more information about a command: spinach help <command>";
|
||||
|
||||
my $command;
|
||||
($command, $arguments) = split / /, $arguments, 2;
|
||||
@ -306,20 +306,6 @@ sub spinach_cmd {
|
||||
return "Coming soon.";
|
||||
}
|
||||
|
||||
when ('score') {
|
||||
if (not @{$self->{state_data}->{players}}) {
|
||||
return "There is nobody playing right now.";
|
||||
}
|
||||
|
||||
my $text = '';
|
||||
my $comma = '';
|
||||
foreach my $player (sort { $b->{score} <=> $a->{score} } @{$self->{state_data}->{players}}) {
|
||||
$text .= "$comma$player->{name}: $player->{score}";
|
||||
$comma = '; ';
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
when ('join') {
|
||||
if ($self->{current_state} eq 'nogame') {
|
||||
$self->{current_state} = 'getplayers';
|
||||
@ -340,23 +326,25 @@ sub spinach_cmd {
|
||||
}
|
||||
|
||||
when ('ready') {
|
||||
if ($self->{current_state} eq 'nogame') {
|
||||
return "There is no game started. Use `start` to begin a new game.";
|
||||
} elsif ($self->{current_state} ne 'getplayers') {
|
||||
return "There is a game in progress. Use `join` to play!";
|
||||
}
|
||||
|
||||
my $id = $self->{pbot}->{messagehistory}->{database}->get_message_account($nick, $user, $host);
|
||||
|
||||
foreach my $player (@{$self->{state_data}->{players}}) {
|
||||
if ($player->{id} == $id) {
|
||||
if ($self->{current_state} ne 'getplayers') {
|
||||
return "/msg $nick This is not the time to use `ready`.";
|
||||
}
|
||||
|
||||
if ($player->{ready} == 0) {
|
||||
$player->{ready} = 1;
|
||||
$player->{score} = 0;
|
||||
return "/msg $self->{channel} $nick is ready!";
|
||||
} else {
|
||||
return "/msg $nick You are already ready.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "$nick: You haven't joined this game yet.";
|
||||
return "$nick: You haven't joined this game yet. Use `j` to play now!";
|
||||
}
|
||||
|
||||
when ('unready') {
|
||||
@ -364,12 +352,20 @@ sub spinach_cmd {
|
||||
|
||||
foreach my $player (@{$self->{state_data}->{players}}) {
|
||||
if ($player->{id} == $id) {
|
||||
if ($self->{current_state} ne 'getplayers') {
|
||||
return "/msg $nick This is not the time to use `unready`.";
|
||||
}
|
||||
|
||||
if ($player->{ready} != 0) {
|
||||
$player->{ready} = 0;
|
||||
return "/msg $self->{channel} $nick is no longer ready!";
|
||||
} else {
|
||||
return "/msg $nick You are already not ready.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "$nick: You haven't joined this game yet.";
|
||||
return "$nick: You haven't joined this game yet. Use `j` to play now!";
|
||||
}
|
||||
|
||||
when ('exit') {
|
||||
@ -402,11 +398,8 @@ sub spinach_cmd {
|
||||
return "/msg $self->{channel} $nick: The game has been aborted.";
|
||||
}
|
||||
|
||||
when ('players') {
|
||||
if ($self->{current_state} ne 'getplayers') {
|
||||
return "This command can only be used during the 'Waiting for players' stage. Try the `score` command.";
|
||||
}
|
||||
|
||||
when ($_ eq 'score' or $_ eq 'players') {
|
||||
if ($self->{current_state} eq 'getplayers') {
|
||||
my @names;
|
||||
foreach my $player (@{$self->{state_data}->{players}}) {
|
||||
if (not $player->{ready}) {
|
||||
@ -421,6 +414,20 @@ sub spinach_cmd {
|
||||
return "Current players: $players";
|
||||
}
|
||||
|
||||
# score
|
||||
if (not @{$self->{state_data}->{players}}) {
|
||||
return "There is nobody playing right now.";
|
||||
}
|
||||
|
||||
my $text = '';
|
||||
my $comma = '';
|
||||
foreach my $player (sort { $b->{score} <=> $a->{score} } @{$self->{state_data}->{players}}) {
|
||||
$text .= "$comma$player->{name}: $player->{score}";
|
||||
$comma = '; ';
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
when ('stop') {
|
||||
if ($self->{current_state} ne 'getplayers') {
|
||||
return "This command can only be used during the 'Waiting for players' stage. To stop a game in progress, use the `abort` command.";
|
||||
@ -458,11 +465,17 @@ sub spinach_cmd {
|
||||
}
|
||||
}
|
||||
|
||||
when ('choose') {
|
||||
if ($self->{current_state} !~ /choosecategory$/) {
|
||||
return "$nick: It is not time to choose a category.";
|
||||
when ('n') {
|
||||
return $self->normalize_text($arguments);
|
||||
}
|
||||
|
||||
when ('v') {
|
||||
my ($truth, $lie) = split /;/, $arguments;
|
||||
return $self->validate_lie($self->normalize_text($truth), $self->normalize_text($lie));
|
||||
}
|
||||
|
||||
when ($_ eq 'lie' or $_ eq 'truth' or $_ eq 'choose') {
|
||||
if ($self->{current_state} =~ /choosecategory$/) {
|
||||
if (not length $arguments) {
|
||||
return "Usage: spinach choose <integer>";
|
||||
}
|
||||
@ -487,20 +500,7 @@ sub spinach_cmd {
|
||||
return "/msg $self->{channel} $nick has chosen $self->{state_data}->{current_category}!";
|
||||
}
|
||||
|
||||
when ('n') {
|
||||
return $self->normalize_text($arguments);
|
||||
}
|
||||
|
||||
when ('v') {
|
||||
my ($truth, $lie) = split /;/, $arguments;
|
||||
return $self->validate_lie($self->normalize_text($truth), $self->normalize_text($lie));
|
||||
}
|
||||
|
||||
when ('lie') {
|
||||
if ($self->{current_state} !~ /getlies$/) {
|
||||
return "$nick: It is not time to submit a lie!";
|
||||
}
|
||||
|
||||
if ($self->{current_state} =~ /getlies$/) {
|
||||
if (not length $arguments) {
|
||||
return "Usage: spinach lie <text>";
|
||||
}
|
||||
@ -516,7 +516,7 @@ sub spinach_cmd {
|
||||
}
|
||||
|
||||
if (not $player) {
|
||||
return "$nick: You are not playing in this game. Please wait until the next game.";
|
||||
return "$nick: You are not playing in this game. Use `join` to start playing now!";
|
||||
}
|
||||
|
||||
$arguments = $self->normalize_text($arguments);
|
||||
@ -549,11 +549,7 @@ sub spinach_cmd {
|
||||
}
|
||||
}
|
||||
|
||||
when ('truth') {
|
||||
if ($self->{current_state} !~ /findtruth$/) {
|
||||
return "$nick: It is not time to find the truth!";
|
||||
}
|
||||
|
||||
if ($self->{current_state} =~ /findtruth$/) {
|
||||
if (not length $arguments) {
|
||||
return "Usage: spinach truth <integer>";
|
||||
}
|
||||
@ -597,6 +593,9 @@ sub spinach_cmd {
|
||||
}
|
||||
}
|
||||
|
||||
return "$nick: It is not time to use this command.";
|
||||
}
|
||||
|
||||
when ('show') {
|
||||
if ($self->{current_state} =~ /(?:getlies|findtruth|showlies)$/) {
|
||||
$self->showquestion($self->{state_data});
|
||||
@ -1210,7 +1209,7 @@ sub choosecategory {
|
||||
|
||||
my $name = $state->{players}->[$state->{current_player}]->{name};
|
||||
my $red = $state->{counter} == $state->{max_count} ? $color{red} : '';
|
||||
$self->{pbot}->{conn}->privmsg($self->{channel}, "$name: $red$color{bold}$state->{counter}/$state->{max_count} Choose a category via `/msg candide choose`:");
|
||||
$self->{pbot}->{conn}->privmsg($self->{channel}, "$name: $red$color{bold}$state->{counter}/$state->{max_count} Choose a category via `/msg me c <number>`:");
|
||||
$self->{pbot}->{conn}->privmsg($self->{channel}, "$color{bold}$state->{categories_text}$color{reset}");
|
||||
return 'wait';
|
||||
}
|
||||
@ -1295,7 +1294,7 @@ sub getlies {
|
||||
|
||||
my $players = join ', ', @nolies;
|
||||
my $red = $state->{counter} == $state->{max_count} ? $color{red} : '';
|
||||
$self->{pbot}->{conn}->privmsg($self->{channel}, "$players: $red$color{bold}$state->{counter}/$state->{max_count} Submit your lie now via `/msg candide lie`!$color{reset}");
|
||||
$self->{pbot}->{conn}->privmsg($self->{channel}, "$players: $red$color{bold}$state->{counter}/$state->{max_count} Submit your lie now via `/msg me lie <your lie>`!$color{reset}");
|
||||
}
|
||||
|
||||
return 'wait';
|
||||
@ -1394,7 +1393,7 @@ sub findtruth {
|
||||
|
||||
my $players = join ', ', @notruth;
|
||||
my $red = $state->{counter} == $state->{max_count} ? $color{red} : '';
|
||||
$self->{pbot}->{conn}->privmsg($self->{channel}, "$players: $red$color{bold}$state->{counter}/$state->{max_count} Find the truth now via `/msg candide truth`!");
|
||||
$self->{pbot}->{conn}->privmsg($self->{channel}, "$players: $red$color{bold}$state->{counter}/$state->{max_count} Find the truth now via `/msg me c <number>`!");
|
||||
$self->{pbot}->{conn}->privmsg($self->{channel}, "$color{bold}$state->{current_choices_text}$color{reset}");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user