mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-07 15:55:42 -04:00
about to do stuff
This commit is contained in:
parent
37882224c8
commit
d4cd4be2cd
2 changed files with 18 additions and 26 deletions
|
@ -16,9 +16,9 @@ http_plugin_port 1092
|
||||||
port 10092
|
port 10092
|
||||||
</console>
|
</console>
|
||||||
|
|
||||||
<web>
|
<restapi>
|
||||||
enabled no
|
enabled yes
|
||||||
</web>
|
</restapi>
|
||||||
|
|
||||||
<pastebot>
|
<pastebot>
|
||||||
enabled no
|
enabled no
|
||||||
|
|
|
@ -4,11 +4,8 @@ use Bot::BB3::Logger;
|
||||||
use POE;
|
use POE;
|
||||||
use POE::Component::Server::SimpleHTTP;
|
use POE::Component::Server::SimpleHTTP;
|
||||||
use HTTP::Status;
|
use HTTP::Status;
|
||||||
use CGI; #Heh.
|
|
||||||
use strict;
|
use strict;
|
||||||
|
use JSON::MaybeXS qw/decode_json encode_json/;
|
||||||
local $/;
|
|
||||||
my $HTML_TEMPLATE = <DATA>;
|
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my( $class, $conf, $plugin_manager ) = @_;
|
my( $class, $conf, $plugin_manager ) = @_;
|
||||||
|
@ -55,19 +52,17 @@ sub _start {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub display_page {
|
sub display_page {
|
||||||
my( $self, $req, $resp, $name, $output ) = @_[OBJECT,ARG0,ARG1,ARG2,ARG3];
|
my( $self, $req, $resp, $name, $output, $said ) = @_[OBJECT,ARG0,ARG1,ARG2,ARG3,ARG4];
|
||||||
my $html = $HTML_TEMPLATE;
|
|
||||||
|
|
||||||
warn "Display Page Activating: $req - $resp - $output\n";
|
warn "Display Page Activating: $req - $resp - $output\n";
|
||||||
|
|
||||||
|
if ($said->{addressed} || $output !~ /^\s*$/) {
|
||||||
if( $output ) {
|
$output = sprintf '@%s %s', $said->{name}, $output;
|
||||||
$html =~ s/\%\%OUTPUT\%\%/$output/;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$resp->code(RC_OK);
|
$resp->code(RC_OK);
|
||||||
$resp->content_type("text/plain");
|
$resp->content_type("application/json");
|
||||||
$resp->content( $html );
|
$resp->content( encode_json({"body" => $output, saidobj => $said}) );
|
||||||
|
|
||||||
$_[KERNEL]->post( web_httpd_alias => 'DONE' => $resp );
|
$_[KERNEL]->post( web_httpd_alias => 'DONE' => $resp );
|
||||||
}
|
}
|
||||||
|
@ -80,26 +75,26 @@ sub handle_request {
|
||||||
|
|
||||||
warn "Request: ", $req->content;
|
warn "Request: ", $req->content;
|
||||||
|
|
||||||
my $query = CGI->new( $req->content );
|
my $data = decode_json($req->content);
|
||||||
my $input = $query->param("body");
|
my $input = $data->{body} // "";
|
||||||
my $channel = $query->param("channel");
|
my $channel = $data->{channel} // "#ERROR";
|
||||||
my $name = $query->param("who");
|
my $name = $data->{who} // "ERROR";
|
||||||
|
|
||||||
my @args = "2+2";
|
my @args = "2+2";
|
||||||
warn "Attempting to handle request: $req $resp $input\n";
|
warn "Attempting to handle request: $req $resp $input\n";
|
||||||
|
|
||||||
my $addressed = 0;
|
my $addressed = 0;
|
||||||
|
|
||||||
if ($body =~ /^\@perlbot/i) {
|
if ($input =~ /^\@?perlbot/i) {
|
||||||
$addressed = 1;
|
$addressed = 1;
|
||||||
$body =~ s/^\@perlbot/perlbot:/i;
|
$input =~ s/^\@?perlbot\b//i;
|
||||||
}
|
}
|
||||||
|
|
||||||
# This is obviously silly but I'm unable to figure out
|
# This is obviously silly but I'm unable to figure out
|
||||||
# the correct way to solve this =[
|
# the correct way to solve this =[
|
||||||
my $said = {
|
my $said = {
|
||||||
body => $input,
|
body => $input,
|
||||||
raw_body => $input,
|
raw_body => $data->{body},
|
||||||
my_name => 'perlbot',
|
my_name => 'perlbot',
|
||||||
addressed => $addressed,
|
addressed => $addressed,
|
||||||
recommended_args => \@args,
|
recommended_args => \@args,
|
||||||
|
@ -129,7 +124,7 @@ sub plugin_output {
|
||||||
my $resp = delete $RESP_MAP{ $said->{pci_id} };
|
my $resp = delete $RESP_MAP{ $said->{pci_id} };
|
||||||
|
|
||||||
|
|
||||||
$kernel->yield( display_page => undef, $resp, undef, $output );
|
$kernel->yield( display_page => undef, $resp, undef, $output, $said );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub sig_DIE {
|
sub sig_DIE {
|
||||||
|
@ -137,6 +132,3 @@ sub sig_DIE {
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
__DATA__
|
|
||||||
%%OUTPUT%%
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue