Bitlair plugins

This commit is contained in:
polyfloyd 2022-06-12 21:35:25 +02:00
parent 71f1600312
commit ae3cc20c74
7 changed files with 118 additions and 6 deletions

26
plugins/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?";
}

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

@ -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,9 @@ 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
revspace_saldo
3dprint