Bitlair changes

This commit is contained in:
polyfloyd 2022-06-12 21:36:56 +02:00
parent 996159a2ad
commit 03084caccb
13 changed files with 134 additions and 14 deletions

View file

@ -72,7 +72,7 @@ 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 < -2300 ? " \e[5;1m(!!)\e[0m" : "";
my $warn = $new->cents < -1337 ? " \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",

26
plugins/bitlair_3dprint Normal file
View file

@ -0,0 +1,26 @@
#!perl
HELP "3dprint <gram>" => "3D-print filament afrekenen";
use Scalar::Util qw(looks_like_number);
sub command :Tab(3dprint) ($self, $cart, $command, @) {
return NEXT if $command ne '3dprint';
return "Gewicht in gram, inclusief supports en purges", \&gram;
}
sub gram($self, $cart, $input, @) {
looks_like_number($input) and $input == int($input) or return REJECT, "Invalid number!";
my $gram = int($input);
return REJECT, "$input: Invalid amount." if $gram <= 0;
my $beneficiary = "3dprinter";
my $amount = 0.10 + $gram * 0.03;
$cart
->add(-$amount, "Given to $beneficiary ($gram g)")
->add_contra($beneficiary, +$amount, "Received from \$you (${gram} g)");
return ACCEPT;
}

17
plugins/bitlair_bigmoney Normal file
View file

@ -0,0 +1,17 @@
#!perl
sub command :Tab(bigmoney) {
my ($self, $cart, $command) = @_;
return NEXT if $command ne "bigmoney";
my @list = sort {
(split " ", $b)[1] <=> (split " ", $a)[1]
} grep {
not RevBank::Users::is_hidden($_)
} slurp("revbank.accounts");
print join "", @list[0..9];
return ACCEPT;
}

19
plugins/bitlair_git Normal file
View file

@ -0,0 +1,19 @@
#!perl
use Cwd ();
sub command { NEXT }
sub hook_checkout_done {
my ($class, $cart, $username, $transaction_id) = @_;
my @cart_printed = map { "\n-> $_" } map { $_->as_printable } $cart->entries;
my $fn = "/tmp/revbank$$.commit";
open my $fh, ">", $fn or warn $!;
print $fh "$username ($transaction_id)\n@cart_printed";
close $fh or warn $!;
my $output = `(cp revbank.accounts revbank.market revbank.products ~/data.git/ && cd ~/data.git/ && git commit -a -F $fn) 2>&1`;
warn "Meh, gitfaal: $output" if $?;
}

19
plugins/bitlair_mqtt Normal file
View file

@ -0,0 +1,19 @@
#!perl
use Cwd ();
use Net::MQTT::Simple;
my $mqtt = Net::MQTT::Simple->new("mqtt.bitlair.nl");
sub command { NEXT }
sub hook_checkout {
my ($class, $cart, $user, $transaction_id) = @_;
my @entries = $cart->entries('product_id') or return;
for my $entry (@entries) {
$mqtt->publish("bitlair/pos/product" => $entry->{description})
for 1..$entry->quantity;
}
}

15
plugins/bitlair_nomunnie Normal file
View file

@ -0,0 +1,15 @@
#!perl
use IO::Socket::IP;
use Net::MQTT::Simple "mqtt.bitlair.nl";
sub command { NEXT }
sub hook_user_balance {
my ($class, $user, $old, $delta, $new, $transaction_id) = @_;
return if $new >= -13.37;
return if RevBank::Users::is_hidden($user);
publish "bitlair/bank/shame" => "NO MUNNIE?";
}

View file

@ -46,6 +46,10 @@ sub how :Tab(&how_tab) ($self, $cart, $input, @) {
return shift @{ $how->{prompts} }, \&how_prompt;
}
if ( ($input eq "iban") && ($self->{amount} < 10 || $self->{amount} == 25) ) {
return REJECT, "\n\e[31;1mPlease transfer at least 10 EUR and not 25 or 32 EUR when using iban\e[0m\n\n";
}
my $contra =
$how->{_key} eq 'cash' ? '-cash'
: $how->{_key} eq 'reimburse' ? '-expenses/reimbursed'

View file

