Skip to content
Snippets Groups Projects
Commit 742700cd authored by Síle Ekaterin Liszka's avatar Síle Ekaterin Liszka
Browse files

Chessa::URI: support filtering.

The `filters()` method applies a set of regexes to each URI in the
input. If there is a match, it returns 1, else 0. This allows for
scripts using Chessa::URI to avoid processing sites unnecessarily.
parent bacc0d30
No related branches found
No related tags found
No related merge requests found
......@@ -126,5 +126,23 @@ sub parse {
}
}
sub filters {
my $self = shift;
my ($input, $filters) = @_;
my @uris = list_uris($input);
my @filters = split ' ', $filters;
foreach my $uri (@uris) {
foreach my $filter (@filters) {
my $regex = qr/$filter/;
if ($uri =~ /$filter/i) {
return 1;
}
}
}
return 0;
}
# A well-fed woof is a happy woof.
0xfeedbeef;
......@@ -28,6 +28,8 @@ my @config = qw(
twitter_bearer_token
google_api_key
twitch_client_id
site_filters
filter_targets
);
for my $i (@config) {
Irssi::settings_add_str('url_title', "url_title_$i", '');
......@@ -54,6 +56,15 @@ sub url_process {
if ((grep {uc($nick) eq uc($_) } @nickblock) || ($text =~ /(notitle)/) || ($text =~ /^[!.\$][a-z]+/i)) {
return;
}
my @channels = split ' ', Irssi::settings_get_str('url_title_filter_targets');
if (grep { uc($target) eq uc($_) } @channels) {
my $filters = Irssi::settings_get_str('url_title_site_filters');
if ($handler->filter($text, $filters)) {
return;
}
}
$handler->parse($text, $on_info, $errors);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment