Plugin/Wordle: add accented words and German nouns

Accented words will be unidecoded to Latin letters so letter list remains A-Z.

German words will include proper nouns since I had no easy way to distinguish
them from regular nouns.
This commit is contained in:
Pragmatic Software 2024-03-16 17:29:09 -07:00
parent 348465b034
commit 753773f06b
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE
6 changed files with 296466 additions and 10 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,8 @@ use parent 'PBot::Plugin::Base';
use PBot::Imports;
use Text::Unidecode;
sub initialize($self, %conf) {
$self->{pbot}->{commands}->add(
name => 'wordle',
@ -126,15 +128,11 @@ sub wordle($self, $context) {
return "Usage: wordle custom <word> <channel> [wordlist]";
}
my $custom_word = $args[0];
my $custom_word = unidecode $args[0];
my $custom_channel = $args[1];
my $custom_wordlist = $args[2];
my $length = length $custom_word;
if ($custom_word !~ /[a-z]/) {
return "Word must be all lowercase and cannot contain numbers or symbols.";
}
if ($length < MIN_LENGTH || $length > MAX_LENGTH) {
return "Invalid word length; must be >= ".MIN_LENGTH." and <= ".MAX_LENGTH.".";
}
@ -218,14 +216,13 @@ sub load_words($self, $length, $wordlist = 'default') {
die "Wordle database `" . $wordlist . "` not available. Set WORDLIST to a valid location of a wordlist file.\n";
}
open my $fh, '<', $wordlist or die "Failed to open Wordle database.";
open my $fh, '<:encoding(UTF-8)', $wordlist or die "Failed to open Wordle database.";
my %words;
while (my $line = <$fh>) {
chomp $line;
next if $line !~ /^[a-z]+$/;
$line = unidecode $line;
if (length $line == $length) {
$words{uc $line} = 1;
}
@ -270,7 +267,11 @@ sub make_wordle($self, $channel, $length, $word = undef, $wordlist = 'default')
$self->{$channel}->{guess} .= ' ? ' x $self->{$channel}->{wordle}->@*;
$self->{$channel}->{guess} .= $color{reset};
return $self->show_wordle($channel) . " Guess the word! Legend: $color{invalid}X $color{reset} not in word; $color{present}X$color{present_a}?$color{reset} wrong position; $color{correct}X$color{correct_a}*$color{reset} correct position";
my $language = $wordlist;
$language = ucfirst $language;
$language = 'American' if $language eq 'Default';
return $self->show_wordle($channel) . " Guess the $language word! Legend: $color{invalid}X $color{reset} not in word; $color{present}X$color{present_a}?$color{reset} wrong position; $color{correct}X$color{correct_a}*$color{reset} correct position";
}
sub show_letters($self, $channel) {
@ -304,6 +305,7 @@ sub guess_wordle($self, $channel, $guess) {
return "The length of your guess does not match length of current Wordle. Try again.";
}
$guess = unidecode $guess;
$guess = uc $guess;
if (not exists $self->{$channel}->{words}->{$guess}) {

View File

@ -25,7 +25,7 @@ use PBot::Imports;
# These are set by the /misc/update_version script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 4719,
BUILD_REVISION => 4720,
BUILD_DATE => "2024-03-16",
};