3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-25 21:39:27 +01:00

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

View File

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