47 lines
1.1 KiB
Perl
47 lines
1.1 KiB
Perl
#!perl
|
|
|
|
HELP "give <account> <amount> [<reason>]" => "Transfer money to user's account";
|
|
|
|
sub command :Tab(give) {
|
|
my ($self, $cart, $command) = @_;
|
|
|
|
return NEXT if $command ne 'give';
|
|
|
|
return "Beneficiary", \&beneficiary;
|
|
}
|
|
|
|
sub beneficiary :Tab(USERS) {
|
|
my ($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 {
|
|
my ($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;
|
|
}
|
|
|
|
sub reason :Tab(whatevah) {
|
|
my ($self, $cart, $input) = @_;
|
|
|
|
my $beneficiary = $self->{beneficiary};
|
|
my $amount = $self->{amount};
|
|
|
|
my $user = parse_user($input);
|
|
my $reason = $user ? "" : " ($input)";
|
|
|
|
$cart
|
|
->add(-$amount, "Given to $beneficiary" . $reason)
|
|
->add_contra($beneficiary, +$amount, "Received from \$you" . $reason);
|
|
|
|
$cart->checkout($user) if $user;
|
|
|
|
return ACCEPT;
|
|
}
|