@ -20,8 +20,8 @@
use IPC::Open2 qw(open2);
use List::Util qw(sum);
my $iban = "NL99ABCD1234567890";
my $beneficiary = "Account Name";
my $iban = "NL89RABO0111741386";
my $beneficiary = "Stichting Bitlair";
sub hook_checkout($class, $cart, $user, $transaction_id, @) {
my @entries = $cart->entries("is_deposit");
@ -41,7 +41,7 @@ sub hook_checkout($class, $cart, $user, $transaction_id, @) {
"EUR" . $amount, # Amount
"",
"",
"rb $user",
"Deposit $user (RB QR)",
"",
);
close $in;
@ -57,6 +57,8 @@ sub hook_checkout($class, $cart, $user, $transaction_id, @) {
$lines[3] =~ s/$/ EPC QR codes. N26 also works./;
$lines[5] =~ s/$/ For manual transfers, use this/;
$lines[6] =~ s/$/ IBAN: $iban/;
$lines[7] =~ s/$/ Benificiary: $beneficiary/;
$lines[8] =~ s/$/ Description: Deposit $user/;
print @lines;
}

View file

@ -5,10 +5,11 @@ sub hook_deposit_methods($class, $message, $hash, @) {
Please type one of the following:
'iban': IBAN transfer (NL 69 ABNA 0431 1582 07)
'iban': IBAN transfer (Min 10 EUR / NL89 RABO 0111 7413 86)
'cash': Cash in the cash box
'reimburse': Reimbursement of expenses agreed upon in advance
Note: we require an invoice or receipt with this exact amount!
Note #1: we require an invoice or receipt with this exact amount!
Note #2: please do not use this plugin for amounts >20 EUR
'other': Provide a manual description
END

8
plugins/revspace_cokeurl Normal file
View file

@ -0,0 +1,8 @@
# Accept the odd QR-codes on Coke (and Fanta, etc.) cans, as they also contain the EAN.
# For this plugin to be useful, it needs to be BEFORE "users" in "revbank.plugins".
sub command {
$_[2] =~ s@^https?://(coke|fanta)url.com/q/srn@@gi; # input is actually a mutable string
return NEXT;
}

View file

@ -3,7 +3,7 @@ use LWP::UserAgent;
use JSON;
my $ua = LWP::UserAgent->new(agent => "revbank");
my $backend_url = "https://deposit.revspace.nl/mollie.php";
my $backend_url = "https://deposit.bitlair.nl/revbank_plugin_backend";
sub backend_call($hash) {
#$hash->{test} = 1; # use mollie test environment

View file

@ -17,7 +17,7 @@ sub hook_checkout_done($class, $cart, $user, $transaction_id, @) {
my $balance = RevBank::Users::balance($user) or return;
my $since = RevBank::Users::since($user);
if ($balance < -22.00) {
if ($balance < -13.37) {
_box(
"Hoi $user,",
"",

View file

@ -9,31 +9,32 @@ beep_terminal
#cash_drawer
idle
#json
nomoney
#nomoney
repeat
deduplicate # wants to be after 'repeat'
restart
sighup
sigint
#stock
stock
#vat # configure before using
#warnings
window_title
bitlair_git
# Then, specific commands:
adduser_note
adduser
#cash # cash tracking also requires deposit_methods to make sense
cash # cash tracking also requires deposit_methods to make sense
deposit
#deposit_methods # Extra options for 'deposit'. Edit/configure first!
#deposit_iban_qr # QR code display, edit/configure first! (needs qrencode(1))
deposit_methods # Extra options for 'deposit'. Edit/configure first!
deposit_iban_qr # QR code display, edit/configure first! (needs qrencode(1))
dinnerbonus
edit
give
grandtotal
help
#skim # cash tracking also requires deposit_methods to make sense
skim # cash tracking also requires deposit_methods to make sense
split
take
tail
@ -44,6 +45,7 @@ withdraw
# Then, plugins that apply heuristics
revspace_cokeurl
#statiegeld # wants to be before 'products'; matches product IDs
#statiegeld_tokens
products # matches product IDs (barcodes)
@ -53,3 +55,10 @@ users # matches usernames
regex_gtin # matches GTINs in URLs and element strings
url # matches other URLs
#deprecated_raw # matches amounts
bitlair_bigmoney
bitlair_mqtt
bitlair_nomunnie
bitlair_3dprint
revspace_saldo
revspace_mollie