From ac8753f9625f30e095c1d85e08293e09cd6c5ed7 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 12 Aug 2024 12:43:20 -0700 Subject: [PATCH] Plugin/Wordle: do not reload words from disk until wordlist changes; add british and urban to supp for English lists --- lib/PBot/Plugin/Wordle.pm | 39 +++++++++++++++++++++++---------------- lib/PBot/VERSION.pm | 4 ++-- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/PBot/Plugin/Wordle.pm b/lib/PBot/Plugin/Wordle.pm index 34a827a6..9625bbfd 100644 --- a/lib/PBot/Plugin/Wordle.pm +++ b/lib/PBot/Plugin/Wordle.pm @@ -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; diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index c3684a6b..44bc6dc1 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -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 {}