From 37882224c82b6f2db8580b62e1d0387fd9253bd6 Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Sat, 8 Aug 2020 23:19:03 -0400 Subject: [PATCH] working on new api --- lib/Bot/BB3/Roles/{Web.pm => RestAPI.pm} | 41 ++++++++++++------------ 1 file changed, 21 insertions(+), 20 deletions(-) rename lib/Bot/BB3/Roles/{Web.pm => RestAPI.pm} (78%) diff --git a/lib/Bot/BB3/Roles/Web.pm b/lib/Bot/BB3/Roles/RestAPI.pm similarity index 78% rename from lib/Bot/BB3/Roles/Web.pm rename to lib/Bot/BB3/Roles/RestAPI.pm index 9e79b10..e305f36 100644 --- a/lib/Bot/BB3/Roles/Web.pm +++ b/lib/Bot/BB3/Roles/RestAPI.pm @@ -1,4 +1,4 @@ -package Bot::BB3::Roles::Web; +package Bot::BB3::Roles::RestAPI; use Bot::BB3::Logger; use POE; @@ -66,7 +66,7 @@ sub display_page { } $resp->code(RC_OK); - $resp->content_type("text/html"); + $resp->content_type("text/plain"); $resp->content( $html ); $_[KERNEL]->post( web_httpd_alias => 'DONE' => $resp ); @@ -82,24 +82,34 @@ sub handle_request { my $query = CGI->new( $req->content ); my $input = $query->param("body"); + my $channel = $query->param("channel"); + my $name = $query->param("who"); my @args = "2+2"; warn "Attempting to handle request: $req $resp $input\n"; + my $addressed = 0; + + if ($body =~ /^\@perlbot/i) { + $addressed = 1; + $body =~ s/^\@perlbot/perlbot:/i; + } + # This is obviously silly but I'm unable to figure out # the correct way to solve this =[ my $said = { body => $input, raw_body => $input, - my_name => 'WI', - addressed => 1, + my_name => 'perlbot', + addressed => $addressed, recommended_args => \@args, - channel => '*web', - name => 'CC', - ircname => 'CC', + channel => $channel // "#error", + name => $name // "ERROR", + ircname => $name // "ERROR", host => '*special', #TODO fix this to be an actual hostname! # Make sure it isn't messed up by the alias feature.. server => '*special', + nolearn => 1, }; # Avoid passing around the full reference @@ -112,7 +122,9 @@ sub handle_request { sub plugin_output { my( $self, $kernel, $said, $output ) = @_[OBJECT,KERNEL,ARG0,ARG1]; - $output =~ s/^\s*CC://; # Clear the response name + my $name = $said->{name}; + + $output =~ s/^\s*$name:/\@$name/; # Clear the response name my $resp = delete $RESP_MAP{ $said->{pci_id} }; @@ -127,15 +139,4 @@ sub sig_DIE { 1; __DATA__ - - - - - - Welcome to the BB3 web interface. You can interact with the bot by typing bot commands in to the text box below. It acts exactly as if you have typed the command in a private message to the bot. Try the command 'help' or 'plugins' (no quotes). -
- Input:
-
- Output: %%OUTPUT%% - - +%%OUTPUT%%