3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-06 03:59:31 +01:00

Plugin/Wordle: removed unidecode normalization; added Finnish

This commit is contained in:
Pragmatic Software 2024-03-17 21:08:50 -07:00
parent 51fb92bc39
commit 5c185486e8
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE
3 changed files with 60333 additions and 11 deletions

60303
data/wordle/finnish Normal file

File diff suppressed because it is too large Load Diff

View File

@ -11,8 +11,6 @@ use parent 'PBot::Plugin::Base';
use PBot::Imports;
use Text::Unidecode;
sub initialize($self, %conf) {
$self->{pbot}->{commands}->add(
name => 'wordle',
@ -46,11 +44,21 @@ my %wordlists = (
insane => '/wordle/american-insane',
british => '/wordle/british',
canadian => '/wordle/canadian',
finnish => '/wordle/finnish',
french => '/wordle/french',
german => '/wordle/german',
italian => '/wordle/italian',
spanish => '/wordle/spanish',
polish => '/wordle/polish',
spanish => '/wordle/spanish',
);
my %accents = (
finnish => 'åäöšž',
french => 'éàèùçâêîôûëïü',
german => 'äöüß',
italian => 'èéìòù',
polish => 'ćńóśźżąęł',
spanish => 'áéíóúüñ',
);
my %color = (
@ -129,7 +137,7 @@ sub wordle($self, $context) {
return "Usage: wordle custom <word> <channel> [wordlist]";
}
my $custom_word = unidecode $args[0];
my $custom_word = $args[0];
my $custom_channel = $args[1];
my $custom_wordlist = $args[2];
my $length = length $custom_word;
@ -152,6 +160,7 @@ sub wordle($self, $context) {
return 'Invalid wordlist; options are: ' . (join ', ', sort keys %wordlists);
}
$custom_word =~ s/ß/ẞ/g; # avoid uppercasing to SS in German
my $result = $self->make_wordle($custom_channel, $length, uc $custom_word, $wordlist);
if ($result !~ /Guess/) {
@ -223,8 +232,8 @@ sub load_words($self, $length, $wordlist = 'default') {
while (my $line = <$fh>) {
chomp $line;
$line = unidecode $line;
if (length $line == $length) {
$line =~ s/ß/ẞ/g; # avoid uppercasing to SS in German
$words{uc $line} = 1;
}
}
@ -264,6 +273,14 @@ sub make_wordle($self, $channel, $length, $word = undef, $wordlist = 'default')
$self->{$channel}->{letters}->{$letter} = 0;
}
if (exists $accents{$wordlist}) {
foreach my $letter (split //, $accents{$wordlist}) {
$letter =~ s/ß/ẞ/g; # avoid uppercasing to SS in German
$letter = uc $letter;
$self->{$channel}->{letters}->{$letter} = 0;
}
}
$self->{$channel}->{guess} = $color{invalid};
$self->{$channel}->{guess} .= ' ? ' x $self->{$channel}->{wordle}->@*;
$self->{$channel}->{guess} .= $color{reset};
@ -302,13 +319,15 @@ sub show_wordle($self, $channel, $with_letters = 0) {
}
sub guess_wordle($self, $channel, $guess) {
if (length $guess != $self->{$channel}->{wordle}->@*) {
return "The length of your guess does not match length of current Wordle. Try again.";
}
$guess = unidecode $guess;
$guess =~ s/ß/ẞ/g; # avoid uppercasing to SS in German
$guess = uc $guess;
if (length $guess != $self->{$channel}->{wordle}->@*) {
my $guess_length = length $guess;
my $wordle_length = $self->{$channel}->{wordle}->@*;
return "Guess length ($guess_length) unequal to Wordle length ($wordle_length). Try again.";
}
if (not exists $self->{$channel}->{words}->{$guess}) {
return "I don't know that word. Try again."
}

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 => 4723,
BUILD_REVISION => 4724,
BUILD_DATE => "2024-03-17",
};