mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-07 17:05:43 -04:00
Make more plugin use pastebin
This commit is contained in:
parent
efd9f86162
commit
5cf5060bf0
3 changed files with 49 additions and 13 deletions
|
@ -6,6 +6,16 @@ use JSON;
|
||||||
use Paws;
|
use Paws;
|
||||||
use Paws::Credential::Explicit;
|
use Paws::Credential::Explicit;
|
||||||
|
|
||||||
|
my $seed = sprintf "%04d", rand()*10000;
|
||||||
|
|
||||||
|
return sub {
|
||||||
|
my( $said ) = @_;
|
||||||
|
|
||||||
|
my $body = $said->{body};
|
||||||
|
my $userid = $said->{server}.$said->{channel}.$said->{nick}.$seed;
|
||||||
|
$userid =~ s/\W/_/g; # hide any non word chars
|
||||||
|
|
||||||
|
|
||||||
my $creds = Paws::Credential::Explicit->new(access_key => '', secret_key => '');
|
my $creds = Paws::Credential::Explicit->new(access_key => '', secret_key => '');
|
||||||
my $paws = Paws->new(config => {credentials => $creds, region => 'us-east-1'});
|
my $paws = Paws->new(config => {credentials => $creds, region => 'us-east-1'});
|
||||||
my $cognito = $paws->service("CognitoIdentity");
|
my $cognito = $paws->service("CognitoIdentity");
|
||||||
|
@ -20,18 +30,11 @@ my $realcreds = Paws::Credential::Explicit->new(access_key=>$cresp->AccessKeyId,
|
||||||
my $service_obj = $paws->service('LexRuntime', credentials => $realcreds, region=>'us-east-1');
|
my $service_obj = $paws->service('LexRuntime', credentials => $realcreds, region=>'us-east-1');
|
||||||
|
|
||||||
|
|
||||||
return sub {
|
|
||||||
my( $said ) = @_;
|
|
||||||
|
|
||||||
my $body = $said->{body};
|
|
||||||
my $userid = $said->{server}.$said->{channel}.$said->{nick};
|
|
||||||
$userid =~ s/\W/_/g; # hide any non word chars
|
|
||||||
|
|
||||||
my $resp = $service_obj->PostText(BotName=>'BookTrip', BotAlias=>'perlbot',InputText=>$body,UserId=>$userid);
|
my $resp = $service_obj->PostText(BotName=>'BookTrip', BotAlias=>'perlbot',InputText=>$body,UserId=>$userid);
|
||||||
|
|
||||||
use JSON::MaybeXS;
|
use JSON::MaybeXS;
|
||||||
my $json = JSON->new();
|
my $json = JSON->new();
|
||||||
printf "%s : %s\n", $resp->Message, $json->encode(\%{$resp->Slots->Map});
|
printf "%s : %s\n", $resp->Message, eval{$json->encode(\%{$resp->Slots->Map})};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package Bot::BB3::Plugin::More;
|
package Bot::BB3::Plugin::More;
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
|
use LWP::UserAgent;
|
||||||
|
use JSON::MaybeXS;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my( $class ) = @_;
|
my( $class ) = @_;
|
||||||
my $self = bless {}, $class;
|
my $self = bless {}, $class;
|
||||||
|
@ -49,6 +52,24 @@ sub post_process {
|
||||||
# warn "Sanity checking, new length: ", length $$output_ref;
|
# warn "Sanity checking, new length: ", length $$output_ref;
|
||||||
# }
|
# }
|
||||||
|
|
||||||
|
my $ua = LWP::UserAgent->new();
|
||||||
|
|
||||||
|
my $res = $ua->post("https://perl.bot/api/v1/paste", {
|
||||||
|
paste => $$output_ref,
|
||||||
|
description => 'More text for '.$said->{body},
|
||||||
|
username => $said->{nick},
|
||||||
|
language => 'text'
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($res->is_success()) {
|
||||||
|
my $content = $res->decoded_content;
|
||||||
|
my $data = decode_json $content;
|
||||||
|
|
||||||
|
my $new_text = substr( $$output_ref, 0, 350, '' );
|
||||||
|
|
||||||
|
$$output_ref = $new_text
|
||||||
|
$$output_ref .= "... [Output truncated. ".$data->{url}." ]";
|
||||||
|
} else {
|
||||||
my $new_text = substr( $$output_ref, 0, 350, '' );
|
my $new_text = substr( $$output_ref, 0, 350, '' );
|
||||||
|
|
||||||
$self->{cache}->set( "pager_$said->{name}", $$output_ref, "10 minutes" ); #Remainder
|
$self->{cache}->set( "pager_$said->{name}", $$output_ref, "10 minutes" ); #Remainder
|
||||||
|
@ -56,6 +77,8 @@ sub post_process {
|
||||||
$$output_ref = $new_text;
|
$$output_ref = $new_text;
|
||||||
$$output_ref .= "... [Output truncated. Use `more` to read more]";
|
$$output_ref .= "... [Output truncated. Use `more` to read more]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
no warnings 'void';
|
no warnings 'void';
|
||||||
|
|
|
@ -75,7 +75,17 @@ sub command {
|
||||||
|
|
||||||
my $orig_type = $type;
|
my $orig_type = $type;
|
||||||
$type = $translations{$type};
|
$type = $translations{$type};
|
||||||
$type = "perl6" if ($orig_type =~ /^[ws]*$/i && $said->{channel} eq '#perl6');
|
# $type = "perl6" if ($orig_type =~ /^[ws]*$/i && $said->{channel} eq '#perl6');
|
||||||
|
|
||||||
|
# We're in #perl6 and we weren't nested or addressed
|
||||||
|
if ($said->{channel} eq "#perl6" && (!$said->{addressed} && !$said->{nested}) && $orig_type =~ /^[ws]*$/) {
|
||||||
|
return ("handled", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
# we were addressed, but not nested, in #perl6. Switch to perl6, otherwise use perl5
|
||||||
|
if ($said->{channel} eq '#perl6' && $said->{addressed} && !$said->{nested} && $orig_type =~ /^[ws]*$/) {
|
||||||
|
$type = "perl6"
|
||||||
|
}
|
||||||
|
|
||||||
if( not $type ) { $type = 'perl'; }
|
if( not $type ) { $type = 'perl'; }
|
||||||
warn "Found $type: $code";
|
warn "Found $type: $code";
|
||||||
|
|
Loading…
Add table
Reference in a new issue