
When the transaction is still pending, the past tense is incorrect. This is not relevant for the contras, because those descriptions are only displayed in logs, after the fact.
40 lines
1.2 KiB
Perl
40 lines
1.2 KiB
Perl
#!perl
|
|
|
|
HELP "give <account> <amount> [<reason>]" => "Transfer money to user's account";
|
|
|
|
sub command :Tab(give) ($self, $cart, $command, @) {
|
|
return NEXT if $command ne 'give';
|
|
|
|
return "Beneficiary", \&beneficiary;
|
|
}
|
|
|
|
sub beneficiary :Tab(USERS) ($self, $cart, $input, @) {
|
|
$self->{beneficiary} = parse_user($input)
|
|
or return REJECT, "$input: No such user.";
|
|
|
|
return "Amount to give to $self->{beneficiary}", \&amount;
|
|
}
|
|
|
|
sub amount($self, $cart, $input, @) {
|
|
$self->{amount} = parse_amount($input)
|
|
or return REJECT, "$input: Invalid amount.";
|
|
|
|
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 $reason = $input =~ /^x?$/ ? "" : " ($input)";
|
|
|
|
$cart
|
|
->add(-$amount, "Give to $beneficiary" . $reason)
|
|
->add_contra($beneficiary, +$amount, "Received from \$you" . $reason);
|
|
|
|
return ACCEPT;
|
|
}
|