Skip to content
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions lib/Synergy/Reactor/CatPic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,65 @@ 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cat pic works by assuming slack will recognise the url and fetch the target for display, so assuming what is returned is a url it should work just fine

# 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exclusive is a means to prevent a string being matched by multiple responders, targeted is to do with if you need to target the bot with @botName or PM etc. Someone who has worked on synergy before could answer those questions, but copying what is in catpic is fine here.

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;

my $http_future = $self->hub->http_client->GET(
"https://llama-as-a-service.vercel.app/llama_url"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you create this API just for this task? cool!

);

return $http_future->on_done(sub($res)
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs some error handling, what happens if we don't get a 200 from the remote api call? What happens if the remote API stops returning a single URL to a picture and starts returning a large html page?

if ($res->code == 200)
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a small nit pick, the new code uses a different brace style to the rest of the code.
opening brace on the same line as the related keyword, one space before brace

$event->reply($res->content);
return;
}
$event->reply("Error while retrieving llama pictures!")
});
};

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_future = $self->hub->http_client->GET(
"https://llama-as-a-service.vercel.app/llama_fax"
);

return $http_future->on_done(sub($res)
{
if ($res->code == 200)
{
$event->reply($res->content);
return;
}

$event->reply("Error while retrieving llama fax!")
});
};

responder cat_pic => {
exclusive => 1,
targeted => 1,
Expand Down