From 6372e30cacc5bb70b0fa26d3d9e194a859e6fc64 Mon Sep 17 00:00:00 2001 From: Juerd Waalboer Date: Thu, 28 Feb 2013 16:31:05 +0100 Subject: [PATCH] "give" now takes a reason like "take", only optional args between [] in help. Contributed by BugBlue --- plugins/deposit | 2 +- plugins/give | 23 +++++++++++++++++++---- plugins/take | 2 +- plugins/undo | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/plugins/deposit b/plugins/deposit index 12ee281..878c7fd 100755 --- a/plugins/deposit +++ b/plugins/deposit @@ -2,7 +2,7 @@ # This plugin must at the end in the plugins file. -HELP "deposit []" => "[Create and] deposit into an account"; +HELP "deposit " => "[Create and] deposit into an account"; sub command :Tab(deposit) { my ($self, $cart, $command) = @_; diff --git a/plugins/give b/plugins/give index e8e66b0..caa2061 100755 --- a/plugins/give +++ b/plugins/give @@ -1,6 +1,6 @@ #!perl -HELP "give [ []]" => "Transfer money to user's account"; +HELP "give []" => "Transfer money to user's account"; sub command :Tab(give) { my ($self, $cart, $command) = @_; @@ -22,13 +22,28 @@ sub benedinges :Tab(USERS) { sub amount { my ($self, $cart, $input) = @_; - my $amount = parse_amount($input) + $self->{amount} = parse_amount($input) or return REJECT, "$input: Invalid amount."; my $user = $self->{user}; + my $amount = $self->{amount}; - $cart->add(undef, -$amount, "Given to $user"); - $cart->add($user, +$amount, "Received from \$you"); + 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 ($user = 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; } diff --git a/plugins/take b/plugins/take index 0aff29c..2ec1906 100755 --- a/plugins/take +++ b/plugins/take @@ -1,6 +1,6 @@ #!perl -HELP "take [ []]" => "Take money from users (equal parts)"; +HELP "take "=>"Take money from users (equal parts)"; sub command :Tab(take,steal) { my ($self, $cart, $command) = @_; diff --git a/plugins/undo b/plugins/undo index 0b01c5c..e5eefbe 100755 --- a/plugins/undo +++ b/plugins/undo @@ -1,6 +1,6 @@ #!perl -HELP "undo []" => "Undo a certain transaction"; +HELP "undo " => "Undo a certain transaction"; my $filename = ".revbank.undo";