Show deposit tokens on user info
Also, singular without s
This commit is contained in:
parent
5b0c85d770
commit
b19609c6f6
2 changed files with 18 additions and 2 deletions
|
@ -4,6 +4,7 @@
|
||||||
# voiding of tokens
|
# voiding of tokens
|
||||||
# querying of tokens
|
# querying of tokens
|
||||||
# expiry of tokens
|
# expiry of tokens
|
||||||
|
# token for non-hidden addon (direct product use)
|
||||||
|
|
||||||
use List::Util;
|
use List::Util;
|
||||||
|
|
||||||
|
@ -147,8 +148,11 @@ sub hook_checkout_prepare($class, $cart, $username, $transaction_id, @) {
|
||||||
my $products = RevBank::Plugin::products::read_products();
|
my $products = RevBank::Plugin::products::read_products();
|
||||||
my $addon = $products->{"+$id"} // $products->{$id};
|
my $addon = $products->{"+$id"} // $products->{$id};
|
||||||
my $avail = $had_num_tokens_by_id{$id};
|
my $avail = $had_num_tokens_by_id{$id};
|
||||||
my $only = $avail ? "only $avail" : "0";
|
my $only =
|
||||||
_warn "you have $only deposit tokens of type $id ($addon->{description}).";
|
+ $avail == 0 ? "0 deposit tokens"
|
||||||
|
: $avail == 1 ? "only 1 deposit token"
|
||||||
|
: "only $avail deposit tokens";
|
||||||
|
_warn "you have $only of type $id ($addon->{description}).";
|
||||||
}
|
}
|
||||||
|
|
||||||
# Store data
|
# Store data
|
||||||
|
@ -157,3 +161,14 @@ sub hook_checkout_prepare($class, $cart, $username, $transaction_id, @) {
|
||||||
return ABORT if %warnings_by_id and not $cart->size;
|
return ABORT if %warnings_by_id and not $cart->size;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub hook_user_info ($class, $username, @) {
|
||||||
|
my $tokens_by_id = _read->{$username};
|
||||||
|
my @info;
|
||||||
|
for my $id (sort keys %$tokens_by_id) {
|
||||||
|
my @tokens = @{ $tokens_by_id->{$id} // [] };
|
||||||
|
push @info, sprintf("%dx %s", scalar @tokens, $id);
|
||||||
|
}
|
||||||
|
@info = ("none") if not @info;
|
||||||
|
print "Deposit tokens: ", join(", ", @info), "\n";
|
||||||
|
}
|
||||||
|
|
|
@ -85,6 +85,7 @@ sub _recent($n, $u) {
|
||||||
|
|
||||||
sub balance($self, $u) {
|
sub balance($self, $u) {
|
||||||
_recent(10, $u);
|
_recent(10, $u);
|
||||||
|
call_hooks("user_info", $u);
|
||||||
printf "Balance for $u is \e[1m%s\e[0m\n", RevBank::Users::balance($u)->string("+");
|
printf "Balance for $u is \e[1m%s\e[0m\n", RevBank::Users::balance($u)->string("+");
|
||||||
say "NB: Products/amounts/commands FIRST, username LAST.";
|
say "NB: Products/amounts/commands FIRST, username LAST.";
|
||||||
return ABORT;
|
return ABORT;
|
||||||
|
|
Loading…
Add table
Reference in a new issue