2015-09-08 10:37:34 +02:00
|
|
|
# File: UrlTitles.pm
|
|
|
|
#
|
|
|
|
# Purpose: Display titles of URLs in channel messages.
|
|
|
|
|
2021-07-11 00:00:22 +02:00
|
|
|
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
|
|
|
# SPDX-License-Identifier: MIT
|
2017-03-05 22:33:31 +01:00
|
|
|
|
2019-09-01 20:01:18 +02:00
|
|
|
package Plugins::UrlTitles;
|
2020-02-09 04:48:05 +01:00
|
|
|
use parent 'Plugins::Plugin';
|
2015-09-08 10:37:34 +02:00
|
|
|
|
2021-06-19 06:23:34 +02:00
|
|
|
use PBot::Imports;
|
2019-07-11 03:40:53 +02:00
|
|
|
|
2015-09-08 10:37:34 +02:00
|
|
|
sub initialize {
|
2020-02-15 23:38:32 +01:00
|
|
|
my ($self, %conf) = @_;
|
|
|
|
$self->{pbot}->{registry}->add_default('text', 'general', 'show_url_titles', $conf{show_url_titles} // 1);
|
|
|
|
$self->{pbot}->{registry}->add_default('array', 'general', 'show_url_titles_channels', $conf{show_url_titles_channels} // '.*');
|
|
|
|
$self->{pbot}->{registry}->add_default('array', 'general', 'show_url_titles_ignore_channels', $conf{show_url_titles_ignore_channels} // 'none');
|
2015-09-08 10:37:34 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->show_url_titles(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.caction', sub { $self->show_url_titles(@_) });
|
2015-09-08 10:37:34 +02:00
|
|
|
}
|
|
|
|
|
2020-02-07 21:24:21 +01:00
|
|
|
sub unload {
|
2020-02-15 23:38:32 +01:00
|
|
|
my ($self) = @_;
|
|
|
|
$self->{pbot}->{event_dispatcher}->remove_handler('irc.public');
|
|
|
|
$self->{pbot}->{event_dispatcher}->remove_handler('irc.caction');
|
2020-02-07 21:24:21 +01:00
|
|
|
}
|
2015-09-08 10:37:34 +02:00
|
|
|
|
|
|
|
sub show_url_titles {
|
2020-02-15 23:38:32 +01:00
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
my $channel = $event->{event}->{to}[0];
|
|
|
|
my ($nick, $user, $host) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host);
|
|
|
|
my $msg = $event->{event}->{args}[0];
|
|
|
|
|
|
|
|
return 0 if not $msg =~ m/https?:\/\/[^\s]/;
|
|
|
|
return 0 if $event->{interpreted};
|
|
|
|
|
2020-03-05 00:38:53 +01:00
|
|
|
if ($self->{pbot}->{ignorelist}->is_ignored($channel, "$nick!$user\@$host")) {
|
2020-03-04 22:24:40 +01:00
|
|
|
return 0;
|
2015-09-08 10:37:34 +02:00
|
|
|
}
|
2020-02-15 23:38:32 +01:00
|
|
|
|
|
|
|
# no titles for unidentified users in +z channels
|
|
|
|
my $chanmodes = $self->{pbot}->{channels}->get_meta($channel, 'MODE');
|
|
|
|
if (defined $chanmodes and $chanmodes =~ m/z/) {
|
|
|
|
my $account = $self->{pbot}->{messagehistory}->{database}->get_message_account($nick, $user, $host);
|
|
|
|
my $nickserv = $self->{pbot}->{messagehistory}->{database}->get_current_nickserv_account($account);
|
|
|
|
return 0 if not defined $nickserv or not length $nickserv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $self->{pbot}->{registry}->get_value('general', 'show_url_titles')
|
|
|
|
and not $self->{pbot}->{registry}->get_value($channel, 'no_url_titles')
|
|
|
|
and not grep { $channel =~ /$_/i } $self->{pbot}->{registry}->get_value('general', 'show_url_titles_ignore_channels')
|
|
|
|
and grep { $channel =~ /$_/i } $self->{pbot}->{registry}->get_value('general', 'show_url_titles_channels'))
|
|
|
|
{
|
|
|
|
my $count = 0;
|
|
|
|
while ($msg =~ s/(https?:\/\/[^\s]+)//i && ++$count <= 3) {
|
|
|
|
my $url = $1;
|
|
|
|
|
|
|
|
if ($self->{pbot}->{antispam}->is_spam('url', $url)) {
|
|
|
|
$self->{pbot}->{logger}->log("Ignoring spam URL $url\n");
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2020-05-02 05:59:51 +02:00
|
|
|
my $context = {
|
2020-05-05 01:51:55 +02:00
|
|
|
from => $channel,
|
|
|
|
nick => $nick,
|
|
|
|
user => $user,
|
|
|
|
host => $host,
|
2020-05-05 03:06:11 +02:00
|
|
|
hostmask => "$nick!$user\@$host",
|
2020-05-05 01:51:55 +02:00
|
|
|
command => "title $nick $url",
|
|
|
|
root_channel => $channel,
|
|
|
|
root_keyword => "title",
|
|
|
|
keyword => "title",
|
|
|
|
arguments => "$nick $url",
|
|
|
|
suppress_no_output => 1,
|
2020-02-15 23:38:32 +01:00
|
|
|
};
|
|
|
|
|
2020-05-02 05:59:51 +02:00
|
|
|
$self->{pbot}->{modules}->execute_module($context);
|
2020-02-15 23:38:32 +01:00
|
|
|
}
|
2015-09-08 10:37:34 +02:00
|
|
|
}
|
2020-02-15 23:38:32 +01:00
|
|
|
return 0;
|
2015-09-08 10:37:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|