From 09411bb6c07216bbb669dee5b8c50c4afa8ff31b Mon Sep 17 00:00:00 2001 From: Juerd Waalboer Date: Tue, 26 Dec 2023 05:15:43 +0100 Subject: [PATCH] give: Don't do checkout with description as username Originally, this command didn't have a description parameter. Foo would use `give xyzzy 10 foo`. Then, a description parameter was added. For backwards compatibility, if you would enter a username (like `foo` in this example) in the place of the description, it would finalize the transaction using that. However, as the user base grows, several reasonable descriptions exist as user account names, and that would finalize the transaction under the wrong user. It's time to break backward compatibility. If you don't want to leave a message (it's still optional), that can be done with `x` (like the `donate` command), or in advanced mode, with `""`. Because it's likely that people are still very much used to just leaving the description out, if you enter something that happens to match an existing username, the input will be rejected. The current equivalent command line would be `give xyzzy 10 ""; foo` or `give xyzzy 10 x; foo`. If the `;` (new since v5.0.0) is left out, the trailing `foo` has to be confirmed with a second press of the enter key. --- plugins/give | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/give b/plugins/give index 1de0150..2c9861e 100644 --- a/plugins/give +++ b/plugins/give @@ -19,21 +19,22 @@ sub amount($self, $cart, $input, @) { $self->{amount} = parse_amount($input) or return REJECT, "$input: Invalid amount."; - return "Why are you giving $self->{amount} to $self->{beneficiary}, or enter your username to end", \&reason; + return "Short description ('x' for no message)", \&reason; } sub reason :Tab(whatevah) ($self, $cart, $input, @) { + return REJECT, "'$input' is a username, not a description :)." + if parse_user($input); + return REJECT, "'$input' is an amount, not a description :)." + if parse_amount($input); + my $beneficiary = $self->{beneficiary}; my $amount = $self->{amount}; - - my $user = parse_user($input); - my $reason = $user ? "" : " ($input)"; + my $reason = $input =~ /^x?$/ ? "" : " ($input)"; $cart ->add(-$amount, "Given to $beneficiary" . $reason) ->add_contra($beneficiary, +$amount, "Received from \$you" . $reason); - $cart->checkout($user) if $user; - return ACCEPT; }