mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-07 10:45:40 -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::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 $paws = Paws->new(config => {credentials => $creds, region => 'us-east-1'});
|
||||
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');
|
||||
|
||||
|
||||
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);
|
||||
|
||||
use JSON::MaybeXS;
|
||||
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;
|
||||
use strict;
|
||||
|
||||
use LWP::UserAgent;
|
||||
use JSON::MaybeXS;
|
||||
|
||||
sub new {
|
||||
my( $class ) = @_;
|
||||
my $self = bless {}, $class;
|
||||
|
@ -49,12 +52,32 @@ sub post_process {
|
|||
# warn "Sanity checking, new length: ", length $$output_ref;
|
||||
# }
|
||||
|
||||
my $new_text = substr( $$output_ref, 0, 350, '' );
|
||||
my $ua = LWP::UserAgent->new();
|
||||
|
||||
$self->{cache}->set( "pager_$said->{name}", $$output_ref, "10 minutes" ); #Remainder
|
||||
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, '' );
|
||||
|
||||
$self->{cache}->set( "pager_$said->{name}", $$output_ref, "10 minutes" ); #Remainder
|
||||
|
||||
$$output_ref = $new_text;
|
||||
$$output_ref .= "... [Output truncated. Use `more` to read more]";
|
||||
}
|
||||
|
||||
$$output_ref = $new_text;
|
||||
$$output_ref .= "... [Output truncated. Use `more` to read more]";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,17 @@ sub command {
|
|||
|
||||
my $orig_type = $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'; }
|
||||
warn "Found $type: $code";
|
||||
|
|
Loading…
Add table
Reference in a new issue