3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-20 02:49:49 +01:00

WebPaste: increase timeout back to 10 seconds; minor clean-ups

This commit is contained in:
Pragmatic Software 2020-02-03 12:27:45 -08:00
parent 866d802850
commit 66201585fe

View File

@ -21,10 +21,7 @@ use Carp ();
use Encode; use Encode;
sub new { sub new {
if (ref($_[1]) eq 'HASH') { Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference" if ref($_[1]) eq 'HASH';
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference");
}
my ($class, %conf) = @_; my ($class, %conf) = @_;
my $self = bless {}, $class; my $self = bless {}, $class;
$self->initialize(%conf); $self->initialize(%conf);
@ -33,8 +30,7 @@ sub new {
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{paste_sites} = [ $self->{paste_sites} = [
sub { $self->paste_ixio(@_) }, sub { $self->paste_ixio(@_) },
@ -51,7 +47,6 @@ sub get_paste_site {
if (++$self->{current_site} >= @{$self->{paste_sites}}) { if (++$self->{current_site} >= @{$self->{paste_sites}}) {
$self->{current_site} = 0; $self->{current_site} = 0;
} }
return $subref; return $subref;
} }
@ -76,24 +71,17 @@ sub paste {
last; last;
} }
} }
return $result; return $result;
} }
sub paste_ixio { sub paste_ixio {
my ($self, $text) = @_; my ($self, $text) = @_;
my $ua = LWP::UserAgent::Paranoid->new(request_timeout => 10);
my $ua = LWP::UserAgent::Paranoid->new(request_timeout => 3);
$ua->agent("Mozilla/5.0"); $ua->agent("Mozilla/5.0");
push @{ $ua->requests_redirectable }, 'POST'; push @{ $ua->requests_redirectable }, 'POST';
my %post = ('f:1' => $text); my %post = ('f:1' => $text);
my $response = $ua->post("http://ix.io", \%post); my $response = $ua->post("http://ix.io", \%post);
return "error pasting: " . $response->status_line if not $response->is_success;
if (not $response->is_success) {
return "error pasting: " . $response->status_line;
}
my $result = $response->content; my $result = $response->content;
$result =~ s/^\s+//; $result =~ s/^\s+//;
$result =~ s/\s+$//; $result =~ s/\s+$//;