mirror of
https://github.com/pragma-/pbot.git
synced 2025-12-13 04:07:27 +01:00
Merge commit 'ca7670da3d42c72dade29cec14cc29cf85b16340'
This commit is contained in:
commit
46b131ef74
1
cpanfile
1
cpanfile
@ -134,6 +134,7 @@ feature FuncSed => sub {
|
|||||||
};
|
};
|
||||||
|
|
||||||
feature GoogleSearch => sub {
|
feature GoogleSearch => sub {
|
||||||
|
requires 'WWW::Google::UserAgent';
|
||||||
requires 'WWW::Google::CustomSearch';
|
requires 'WWW::Google::CustomSearch';
|
||||||
requires 'HTML::Entities';
|
requires 'HTML::Entities';
|
||||||
};
|
};
|
||||||
|
|||||||
1
data/plugin_autoload
vendored
1
data/plugin_autoload
vendored
@ -20,5 +20,6 @@ TypoSub
|
|||||||
UrlTitles
|
UrlTitles
|
||||||
Weather
|
Weather
|
||||||
Wolfram
|
Wolfram
|
||||||
|
Wordle
|
||||||
WordMorph
|
WordMorph
|
||||||
Wttr
|
Wttr
|
||||||
|
|||||||
@ -24,12 +24,15 @@ sub unload($self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use constant {
|
use constant {
|
||||||
USAGE => 'Usage: wordle start [word length] | custom <word> <channel> | guess <word> | show | giveup',
|
USAGE => 'Usage: wordle start [word length] | custom <word> <channel> | guess <word> | letters | show | giveup',
|
||||||
NO_WORDLE => 'There is no Wordle yet. Use `wordle start` to begin a game.',
|
NO_WORDLE => 'There is no Wordle yet. Use `wordle start` to begin a game.',
|
||||||
DEFAULT_LENGTH => 5,
|
DEFAULT_LENGTH => 5,
|
||||||
MIN_LENGTH => 3,
|
MIN_LENGTH => 3,
|
||||||
MAX_LENGTH => 10,
|
MAX_LENGTH => 10,
|
||||||
WORDLIST => '/usr/share/dict/words',
|
WORDLIST => '/usr/share/dict/words',
|
||||||
|
LETTER_CORRECT => 1,
|
||||||
|
LETTER_PRESENT => 2,
|
||||||
|
LETTER_INVALID => 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
sub wordle($self, $context) {
|
sub wordle($self, $context) {
|
||||||
@ -149,6 +152,30 @@ sub wordle($self, $context) {
|
|||||||
return $self->guess_wordle($channel, $args[0]);
|
return $self->guess_wordle($channel, $args[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
when ('letters') {
|
||||||
|
if (@args > 1) {
|
||||||
|
return "Usage: wordle letters";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not defined $self->{$channel}->{wordle}) {
|
||||||
|
return NO_WORDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $result = 'Good/unknown letters: ';
|
||||||
|
|
||||||
|
foreach my $letter (sort keys $self->{$channel}->{letters}->%*) {
|
||||||
|
if ($self->{$channel}->{letters}->{$letter} == LETTER_CORRECT) {
|
||||||
|
$result .= "*$letter* ";
|
||||||
|
} elsif ($self->{$channel}->{letters}->{$letter} == LETTER_PRESENT) {
|
||||||
|
$result .= "?$letter? ";
|
||||||
|
} elsif ($self->{$channel}->{letters}->{$letter} == 0) {
|
||||||
|
$result .= "$letter ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
default {
|
default {
|
||||||
return "Unknown command `$command`; " . USAGE;
|
return "Unknown command `$command`; " . USAGE;
|
||||||
}
|
}
|
||||||
@ -198,10 +225,15 @@ sub make_wordle($self, $channel, $length, $word = undef) {
|
|||||||
@wordle = split //, $words[rand @words];
|
@wordle = split //, $words[rand @words];
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{$channel}->{wordle} = \@wordle;
|
$self->{$channel}->{wordle} = \@wordle;
|
||||||
$self->{$channel}->{guesses} = [];
|
$self->{$channel}->{guesses} = [];
|
||||||
$self->{$channel}->{correct} = 0;
|
$self->{$channel}->{correct} = 0;
|
||||||
$self->{$channel}->{guess_count} = 0;
|
$self->{$channel}->{guess_count} = 0;
|
||||||
|
$self->{$channel}->{letters} = {};
|
||||||
|
|
||||||
|
foreach my $letter ('A'..'Z') {
|
||||||
|
$self->{$channel}->{letters}->{$letter} = 0;
|
||||||
|
}
|
||||||
|
|
||||||
push $self->{$channel}->{guesses}->@*, '? ' x $self->{$channel}->{wordle}->@*;
|
push $self->{$channel}->{guesses}->@*, '? ' x $self->{$channel}->{wordle}->@*;
|
||||||
|
|
||||||
@ -255,6 +287,7 @@ sub guess_wordle($self, $channel, $guess) {
|
|||||||
$seen{$guess[$i]}++;
|
$seen{$guess[$i]}++;
|
||||||
$correct++;
|
$correct++;
|
||||||
push @result, "*$guess[$i]*";
|
push @result, "*$guess[$i]*";
|
||||||
|
$self->{$channel}->{letters}->{$guess[$i]} = LETTER_CORRECT;
|
||||||
} else {
|
} else {
|
||||||
my $present = 0;
|
my $present = 0;
|
||||||
|
|
||||||
@ -271,8 +304,10 @@ sub guess_wordle($self, $channel, $guess) {
|
|||||||
|
|
||||||
if ($present) {
|
if ($present) {
|
||||||
push @result, "?$guess[$i]?";
|
push @result, "?$guess[$i]?";
|
||||||
|
$self->{$channel}->{letters}->{$guess[$i]} = LETTER_PRESENT;
|
||||||
} else {
|
} else {
|
||||||
push @result, "$guess[$i]";
|
push @result, "$guess[$i]";
|
||||||
|
$self->{$channel}->{letters}->{$guess[$i]} = LETTER_INVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user