From 9636995d4247a5b1c2e20c4e2b107cc3e2e71820 Mon Sep 17 00:00:00 2001 From: Mars Kitten <57377187+MarsKittenPro@users.noreply.github.com> Date: Wed, 17 May 2023 12:21:03 +1000 Subject: [PATCH 1/7] Llama Picture Command --- lib/Synergy/Reactor/CatPic.pm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/Synergy/Reactor/CatPic.pm b/lib/Synergy/Reactor/CatPic.pm index df5ec881..33cf47ad 100644 --- a/lib/Synergy/Reactor/CatPic.pm +++ b/lib/Synergy/Reactor/CatPic.pm @@ -191,6 +191,25 @@ sub _build_reactions ($self, @) { return $reactions; } +# Copied cat_pic code +# Because there was no documentation +# Works on terminal, dunno if slack wil be able to display it as an image +# Tried to test it on local slack, but the documentation was pretty bad with the config files +responder llama_pic => { + exclusive => 1, # No idea what this is. + targeted => 1, # Or this + help_titles => [ 'llama pic' ], + help => '*llama pic*: get a picture of a llama', + matcher => sub ($text, @) { + return unless $text =~ /\Allama\spic?\z/i; + return []; + }, +}, sub ($self, $event) { + $event->mark_handled; + + $event->reply("https://llama-as-a-service.vercel.app"); # Might need the webservice to return a url to the image not just redirect +}; + responder cat_pic => { exclusive => 1, targeted => 1, From c63d874f144cafb3970033622b7624c2aa2ac68a Mon Sep 17 00:00:00 2001 From: Mars Kitten <57377187+MarsKittenPro@users.noreply.github.com> Date: Wed, 17 May 2023 13:17:05 +1000 Subject: [PATCH 2/7] fixed caching issue --- lib/Synergy/Reactor/CatPic.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Synergy/Reactor/CatPic.pm b/lib/Synergy/Reactor/CatPic.pm index 33cf47ad..56728344 100644 --- a/lib/Synergy/Reactor/CatPic.pm +++ b/lib/Synergy/Reactor/CatPic.pm @@ -207,7 +207,8 @@ responder llama_pic => { }, sub ($self, $event) { $event->mark_handled; - $event->reply("https://llama-as-a-service.vercel.app"); # Might need the webservice to return a url to the image not just redirect + my $epoch = time(); + $event->reply("https://llama-as-a-service.vercel.app/llama?t=$epoch"); # Might need the webservice to return a url to the image not just redirect, slack needs t so it doesn't cache }; responder cat_pic => { From d25a5ef1a5699ecd54b12fcde2cb996aaa8e7420 Mon Sep 17 00:00:00 2001 From: Mars Kitten <57377187+MarsKittenPro@users.noreply.github.com> Date: Wed, 17 May 2023 13:51:53 +1000 Subject: [PATCH 3/7] now sends the direct links --- lib/Synergy/Reactor/CatPic.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Synergy/Reactor/CatPic.pm b/lib/Synergy/Reactor/CatPic.pm index 56728344..31b512d6 100644 --- a/lib/Synergy/Reactor/CatPic.pm +++ b/lib/Synergy/Reactor/CatPic.pm @@ -207,8 +207,14 @@ responder llama_pic => { }, sub ($self, $event) { $event->mark_handled; - my $epoch = time(); - $event->reply("https://llama-as-a-service.vercel.app/llama?t=$epoch"); # Might need the webservice to return a url to the image not just redirect, slack needs t so it doesn't cache + my $http_request = $self->hub->http_client->GET( + "https://llama-as-a-service.vercel.app/llama_url" + ); + + return $http_request->on_done(sub($res) + { + $event->reply($res->content) + }); }; responder cat_pic => { From 3d44d46b270b6fb2653514b1f7b5e25c0ed87784 Mon Sep 17 00:00:00 2001 From: Mars Kitten <57377187+MarsKittenPro@users.noreply.github.com> Date: Wed, 17 May 2023 14:18:03 +1000 Subject: [PATCH 4/7] llama fax --- lib/Synergy/Reactor/CatPic.pm | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/Synergy/Reactor/CatPic.pm b/lib/Synergy/Reactor/CatPic.pm index 31b512d6..1f9162b1 100644 --- a/lib/Synergy/Reactor/CatPic.pm +++ b/lib/Synergy/Reactor/CatPic.pm @@ -201,7 +201,7 @@ responder llama_pic => { help_titles => [ 'llama pic' ], help => '*llama pic*: get a picture of a llama', matcher => sub ($text, @) { - return unless $text =~ /\Allama\spic?\z/i; + return unless $text =~ /\Allama\spic\z/i; return []; }, }, sub ($self, $event) { @@ -217,6 +217,28 @@ responder llama_pic => { }); }; +responder llama_fax => { + exclusive => 1, # No idea what this is. + targeted => 1, # Or this + help_titles => [ 'llama fax' ], + help => '*llama fax*: get a fact about a llama', + matcher => sub ($text, @) { + return unless $text =~ /\Allama\s(facts?|fax)\z/i; + return []; + }, +}, sub ($self, $event) { + $event->mark_handled; + + my $http_request = $self->hub->http_client->GET( + "https://llama-as-a-service.vercel.app/llama_fax" + ); + + return $http_request->on_done(sub($res) + { + $event->reply($res->content) + }); +}; + responder cat_pic => { exclusive => 1, targeted => 1, From d80bd0ce34ba27527baaafde49c4289de18fe89f Mon Sep 17 00:00:00 2001 From: Mars Kitten <57377187+MarsKittenPro@users.noreply.github.com> Date: Wed, 17 May 2023 15:48:24 +1000 Subject: [PATCH 5/7] Fixed bug and added error checing --- lib/Synergy/Reactor/CatPic.pm | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/Synergy/Reactor/CatPic.pm b/lib/Synergy/Reactor/CatPic.pm index 1f9162b1..84356ee1 100644 --- a/lib/Synergy/Reactor/CatPic.pm +++ b/lib/Synergy/Reactor/CatPic.pm @@ -207,13 +207,18 @@ responder llama_pic => { }, sub ($self, $event) { $event->mark_handled; - my $http_request = $self->hub->http_client->GET( + my $http_future = $self->hub->http_client->GET( "https://llama-as-a-service.vercel.app/llama_url" ); - return $http_request->on_done(sub($res) + return $http_future->on_done(sub($res) { - $event->reply($res->content) + if ($res->code == 200) + { + $event->reply($res->content); + return; + } + $event->reply("Error while retrieving llama pictures!") }); }; @@ -229,13 +234,19 @@ responder llama_fax => { }, sub ($self, $event) { $event->mark_handled; - my $http_request = $self->hub->http_client->GET( + my $http_future = $self->hub->http_client->GET( "https://llama-as-a-service.vercel.app/llama_fax" ); - return $http_request->on_done(sub($res) + return $http_future->on_done(sub($res) { - $event->reply($res->content) + if ($res->code == 200) + { + $event->reply($res->content); + return; + } + + $event->reply("Error while retrieving llama fax!") }); }; From be5910a103902699dab0b731be71ab930d4d0e27 Mon Sep 17 00:00:00 2001 From: Mars Kitten <57377187+MarsKittenPro@users.noreply.github.com> Date: Fri, 19 May 2023 10:44:48 +1000 Subject: [PATCH 6/7] Removed unneeded comments --- lib/Synergy/Reactor/CatPic.pm | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/Synergy/Reactor/CatPic.pm b/lib/Synergy/Reactor/CatPic.pm index 84356ee1..0833df8a 100644 --- a/lib/Synergy/Reactor/CatPic.pm +++ b/lib/Synergy/Reactor/CatPic.pm @@ -191,13 +191,9 @@ sub _build_reactions ($self, @) { return $reactions; } -# Copied cat_pic code -# Because there was no documentation -# Works on terminal, dunno if slack wil be able to display it as an image -# Tried to test it on local slack, but the documentation was pretty bad with the config files responder llama_pic => { - exclusive => 1, # No idea what this is. - targeted => 1, # Or this + exclusive => 1, + targeted => 1, help_titles => [ 'llama pic' ], help => '*llama pic*: get a picture of a llama', matcher => sub ($text, @) { @@ -223,8 +219,8 @@ responder llama_pic => { }; responder llama_fax => { - exclusive => 1, # No idea what this is. - targeted => 1, # Or this + exclusive => 1, + targeted => 1, help_titles => [ 'llama fax' ], help => '*llama fax*: get a fact about a llama', matcher => sub ($text, @) { From daa6f5264eb1845d33d9b656d5849f467b4cdb0e Mon Sep 17 00:00:00 2001 From: Mars Kitten <57377187+MarsKittenPro@users.noreply.github.com> Date: Fri, 19 May 2023 11:04:16 +1000 Subject: [PATCH 7/7] Open Brackets On Same Line as keyword --- lib/Synergy/Reactor/CatPic.pm | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/Synergy/Reactor/CatPic.pm b/lib/Synergy/Reactor/CatPic.pm index 0833df8a..9d325207 100644 --- a/lib/Synergy/Reactor/CatPic.pm +++ b/lib/Synergy/Reactor/CatPic.pm @@ -207,14 +207,15 @@ responder llama_pic => { "https://llama-as-a-service.vercel.app/llama_url" ); - return $http_future->on_done(sub($res) - { - if ($res->code == 200) - { + return $http_future->on_done(sub($res) { + + if ($res->code == 200) { $event->reply($res->content); return; } + $event->reply("Error while retrieving llama pictures!") + }); }; @@ -234,15 +235,15 @@ responder llama_fax => { "https://llama-as-a-service.vercel.app/llama_fax" ); - return $http_future->on_done(sub($res) - { - if ($res->code == 200) - { + return $http_future->on_done(sub($res) { + + if ($res->code == 200) { $event->reply($res->content); return; } $event->reply("Error while retrieving llama fax!") + }); };