<commit_before># File: WebPaste.pm
# Author: pragma_
#
# Purpose: Pastes text to web paste sites.

# 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/.

package PBot::WebPaste;

use warnings;
use strict;

use Time::HiRes qw/gettimeofday/;
use Time::Duration;
use LWP::UserAgent;
use Carp ();

sub new {
  if (ref($_[1]) eq 'HASH') {
    Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference");
  }

  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->{paste_sites} = [
    sub { $self->paste_ixio(@_) },
  ];

  $self->{current_site} = 0;
}

sub get_paste_site {
  my ($self) = @_;

  my $subref = $self->{paste_sites}->[$self->{current_site}];

  if (++$self->{current_site} >= @{$self->{paste_sites}}) {
    $self->{current_site} = 0;
  }

  return $subref;
}

sub paste {
  my ($self, $text) = @_;

  $text =~ s/(.{120})\s/$1\n/g;
  my $result;

  for (my $tries = 5; $tries > 0; $tries--) {
    my $paste_site = $self->get_paste_site;
    $result = $paste_site->($text);

    if ($result !~ m/error pasting/) {
      last;
    }
  }

  return $result;
}

sub paste_ixio {
  my $self = shift;
  my $text = join(' ', @_);

  $text =~ s/(.{120})\s/$1\n/g;

  my $ua = LWP::UserAgent->new();
  $ua->agent("Mozilla/5.0");<commit_msg>WebPaste: Encode output as UTF-8<commit_after># File: WebPaste.pm
# Author: pragma_
#
# Purpose: Pastes text to web paste sites.

# 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/.

package PBot::WebPaste;

use warnings;
use strict;

use Time::HiRes qw/gettimeofday/;
use Time::Duration;
use LWP::UserAgent;
use Carp ();
use Encode;

sub new {
  if (ref($_[1]) eq 'HASH') {
    Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference");
  }

  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->{paste_sites} = [
    sub { $self->paste_ixio(@_) },
  ];

  $self->{current_site} = 0;
}

sub get_paste_site {
  my ($self) = @_;

  my $subref = $self->{paste_sites}->[$self->{current_site}];

  if (++$self->{current_site} >= @{$self->{paste_sites}}) {
    $self->{current_site} = 0;
  }

  return $subref;
}

sub paste {
  my ($self, $text) = @_;

  $text = encode('UTF-8', $text);
  $text =~ s/(.{120})\s/$1\n/g;

  my $result;
  for (my $tries = 5; $tries > 0; $tries--) {
    my $paste_site = $self->get_paste_site;
    $result = $paste_site->($text);

    if ($result !~ m/error pasting/) {
      last;
    }
  }

  return $result;
}

sub paste_ixio {
  my $self = shift;
  my $text = join(' ', @_);

  $text =~ s/(.{120})\s/$1\n/g;

  my $ua = LWP::UserAgent->new();
  $ua->agent("Mozilla/5.0");
{'fraction_non_alphanumeric': 0.19914867740954698, 'fraction_numerical': 0.012161751292186074, 'mean_word_length': 3.169835234474018, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1150713', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1291, 'n_words': 330}