mirror of https://github.com/pragma-/pbot.git
Plugin/Wordle: refactor how wordlist is (not) reloaded
This commit is contained in:
parent
ac8753f962
commit
1b9e482396
|
@ -11,6 +11,7 @@ use parent 'PBot::Plugin::Base';
|
||||||
|
|
||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
|
|
||||||
|
use Storable qw(dclone);
|
||||||
use utf8;
|
use utf8;
|
||||||
|
|
||||||
sub initialize($self, %conf) {
|
sub initialize($self, %conf) {
|
||||||
|
@ -45,36 +46,36 @@ my %wordlists = (
|
||||||
american => {
|
american => {
|
||||||
name => 'American English',
|
name => 'American English',
|
||||||
prompt => 'Guess the American English word!',
|
prompt => 'Guess the American English word!',
|
||||||
list => '/wordle/american',
|
wlist => '/wordle/american',
|
||||||
supp => ['insane', 'british', 'urban'],
|
glist => ['insane', 'british', 'urban'],
|
||||||
},
|
},
|
||||||
insane => {
|
insane => {
|
||||||
name => 'American English (Insanely Huge List)',
|
name => 'American English (Insanely Huge List)',
|
||||||
prompt => 'Guess the American English (Insanely Huge List) word!',
|
prompt => 'Guess the American English (Insanely Huge List) word!',
|
||||||
list => '/wordle/american-insane',
|
wlist => '/wordle/american-insane',
|
||||||
},
|
},
|
||||||
uncommon => {
|
uncommon => {
|
||||||
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',
|
wlist => '/wordle/american-uncommon',
|
||||||
supp => ['insane', 'british', 'urban'],
|
glist => ['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',
|
wlist => '/wordle/british',
|
||||||
supp => ['insane', 'british', 'urban'],
|
glist => ['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',
|
wlist => '/wordle/canadian',
|
||||||
supp => ['insane', 'british', 'urban'],
|
glist => ['insane', 'british', 'urban'],
|
||||||
},
|
},
|
||||||
finnish => {
|
finnish => {
|
||||||
name => 'Finnish',
|
name => 'Finnish',
|
||||||
prompt => 'Arvaa suomenkielinen sana!',
|
prompt => 'Arvaa suomenkielinen sana!',
|
||||||
list => '/wordle/finnish',
|
wlist => '/wordle/finnish',
|
||||||
accents => 'åäöšž',
|
accents => 'åäöšž',
|
||||||
min_len => 5,
|
min_len => 5,
|
||||||
max_len => 8,
|
max_len => 8,
|
||||||
|
@ -82,25 +83,25 @@ my %wordlists = (
|
||||||
french => {
|
french => {
|
||||||
name => 'French',
|
name => 'French',
|
||||||
prompt => 'Devinez le mot Français !',
|
prompt => 'Devinez le mot Français !',
|
||||||
list => '/wordle/french',
|
wlist => '/wordle/french',
|
||||||
accents => 'éàèùçâêîôûëïü',
|
accents => 'éàèùçâêîôûëïü',
|
||||||
},
|
},
|
||||||
german => {
|
german => {
|
||||||
name => 'German',
|
name => 'German',
|
||||||
prompt => 'Erraten Sie das Deutsches Wort!',
|
prompt => 'Erraten Sie das Deutsches Wort!',
|
||||||
list => '/wordle/german',
|
wlist => '/wordle/german',
|
||||||
accents => 'äöüß',
|
accents => 'äöüß',
|
||||||
},
|
},
|
||||||
italian => {
|
italian => {
|
||||||
name => 'Italian',
|
name => 'Italian',
|
||||||
prompt => 'Indovina la parola italiana!',
|
prompt => 'Indovina la parola italiana!',
|
||||||
list => '/wordle/italian',
|
wlist => '/wordle/italian',
|
||||||
accents => 'èéìòù',
|
accents => 'èéìòù',
|
||||||
},
|
},
|
||||||
polish => {
|
polish => {
|
||||||
name => 'Polish',
|
name => 'Polish',
|
||||||
prompt => 'Odgadnij polskie słowo!',
|
prompt => 'Odgadnij polskie słowo!',
|
||||||
list => '/wordle/polish',
|
wlist => '/wordle/polish',
|
||||||
accents => 'ćńóśźżąęł',
|
accents => 'ćńóśźżąęł',
|
||||||
min_len => 5,
|
min_len => 5,
|
||||||
max_len => 8,
|
max_len => 8,
|
||||||
|
@ -108,14 +109,14 @@ my %wordlists = (
|
||||||
spanish => {
|
spanish => {
|
||||||
name => 'Spanish',
|
name => 'Spanish',
|
||||||
prompt => '¡Adivina la palabra en español!',
|
prompt => '¡Adivina la palabra en español!',
|
||||||
list => '/wordle/spanish',
|
wlist => '/wordle/spanish',
|
||||||
accents => 'áéíóúüñ',
|
accents => 'áéíóúüñ',
|
||||||
},
|
},
|
||||||
urban => {
|
urban => {
|
||||||
name => 'Urban Dictionary',
|
name => 'Urban Dictionary',
|
||||||
prompt => 'Guess the Urban Dictionary word!',
|
prompt => 'Guess the Urban Dictionary word!',
|
||||||
list => '/wordle/urban',
|
wlist => '/wordle/urban',
|
||||||
supp => ['insane', 'british'],
|
glist => ['insane', 'british'],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -284,7 +285,7 @@ sub wordle($self, $context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub load_words($self, $length, $wordlist = DEFAULT_LIST, $words = undef) {
|
sub load_words($self, $length, $wordlist = DEFAULT_LIST, $words = undef) {
|
||||||
$wordlist = $self->{datadir} . $wordlists{$wordlist}->{list};
|
$wordlist = $self->{datadir} . $wordlists{$wordlist}->{wlist};
|
||||||
|
|
||||||
if (not -e $wordlist) {
|
if (not -e $wordlist) {
|
||||||
die "Wordle database `" . $wordlist . "` not available.\n";
|
die "Wordle database `" . $wordlist . "` not available.\n";
|
||||||
|
@ -307,9 +308,12 @@ 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) {
|
||||||
unless ($self->{$channel}->{wordlist} eq $wordlist && exists $self->{$channel}->{words}) {
|
unless ($self->{$channel}->{wordlist} eq $wordlist
|
||||||
|
&& $self->{$channel}->{length} == $length
|
||||||
|
&& exists $self->{$channel}->{words}) {
|
||||||
eval {
|
eval {
|
||||||
$self->{$channel}->{words} = $self->load_words($length, $wordlist);
|
$self->{$channel}->{words} = $self->load_words($length, $wordlist);
|
||||||
|
$self->{$channel}->{guesslist} = dclone $self->{$channel}->{words};
|
||||||
};
|
};
|
||||||
|
|
||||||
if ($@) {
|
if ($@) {
|
||||||
|
@ -333,11 +337,13 @@ 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.";
|
||||||
}
|
}
|
||||||
|
|
||||||
unless ($self->{$channel}->{wordlist} eq $wordlist && exists $self->{$channel}->{words}) {
|
unless ($self->{$channel}->{wordlist} eq $wordlist
|
||||||
if (exists $wordlists{$wordlist}->{supp}) {
|
&& $self->{$channel}->{length} == $length
|
||||||
|
&& exists $self->{$channel}->{words}) {
|
||||||
|
if (exists $wordlists{$wordlist}->{glist}) {
|
||||||
eval {
|
eval {
|
||||||
foreach my $list ($wordlists{$wordlist}->{supp}->@*) {
|
foreach my $list ($wordlists{$wordlist}->{glist}->@*) {
|
||||||
$self->load_words($length, $list, $self->{$channel}->{words});
|
$self->load_words($length, $list, $self->{$channel}->{guesslist});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -348,6 +354,7 @@ sub make_wordle($self, $channel, $length, $word = undef, $wordlist = DEFAULT_LIS
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{$channel}->{wordlist} = $wordlist;
|
$self->{$channel}->{wordlist} = $wordlist;
|
||||||
|
$self->{$channel}->{length} = $length;
|
||||||
$self->{$channel}->{wordle} = \@wordle;
|
$self->{$channel}->{wordle} = \@wordle;
|
||||||
$self->{$channel}->{guess} = '';
|
$self->{$channel}->{guess} = '';
|
||||||
$self->{$channel}->{correct} = 0;
|
$self->{$channel}->{correct} = 0;
|
||||||
|
@ -409,7 +416,7 @@ sub guess_wordle($self, $channel, $guess) {
|
||||||
return "Guess length ($guess_length) unequal to Wordle length ($wordle_length). Try again.";
|
return "Guess length ($guess_length) unequal to Wordle length ($wordle_length). Try again.";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not exists $self->{$channel}->{words}->{$guess}) {
|
if (not exists $self->{$channel}->{guesslist}->{$guess}) {
|
||||||
return "I don't know that word. Try again."
|
return "I don't know that word. Try again."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 => 4779,
|
BUILD_REVISION => 4780,
|
||||||
BUILD_DATE => "2024-08-12",
|
BUILD_DATE => "2024-08-13",
|
||||||
};
|
};
|
||||||
|
|
||||||
sub initialize {}
|
sub initialize {}
|
||||||
|
|
Loading…
Reference in New Issue