3
0
mirror of https://github.com/pragma-/pbot.git synced 2026-03-19 21:58:06 +01:00

Plugins/Wordle: minor improvements

This commit is contained in:
Pragmatic Software 2026-03-16 14:08:54 -07:00
parent 0ef979f829
commit 0462e4153d
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE
2 changed files with 10 additions and 4 deletions

View File

@ -252,6 +252,10 @@ sub wordle($self, $context) {
if (not defined $args[0]) {
return "$context->{nick}: You are playing the $gameid Wordle.";
} else {
if ($gameid !~ /^[a-zA-Z0-9_]{1,16}$/) {
return "Invalid game-id `$gameid`; must be up to 16 alphanumeric characters";
}
$self->{players}->{$channel}->{$context->{message_account}}->{gameid} = $gameid;
$self->{games}->{$channel}->{$gameid}->{exists} = 1;
return "$context->{nick} is now playing the $gameid Wordle!";
@ -1023,6 +1027,7 @@ sub guesses2state($self, $channel, $gameid) {
my $g = $guess;
$g =~ s/\x02|\x0F|\x11|\x1D|\x1E|\x1F|\x03([0-9][0-9]?(,[0-9][0-9]?)?)?//g;
$g =~ s/ß/ẞ/g; # avoid uppercasing to SS in German
my @states = ($g =~ /..(.)/g);
foreach my $state (@states) {
@ -1136,8 +1141,8 @@ sub state2pattern($self, $state) {
}
sub pattern2words($self, $channel, $gameid, $pattern) {
my @keys = keys $self->{games}->{$channel}->{$gameid}->{words}->%*;
return grep { /$pattern/i } @keys;
my @keys = map { lc } keys $self->{games}->{$channel}->{$gameid}->{words}->%*;
return grep { /$pattern/ } @keys;
}
sub check_games($self) {
@ -1145,6 +1150,7 @@ sub check_games($self) {
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
foreach my $channel (keys $self->{games}->%*) {
foreach my $gameid (keys $self->{games}->{$channel}->%*) {
next if $gameid eq 'main';
next if not exists $self->{games}->{$channel}->{$gameid}->{wordle};
if ($now - $self->{games}->{$channel}->{$gameid}->{guess_time} > 60 * 60 * 24) {
my $wordle = join '', $self->{games}->{$channel}->{$gameid}->{wordle}->@*;

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 => 4941,
BUILD_DATE => "2026-03-15",
BUILD_REVISION => 4942,
BUILD_DATE => "2026-03-16",
};
sub initialize {}