mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-25 13:29:29 +01:00
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:
parent
348465b034
commit
753773f06b
141447
data/wordle/french
141447
data/wordle/french
File diff suppressed because it is too large
Load Diff
133793
data/wordle/german
133793
data/wordle/german
File diff suppressed because it is too large
Load Diff
3882
data/wordle/italian
3882
data/wordle/italian
File diff suppressed because it is too large
Load Diff
17332
data/wordle/spanish
17332
data/wordle/spanish
File diff suppressed because it is too large
Load Diff
@ -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}) {
|
||||
|
@ -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",
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user