mirror of
https://github.com/pragma-/pbot.git
synced 2025-02-16 21:40:46 +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
|
UrlTitles
|
||||||
Weather
|
Weather
|
||||||
Wolfram
|
Wolfram
|
||||||
|
Wordle
|
||||||
WordMorph
|
WordMorph
|
||||||
Wttr
|
Wttr
|
||||||
|
@ -24,12 +24,15 @@ sub unload($self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use constant {
|
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.',
|
NO_WORDLE => 'There is no Wordle yet. Use `wordle start` to begin a game.',
|
||||||
DEFAULT_LENGTH => 5,
|
DEFAULT_LENGTH => 5,
|
||||||
MIN_LENGTH => 3,
|
MIN_LENGTH => 3,
|
||||||
MAX_LENGTH => 10,
|
MAX_LENGTH => 10,
|
||||||
WORDLIST => '/usr/share/dict/words',
|
WORDLIST => '/usr/share/dict/words',
|
||||||
|
LETTER_CORRECT => 1,
|
||||||
|
LETTER_PRESENT => 2,
|
||||||
|
LETTER_INVALID => 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
sub wordle($self, $context) {
|
sub wordle($self, $context) {
|
||||||
@ -125,7 +128,7 @@ sub wordle($self, $context) {
|
|||||||
hostmask => "$botnick!wordle\@localhost",
|
hostmask => "$botnick!wordle\@localhost",
|
||||||
command => 'wordle',
|
command => 'wordle',
|
||||||
checkflood => 1,
|
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);
|
$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]);
|
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 {
|
default {
|
||||||
return "Unknown command `$command`; " . USAGE;
|
return "Unknown command `$command`; " . USAGE;
|
||||||
}
|
}
|
||||||
@ -202,6 +229,11 @@ sub make_wordle($self, $channel, $length, $word = undef) {
|
|||||||
$self->{$channel}->{guesses} = [];
|
$self->{$channel}->{guesses} = [];
|
||||||
$self->{$channel}->{correct} = 0;
|
$self->{$channel}->{correct} = 0;
|
||||||
$self->{$channel}->{guess_count} = 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}->@*;
|
push $self->{$channel}->{guesses}->@*, '? ' x $self->{$channel}->{wordle}->@*;
|
||||||
|
|
||||||
@ -255,6 +287,7 @@ sub guess_wordle($self, $channel, $guess) {
|
|||||||
$seen{$guess[$i]}++;
|
$seen{$guess[$i]}++;
|
||||||
$correct++;
|
$correct++;
|
||||||
push @result, "*$guess[$i]*";
|
push @result, "*$guess[$i]*";
|
||||||
|
$self->{$channel}->{letters}->{$guess[$i]} = LETTER_CORRECT;
|
||||||
} else {
|
} else {
|
||||||
my $present = 0;
|
my $present = 0;
|
||||||
|
|
||||||
@ -271,8 +304,10 @@ sub guess_wordle($self, $channel, $guess) {
|
|||||||
|
|
||||||
if ($present) {
|
if ($present) {
|
||||||
push @result, "?$guess[$i]?";
|
push @result, "?$guess[$i]?";
|
||||||
|
$self->{$channel}->{letters}->{$guess[$i]} = LETTER_PRESENT;
|
||||||
} else {
|
} else {
|
||||||
push @result, "$guess[$i]";
|
push @result, "$guess[$i]";
|
||||||
|
$self->{$channel}->{letters}->{$guess[$i]} = LETTER_INVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user