2015-09-08 10:37:34 +02:00
|
|
|
# File: UrlTitles.pm
|
|
|
|
# Author: pragma-
|
|
|
|
#
|
|
|
|
# Purpose: Display titles of URLs in channel messages.
|
|
|
|
|
2017-03-05 22:33:31 +01:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2019-09-01 20:01:18 +02:00
|
|
|
package Plugins::UrlTitles;
|
2015-09-08 10:37:34 +02:00
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
2019-07-11 03:40:53 +02:00
|
|
|
use feature 'unicode_strings';
|
|
|
|
|
2015-09-08 10:37:34 +02:00
|
|
|
use Carp ();
|
|
|
|
|
|
|
|
sub new {
|
|
|
|
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
|
|
|
|
my ($class, %conf) = @_;
|
|
|
|
my $self = bless {}, $class;
|
|
|
|
$self->initialize(%conf);
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub initialize {
|
|
|
|
my ($self, %conf) = @_;
|
|
|
|
|
|
|
|
$self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
|
|
|
|
|
|
|
|
$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');
|
|
|
|
|
|
|
|
$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(@_) });
|
|
|
|
}
|
|
|
|
|
|
|
|
sub unload {
|
|
|
|
my $self = shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub show_url_titles {
|
|
|
|
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];
|
|
|
|
|
2015-09-08 14:30:02 +02:00
|
|
|
return 0 if not $msg =~ m/https?:\/\/[^\s]/;
|
2019-05-31 17:59:59 +02:00
|
|
|
return 0 if $event->{interpreted};
|
2015-09-08 14:30:02 +02:00
|
|
|
|
2015-09-08 10:37:34 +02:00
|
|
|
if ($self->{pbot}->{ignorelist}->check_ignore($nick, $user, $host, $channel)) {
|
2020-01-25 21:31:08 +01:00
|
|
|
my $admin = $self->{pbot}->{users}->loggedin_admin($channel, "$nick!$user\@$host");
|
2015-09-08 10:37:34 +02:00
|
|
|
if (!defined $admin || $admin->{level} < 10) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-11 07:57:00 +02: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;
|
|
|
|
}
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($self->{pbot}->{registry}->get_value('general', 'show_url_titles')
|
2015-09-08 13:43:24 +02:00
|
|
|
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')) {
|
|
|
|
|
2019-05-31 17:59:59 +02:00
|
|
|
my $count = 0;
|
|
|
|
while ($msg =~ s/(https?:\/\/[^\s]+)//i && ++$count <= 3) {
|
2018-08-06 18:41:18 +02:00
|
|
|
my $url = $1;
|
|
|
|
|
2018-08-06 18:49:03 +02:00
|
|
|
if ($self->{pbot}->{antispam}->is_spam('url', $url)) {
|
|
|
|
$self->{pbot}->{logger}->log("Ignoring spam URL $url\n");
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2017-11-19 22:38:55 +01:00
|
|
|
my $stuff = {
|
|
|
|
from => $channel, nick => $nick, user => $user, host => $host,
|
2018-08-06 18:41:18 +02:00
|
|
|
command => "title $nick $url", root_channel => $channel, root_keyword => "title",
|
|
|
|
keyword => "title", arguments => "$nick $url"
|
2017-11-19 22:38:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
$self->{pbot}->{factoids}->{factoidmodulelauncher}->execute_module($stuff);
|
2015-09-08 10:37:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|