Plugin/Wordle: do not reload words from disk until wordlist changes; add british and urban to supp for English lists

This commit is contained in:
Pragmatic Software 2024-08-12 12:43:20 -07:00
parent b31aa7a816
commit ac8753f962
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE
2 changed files with 25 additions and 18 deletions

View File

@ -46,7 +46,7 @@ my %wordlists = (
name => 'American English', name => 'American English',
prompt => 'Guess the American English word!', prompt => 'Guess the American English word!',
list => '/wordle/american', list => '/wordle/american',
supp => 'insane', supp => ['insane', 'british', 'urban'],
}, },
insane => { insane => {
name => 'American English (Insanely Huge List)', name => 'American English (Insanely Huge List)',
@ -57,19 +57,19 @@ my %wordlists = (
name => 'American English (Uncommon)', name => 'American English (Uncommon)',
prompt => 'Guess the American English (Uncommon) word!', prompt => 'Guess the American English (Uncommon) word!',
list => '/wordle/american-uncommon', list => '/wordle/american-uncommon',
supp => 'insane', supp => ['insane', 'british', 'urban'],
}, },
british => { british => {
name => 'British English', name => 'British English',
prompt => 'Guess the British English word!', prompt => 'Guess the British English word!',
list => '/wordle/british', list => '/wordle/british',
supp => 'insane', supp => ['insane', 'british', 'urban'],
}, },
canadian => { canadian => {
name => 'Canadian English', name => 'Canadian English',
prompt => 'Guess the Canadian English word!', prompt => 'Guess the Canadian English word!',
list => '/wordle/canadian', list => '/wordle/canadian',
supp => 'insane', supp => ['insane', 'british', 'urban'],
}, },
finnish => { finnish => {
name => 'Finnish', name => 'Finnish',
@ -115,7 +115,7 @@ my %wordlists = (
name => 'Urban Dictionary', name => 'Urban Dictionary',
prompt => 'Guess the Urban Dictionary word!', prompt => 'Guess the Urban Dictionary word!',
list => '/wordle/urban', list => '/wordle/urban',
supp => 'insane', supp => ['insane', 'british'],
}, },
); );
@ -307,12 +307,14 @@ sub load_words($self, $length, $wordlist = DEFAULT_LIST, $words = undef) {
} }
sub make_wordle($self, $channel, $length, $word = undef, $wordlist = DEFAULT_LIST) { sub make_wordle($self, $channel, $length, $word = undef, $wordlist = DEFAULT_LIST) {
eval { unless ($self->{$channel}->{wordlist} eq $wordlist && exists $self->{$channel}->{words}) {
$self->{$channel}->{words} = $self->load_words($length, $wordlist); eval {
}; $self->{$channel}->{words} = $self->load_words($length, $wordlist);
};
if ($@) { if ($@) {
return "Failed to load words: $@"; return "Failed to load words: $@";
}
} }
my @wordle; my @wordle;
@ -331,16 +333,21 @@ sub make_wordle($self, $channel, $length, $word = undef, $wordlist = DEFAULT_LIS
return "Failed to find a suitable word."; return "Failed to find a suitable word.";
} }
if (exists $wordlists{$wordlist}->{supp}) { unless ($self->{$channel}->{wordlist} eq $wordlist && exists $self->{$channel}->{words}) {
eval { if (exists $wordlists{$wordlist}->{supp}) {
$self->load_words($length, $wordlists{$wordlist}->{supp}, $self->{$channel}->{words}); eval {
}; foreach my $list ($wordlists{$wordlist}->{supp}->@*) {
$self->load_words($length, $list, $self->{$channel}->{words});
}
};
if ($@) { if ($@) {
return "Failed to load words: $@"; return "Failed to load words: $@";
}
} }
} }
$self->{$channel}->{wordlist} = $wordlist;
$self->{$channel}->{wordle} = \@wordle; $self->{$channel}->{wordle} = \@wordle;
$self->{$channel}->{guess} = ''; $self->{$channel}->{guess} = '';
$self->{$channel}->{correct} = 0; $self->{$channel}->{correct} = 0;

View File

@ -25,8 +25,8 @@ use PBot::Imports;
# These are set by the /misc/update_version script # These are set by the /misc/update_version script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 4778, BUILD_REVISION => 4779,
BUILD_DATE => "2024-08-10", BUILD_DATE => "2024-08-12",
}; };
sub initialize {} sub initialize {}