3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-03 01:48:38 +02:00

Interpreter: fix-up a/an article in front of &{cmdsub}s

This commit is contained in:
Pragmatic Software 2021-08-23 13:23:12 -07:00
parent 68490b6ac5
commit b638757f92

View File

@ -15,6 +15,7 @@ use parent 'PBot::Core::Class', 'PBot::Core::Registerable';
use PBot::Imports;
use PBot::Core::MessageHistory::Constants ':all';
use PBot::Core::Utils::Indefinite;
use PBot::Core::Utils::ValidateString;
use Encode;
@ -370,7 +371,7 @@ sub interpret {
$command =~ s/^\s+|\s+$//g;
# replace contextual command
$context->{command} = $command;
$context->{command} = $command;
# reset contextual command history
$context->{commands} = [];
@ -593,9 +594,25 @@ sub handle_result {
if (exists $context->{subcmd}) {
my $command = pop @{$context->{subcmd}};
if (@{$context->{subcmd}} == 0 or $context->{alldone}) { delete $context->{subcmd}; }
if (@{$context->{subcmd}} == 0 or $context->{alldone}) {
delete $context->{subcmd};
}
$command =~ s/&\{subcmd\}/$result/;
if ($command =~ s/\b(an?)(\s+)&\{subcmd\}/&{subcmd}/i) {
# fix-up a/an article
my ($article, $spaces) = ($1, $2);
my $fixed_article = select_indefinite_article $result;
if ($article eq 'AN') {
$fixed_article = uc $fixed_article;
} elsif ($article eq 'An' or $article eq 'A') {
$fixed_article = ucfirst $fixed_article;
}
$command =~ s/&\{subcmd\}/$fixed_article$spaces$result/;
} else {
$command =~ s/&\{subcmd\}/$result/;
}
if (not $context->{alldone}) {
$context->{command} = $command;