revbank/plugins/give
2013-02-28 16:36:48 +01:00

49 lines
1.2 KiB
Perl
Executable file

#!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 "Benificiary", \&benedinges;
}
sub benedinges :Tab(USERS) {
my ($self, $cart, $input) = @_;
$self->{user} = parse_user($input)
or return REJECT, "$input: No such user.";
return "Amount to give to $self->{user}", \&amount;
}
sub amount {
my ($self, $cart, $input) = @_;
$self->{amount} = parse_amount($input)
or return REJECT, "$input: Invalid amount.";
my $user = $self->{user};
my $amount = $self->{amount};
return "Why are you giving $amount to $user, or enter your username to end",
\&reason;
}
sub reason :Tab(whatevah) {
my ($self, $cart, $input) = @_;
my $user = $self->{user};
my $amount = $self->{amount};
if ($input = parse_user($input)) {
$cart->add(undef, -$amount, "Given to $user");
$cart->add($user, +$amount, "Received from \$you");
$cart->checkout($input);
} else {
$cart->add(undef, -$amount, "Given to $user ($input)");
$cart->add($user, +$amount, "Received from \$you ($input)");
}
return ACCEPT;
}