diff --git a/plugins/warnings b/plugins/warnings new file mode 100755 index 0000000..ebf46f1 --- /dev/null +++ b/plugins/warnings @@ -0,0 +1,43 @@ +#!perl + +# The file format for 'revbank.warnings' is simply two whitespace separated +# columns: product id (or /regex/ for descriptions) and the warning text. + +sub _read_warnings { + open my $fh, 'revbank.warnings' or die $!; + return map { + my ($matcher, $text) = split " ", $_, 2; + chomp $text; + + my ($regex) = $matcher =~ m[^/([^/]+)/$]; + + $regex + ? sub { + my ($id, $desc) = @_; + $desc =~ /$regex/i ? $text : (); + } + : sub { + my ($id, $desc) = @_; + (grep { $_ eq $id } split /,/, $matcher) ? $text : (); + } + } grep /\S/, grep !/^\s*#/, readline $fh; +} + +sub command { NEXT } + +sub hook_add { + my ($class, $cart, $user, $item) = @_; + return if defined $user; # skip market items + return if not exists $item->{product_id}; # skip unlisted, deposit, give, take + + my @warnings = map { + $_->( $item->{product_id}, $item->{description} ) + } _read_warnings; + + if (@warnings) { + print "\e[7m>> $_ <<\e[0m " for @warnings; + sleep 2; + print "\n"; + } +} +