revbank/plugins/market
Juerd Waalboer 7321b99c6b New plugin: market
Hackerspace members sell their surplus components, space profits.
2013-02-26 23:05:37 +01:00

35 lines
832 B
Perl
Executable file

#!perl
HELP "market" => "Edit market list";
my $filename = 'revbank.market';
sub command :Tab(market) {
my ($self, $cart, $command) = @_;
if ($command eq 'market') {
system $ENV{EDITOR} || 'vi', $filename;
return ACCEPT;
}
my @products;
open my $fh, '<', $filename or die $!;
/\S/ && !/^\s*#/ and push @products, [split " ", $_, 5] while readline $fh;
chomp @$_ for @products;
for my $fields (@products) {
my ($username, $id, $seller, $space, $description) = @$fields;
next if $command ne $id;
next if $space < 0;
next if $seller < 0;
$cart->add(undef, -($seller + $space), $description);
$cart->add($username, 0+$seller, "\$you bought $description")
if 0+$seller;
return ACCEPT;
}
return NEXT;
}