New plugin: warnings
This commit is contained in:
parent
1b744e421d
commit
faa1504d63
1 changed files with 43 additions and 0 deletions
43
plugins/warnings
Executable file
43
plugins/warnings
Executable file
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Reference in a new issue