3
0
mirror of https://github.com/pragma-/pbot.git synced 2025-02-02 07:24:09 +01:00

Plugin/WordMorph: minor refactoring/clean-up

This commit is contained in:
Pragmatic Software 2022-08-31 23:09:10 -07:00
parent f71e08cf7f
commit 82edbd2a18
2 changed files with 7 additions and 6 deletions

View File

@ -77,11 +77,13 @@ sub wordmorph {
return "Unknown direction `$args[0]`; usage: wordmorph hint [from direction]; from direction can be `left` or `right`"; return "Unknown direction `$args[0]`; usage: wordmorph hint [from direction]; from direction can be `left` or `right`";
} }
my $end = $#{$self->{$channel}->{morph}};
if ($direction == LEFT) { if ($direction == LEFT) {
$self->{$channel}->{hintL}++; $self->{$channel}->{hintL}++;
if ($self->{$channel}->{hintL} > $#{$self->{$channel}->{morph}}) { if ($self->{$channel}->{hintL} > $end) {
$self->{$channel}->{hintL} = $#{$self->{$channel}->{morph}}; $self->{$channel}->{hintL} = $end;
} }
} else { } else {
$self->{$channel}->{hintR}--; $self->{$channel}->{hintR}--;
@ -92,9 +94,8 @@ sub wordmorph {
} }
my @hints; my @hints;
my $end = $#{$self->{$channel}->{morph}};
$hints[0] = $self->{$channel}->{morph}->[0]; $hints[0] = $self->{$channel}->{morph}->[0];
$hints[$end] = $self->{$channel}->{morph}->[$end]; $hints[$end] = $self->{$channel}->{morph}->[$end];
for (my $i = 1; $i < $self->{$channel}->{hintL}; $i++) { for (my $i = 1; $i < $self->{$channel}->{hintL}; $i++) {
@ -108,7 +109,7 @@ sub wordmorph {
$hints[$i] = $blank_hint; $hints[$i] = $blank_hint;
} }
for (my $i = $#{$self->{$channel}->{morph}} - 1; $i > $self->{$channel}->{hintR}; $i--) { for (my $i = $end - 1; $i > $self->{$channel}->{hintR}; $i--) {
my $word1 = $self->{$channel}->{morph}->[$i]; my $word1 = $self->{$channel}->{morph}->[$i];
my $word2 = $self->{$channel}->{morph}->[$i + 1]; my $word2 = $self->{$channel}->{morph}->[$i + 1];
$hints[$i] = $self->form_hint($word1, $word2); $hints[$i] = $self->form_hint($word1, $word2);

View File

@ -25,7 +25,7 @@ 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 => 4579, BUILD_REVISION => 4580,
BUILD_DATE => "2022-08-31", BUILD_DATE => "2022-08-31",
}; };