mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-22 18:52:40 +01:00
Plugin/Wordle: add letters
subcommand to display good/unknown letters
This commit is contained in:
parent
961da6f09f
commit
ca7670da3d
1
data/plugin_autoload
vendored
1
data/plugin_autoload
vendored
@ -20,5 +20,6 @@ TypoSub
|
||||
UrlTitles
|
||||
Weather
|
||||
Wolfram
|
||||
Wordle
|
||||
WordMorph
|
||||
Wttr
|
||||
|
@ -24,12 +24,15 @@ sub unload($self) {
|
||||
}
|
||||
|
||||
use constant {
|
||||
USAGE => 'Usage: wordle start [word length] | custom <word> <channel> | guess <word> | show | giveup',
|
||||
USAGE => 'Usage: wordle start [word length] | custom <word> <channel> | guess <word> | letters | show | giveup',
|
||||
NO_WORDLE => 'There is no Wordle yet. Use `wordle start` to begin a game.',
|
||||
DEFAULT_LENGTH => 5,
|
||||
MIN_LENGTH => 3,
|
||||
MAX_LENGTH => 10,
|
||||
WORDLIST => '/usr/share/dict/words',
|
||||
LETTER_CORRECT => 1,
|
||||
LETTER_PRESENT => 2,
|
||||
LETTER_INVALID => 3,
|
||||
};
|
||||
|
||||
sub wordle($self, $context) {
|
||||
@ -125,7 +128,7 @@ sub wordle($self, $context) {
|
||||
hostmask => "$botnick!wordle\@localhost",
|
||||
command => 'wordle',
|
||||
checkflood => 1,
|
||||
message => "$context->{nick} started a custom $result";
|
||||
message => "$context->{nick} started a custom $result",
|
||||
};
|
||||
|
||||
$self->{pbot}->{interpreter}->add_message_to_output_queue($custom_channel, $message, 0);
|
||||
@ -149,6 +152,30 @@ sub wordle($self, $context) {
|
||||
return $self->guess_wordle($channel, $args[0]);
|
||||
}
|
||||
|
||||
when ('letters') {
|
||||
if (@args > 1) {
|
||||
return "Usage: wordle letters";
|
||||
}
|
||||
|
||||
if (not defined $self->{$channel}->{wordle}) {
|
||||
return NO_WORDLE;
|
||||
}
|
||||
|
||||
my $result = 'Good/unknown letters: ';
|
||||
|
||||
foreach my $letter (sort keys $self->{$channel}->{letters}->%*) {
|
||||
if ($self->{$channel}->{letters}->{$letter} == LETTER_CORRECT) {
|
||||
$result .= "*$letter* ";
|
||||
} elsif ($self->{$channel}->{letters}->{$letter} == LETTER_PRESENT) {
|
||||
$result .= "?$letter? ";
|
||||
} elsif ($self->{$channel}->{letters}->{$letter} == 0) {
|
||||
$result .= "$letter ";
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
default {
|
||||
return "Unknown command `$command`; " . USAGE;
|
||||
}
|
||||
@ -198,10 +225,15 @@ sub make_wordle($self, $channel, $length, $word = undef) {
|
||||
@wordle = split //, $words[rand @words];
|
||||
}
|
||||
|
||||
$self->{$channel}->{wordle} = \@wordle;
|
||||
$self->{$channel}->{guesses} = [];
|
||||
$self->{$channel}->{correct} = 0;
|
||||
$self->{$channel}->{wordle} = \@wordle;
|
||||
$self->{$channel}->{guesses} = [];
|
||||
$self->{$channel}->{correct} = 0;
|
||||
$self->{$channel}->{guess_count} = 0;
|
||||
$self->{$channel}->{letters} = {};
|
||||
|
||||
foreach my $letter ('A'..'Z') {
|
||||
$self->{$channel}->{letters}->{$letter} = 0;
|
||||
}
|
||||
|
||||
push $self->{$channel}->{guesses}->@*, '? ' x $self->{$channel}->{wordle}->@*;
|
||||
|
||||
@ -255,6 +287,7 @@ sub guess_wordle($self, $channel, $guess) {
|
||||
$seen{$guess[$i]}++;
|
||||
$correct++;
|
||||
push @result, "*$guess[$i]*";
|
||||
$self->{$channel}->{letters}->{$guess[$i]} = LETTER_CORRECT;
|
||||
} else {
|
||||
my $present = 0;
|
||||
|
||||
@ -271,8 +304,10 @@ sub guess_wordle($self, $channel, $guess) {
|
||||
|
||||
if ($present) {
|
||||
push @result, "?$guess[$i]?";
|
||||
$self->{$channel}->{letters}->{$guess[$i]} = LETTER_PRESENT;
|
||||
} else {
|
||||
push @result, "$guess[$i]";
|
||||
$self->{$channel}->{letters}->{$guess[$i]} = LETTER_INVALID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user