
This should have been done much earlier, but wasn't done for nostalgic reasons. To new users, it didn't make sense that you could just enter an amount, and revbank would just accept that as "withdrawal or unlisted product". It existed for backwards compatibility with the very first revbank version, which didn't have a product list, and which was not yet used with a barcode scanner. You would simply enter the amount and your name, and there were no further statistics. Nowadays, there are statistics that are messed up if you don't use the product codes. And some people were looking for a withdrawal command, and try 'take' as that seems closest to it, but which instead transfers money to another account. Additionally, some texts were changed for improved clarity. ("Enter username to pay", when withdrawing, was confusing: one expects money back, not to pay more.)
69 lines
1.8 KiB
Perl
69 lines
1.8 KiB
Perl
package RevBank::Messages;
|
|
|
|
use v5.28;
|
|
use warnings;
|
|
use feature qw(signatures);
|
|
no warnings qw(experimental::signatures);
|
|
|
|
use RevBank::Global;
|
|
use base 'RevBank::Plugin';
|
|
|
|
# Don't edit this file just to change the messages. Instead, RTFM and define
|
|
# your own hooks.
|
|
|
|
BEGIN {
|
|
RevBank::Plugins::register("RevBank::Messages");
|
|
}
|
|
|
|
sub command { return NEXT; }
|
|
sub id { 'built in messages' }
|
|
|
|
sub hook_startup {
|
|
say "\e[0m\n\n\nWelcome to the RevBank Shell, version $::VERSION\n";
|
|
}
|
|
|
|
sub hook_plugin_fail($class, $plugin, $error, @) {
|
|
warn "Plugin '$plugin' failed: $error\n";
|
|
}
|
|
|
|
sub hook_cart_changed($class, $cart, @) {
|
|
$cart->size or return;
|
|
say "Pending:";
|
|
$cart->display;
|
|
|
|
if (not $cart->entries('refuse_checkout')) {
|
|
my $sum = $cart->sum;
|
|
my $what = $sum->cents > 0 ? "add" : $cart->entries('is_withdrawal') ? "deduct" : "pay";
|
|
my $dir = $sum->cents > 0 ? "to" : "from";
|
|
my $abs = $sum->abs;
|
|
say "Enter username to $what $abs $dir your account; type 'abort' to abort.";
|
|
}
|
|
}
|
|
|
|
sub hook_abort($class, $cart, @) {
|
|
say "\e[1;4mABORTING TRANSACTION.\e[0m";
|
|
}
|
|
|
|
sub hook_invalid_input($class, $cart, $word, @) {
|
|
say "$word: No such product, user, or command.";
|
|
}
|
|
|
|
sub hook_reject($class, $plugin, $reason, $abort, @) {
|
|
say $abort ? $reason : "$reason Enter 'abort' to abort.";
|
|
}
|
|
|
|
sub hook_user_balance($class, $username, $old, $delta, $new, @) {
|
|
my $sign = $delta->cents >= 0 ? '+' : '-';
|
|
my $rood = $new->cents < 0 ? '31;' : '';
|
|
my $abs = $delta->abs;
|
|
my $warn = $new->cents < -1984 ? " \e[5;1m(!!)\e[0m" : "";
|
|
|
|
$_ = $_->string("+") for $old, $new;
|
|
printf "New balance for $username: $old $sign $abs = \e[${rood}1m$new\e[0m$warn\n",
|
|
}
|
|
|
|
sub hook_user_created($class, $username, @) {
|
|
say "New account '$username' created.";
|
|
}
|
|
|
|
1;
|