mirror of
https://github.com/pragma-/pbot.git
synced 2025-11-28 04:27:25 +01:00
Plugin/Wordle: restrict game-ids to alphanum; minor improvements
This commit is contained in:
parent
9fada0f82c
commit
2afc6210c5
@ -13,6 +13,7 @@ use PBot::Imports;
|
|||||||
use PBot::Core::Utils::IsAbbrev;
|
use PBot::Core::Utils::IsAbbrev;
|
||||||
|
|
||||||
use Storable qw(dclone);
|
use Storable qw(dclone);
|
||||||
|
use Time::HiRes qw/time/;
|
||||||
use Time::Duration;
|
use Time::Duration;
|
||||||
use JSON::XS;
|
use JSON::XS;
|
||||||
use utf8;
|
use utf8;
|
||||||
@ -379,6 +380,10 @@ sub wordle($self, $context) {
|
|||||||
my $gameid = $self->gameid($args[2], $context, 1) // 'main';
|
my $gameid = $self->gameid($args[2], $context, 1) // 'main';
|
||||||
my $game = $gameid ne 'main' ? "($gameid) " : '';
|
my $game = $gameid ne 'main' ? "($gameid) " : '';
|
||||||
|
|
||||||
|
if ($gameid !~ /^[a-zA-Z0-9_]{1,16}$/) {
|
||||||
|
return "Invalid game-id `$gameid`; must be [a-zA-Z0-9_]{1,16}";
|
||||||
|
}
|
||||||
|
|
||||||
$self->{players}->{$channel}->{$context->{message_account}}->{gameid} = $gameid;
|
$self->{players}->{$channel}->{$context->{message_account}}->{gameid} = $gameid;
|
||||||
|
|
||||||
if (defined $self->{games}->{$channel}->{$gameid}->{wordle}
|
if (defined $self->{games}->{$channel}->{$gameid}->{wordle}
|
||||||
@ -420,6 +425,10 @@ sub wordle($self, $context) {
|
|||||||
my $gameid = $self->gameid($args[3], $context, 1) // 'main';
|
my $gameid = $self->gameid($args[3], $context, 1) // 'main';
|
||||||
my $game = $gameid ne 'main' ? "($gameid) " : '';
|
my $game = $gameid ne 'main' ? "($gameid) " : '';
|
||||||
|
|
||||||
|
if ($gameid !~ /^[a-zA-Z0-9_]{1,16}$/) {
|
||||||
|
return "Invalid game-id `$gameid`; must be [a-zA-Z0-9_]{1,16}";
|
||||||
|
}
|
||||||
|
|
||||||
if (defined $self->{games}->{$custom_channel}->{$gameid}->{wordle}
|
if (defined $self->{games}->{$custom_channel}->{$gameid}->{wordle}
|
||||||
&& !$self->{games}->{$custom_channel}->{$gameid}->{solved}
|
&& !$self->{games}->{$custom_channel}->{$gameid}->{solved}
|
||||||
&& !$self->{games}->{$custom_channel}->{$gameid}->{givenup}) {
|
&& !$self->{games}->{$custom_channel}->{$gameid}->{givenup}) {
|
||||||
@ -570,6 +579,10 @@ sub gameid($self, $gameid, $context, $newgame = 0) {
|
|||||||
$gameid = $self->{players}->{$channel}->{$context->{message_account}}->{gameid};
|
$gameid = $self->{players}->{$channel}->{$context->{message_account}}->{gameid};
|
||||||
return $gameid if defined $gameid;
|
return $gameid if defined $gameid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (exists $self->{games}->{$channel}->{main}) {
|
||||||
|
return 'main';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!exists $self->{games}->{$channel}->{$gameid} && !$newgame) {
|
if (!exists $self->{games}->{$channel}->{$gameid} && !$newgame) {
|
||||||
return undef;
|
return undef;
|
||||||
@ -909,7 +922,7 @@ sub check_games($self) {
|
|||||||
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
|
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
|
||||||
foreach my $channel (keys $self->{games}->%*) {
|
foreach my $channel (keys $self->{games}->%*) {
|
||||||
foreach my $gameid (keys $self->{games}->{$channel}->%*) {
|
foreach my $gameid (keys $self->{games}->{$channel}->%*) {
|
||||||
if ($now - $self->{games}->{$channel}->{$gameid}->{guess_time} > 60 * 60 * 24 * 3) {
|
if ($now - $self->{games}->{$channel}->{$gameid}->{guess_time} > 60 * 60 * 24) {
|
||||||
my $wordle = join '', $self->{games}->{$channel}->{$gameid}->{wordle}->@*;
|
my $wordle = join '', $self->{games}->{$channel}->{$gameid}->{wordle}->@*;
|
||||||
|
|
||||||
my $state;
|
my $state;
|
||||||
|
|||||||
@ -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 => 4922,
|
BUILD_REVISION => 4923,
|
||||||
BUILD_DATE => "2025-10-22",
|
BUILD_DATE => "2025-11-05",
|
||||||
};
|
};
|
||||||
|
|
||||||
sub initialize {}
|
sub initialize {}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user