revbank/plugins/market
2013-02-27 23:12:13 +01:00

37 lines
928 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;
$username = parse_user($username) or next;
$seller = parse_amount($seller) or next;
$space = parse_amount($space) or next;
$cart->add(undef, -($seller + $space), $description);
$cart->add($username, 0+$seller, "\$you bought $description")
if 0+$seller;
return ACCEPT;
}
return NEXT;
}