From fc410035cae69d066304abd5c60f779e6cf01958 Mon Sep 17 00:00:00 2001 From: polyfloyd Date: Sun, 12 Jun 2022 21:36:56 +0200 Subject: [PATCH] Bitlair changes --- lib/RevBank/Messages.pm | 2 +- plugins/bitlair_3dprint | 26 ++++++++++++++++++++++++++ plugins/bitlair_bigmoney | 17 +++++++++++++++++ plugins/bitlair_git | 19 +++++++++++++++++++ plugins/bitlair_mqtt | 19 +++++++++++++++++++ plugins/bitlair_nomunnie | 15 +++++++++++++++ plugins/deposit | 4 ++++ plugins/deposit_iban_qr | 6 ++++-- plugins/deposit_methods | 5 +++-- plugins/revspace_cokeurl | 8 ++++++++ plugins/revspace_mollie | 2 +- plugins/revspace_saldo | 2 +- revbank.plugins | 21 +++++++++++++++------ 13 files changed, 133 insertions(+), 13 deletions(-) create mode 100644 plugins/bitlair_3dprint create mode 100644 plugins/bitlair_bigmoney create mode 100644 plugins/bitlair_git create mode 100644 plugins/bitlair_mqtt create mode 100644 plugins/bitlair_nomunnie create mode 100644 plugins/revspace_cokeurl diff --git a/lib/RevBank/Messages.pm b/lib/RevBank/Messages.pm index ae1f61c..1079908 100644 --- a/lib/RevBank/Messages.pm +++ b/lib/RevBank/Messages.pm @@ -72,7 +72,7 @@ sub hook_account_balance($class, $account, $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 $account: $old $sign $abs = \e[${rood}1m$new\e[0m$warn\n", diff --git a/plugins/bitlair_3dprint b/plugins/bitlair_3dprint new file mode 100644 index 0000000..bf45a7d --- /dev/null +++ b/plugins/bitlair_3dprint @@ -0,0 +1,26 @@ +#!perl + +HELP "3dprint " => "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; +} diff --git a/plugins/bitlair_bigmoney b/plugins/bitlair_bigmoney new file mode 100644 index 0000000..6e4991e --- /dev/null +++ b/plugins/bitlair_bigmoney @@ -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; +} diff --git a/plugins/bitlair_git b/plugins/bitlair_git new file mode 100644 index 0000000..afe7144 --- /dev/null +++ b/plugins/bitlair_git @@ -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 $?; +} diff --git a/plugins/bitlair_mqtt b/plugins/bitlair_mqtt new file mode 100644 index 0000000..9ffd004 --- /dev/null +++ b/plugins/bitlair_mqtt @@ -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; + } +} diff --git a/plugins/bitlair_nomunnie b/plugins/bitlair_nomunnie new file mode 100644 index 0000000..c5e97e4 --- /dev/null +++ b/plugins/bitlair_nomunnie @@ -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?"; +} diff --git a/plugins/deposit b/plugins/deposit index 0bac34d..8b64d44 100644 --- a/plugins/deposit +++ b/plugins/deposit @@ -37,6 +37,10 @@ sub amount :Tab(13.37,42) ($self, $cart, $input, @) { sub how :Tab(&how_tab) ($self, $cart, $input, @) { my %methods = %{ $self->{deposit_methods} }; + if ($input eq "iban") { + return ABORT, "\nBank transactions now go via iDeal:\n\n >>> https://deposit.bitlair.nl <<<\n\n" + } + my $how = $self->{how} = $methods{$input} or return REJECT, "'$input' is not a valid answer."; diff --git a/plugins/deposit_iban_qr b/plugins/deposit_iban_qr index a93ad7b..3462185 100644 --- a/plugins/deposit_iban_qr +++ b/plugins/deposit_iban_qr @@ -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, $account, $transaction_id, @) { my @entries = $cart->entries("is_deposit"); @@ -57,6 +57,8 @@ sub hook_checkout($class, $cart, $account, $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; } diff --git a/plugins/deposit_methods b/plugins/deposit_methods index dca74fd..cf17d52 100644 --- a/plugins/deposit_methods +++ b/plugins/deposit_methods @@ -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': Deprecated. Abort and go to https://deposit.bitlair.nl instead '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 diff --git a/plugins/revspace_cokeurl b/plugins/revspace_cokeurl new file mode 100644 index 0000000..dc63b23 --- /dev/null +++ b/plugins/revspace_cokeurl @@ -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; +} diff --git a/plugins/revspace_mollie b/plugins/revspace_mollie index bb09cc8..f25c3c1 100644 --- a/plugins/revspace_mollie +++ b/plugins/revspace_mollie @@ -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 diff --git a/plugins/revspace_saldo b/plugins/revspace_saldo index b9eb1eb..73d1fee 100644 --- a/plugins/revspace_saldo +++ b/plugins/revspace_saldo @@ -17,7 +17,7 @@ sub hook_checkout_done($class, $cart, $account, $transaction_id, @) { my $balance = RevBank::Accounts::balance($account) or return; my $since = RevBank::Accounts::since($account); - if ($balance < -22.00) { + if ($balance < -13.37) { _box( "Hoi $account,", "", diff --git a/revbank.plugins b/revbank.plugins index ee632b0..d7acb3a 100644 --- a/revbank.plugins +++ b/revbank.plugins @@ -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