Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a Llama Picture and Llama Facts Command #196

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Zycrasion
Copy link

@Zycrasion Zycrasion commented May 17, 2023

Uses a webservice to get random llama picture.
Llama webservice written by me

also added a llama facts command

@Zycrasion Zycrasion changed the title Added a Llama Picture Command Added a Llama Picture and Llama FactsCommand May 17, 2023
@Zycrasion Zycrasion changed the title Added a Llama Picture and Llama FactsCommand Added a Llama Picture and Llama Facts Command May 17, 2023
Copy link
Member

@marcbradshaw marcbradshaw left a comment

Choose a reason for hiding this comment

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

A couple of comments, 1 bug, and some error checking needed.

Synergy::Reactor::CatPic is growing to be more than just Cat pics again, and is increasingly misnamed, are we adopting Blake Freeman's animal categorisation system?

https://www.youtube.com/watch?v=qvagEsvHQSU&themeRefresh=1

help_titles => [ 'llama pic' ],
help => '*llama pic*: get a picture of a llama',
matcher => sub ($text, @) {
return unless $text =~ /\Allama\spic?\z/i;
Copy link
Member

Choose a reason for hiding this comment

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

The regex here is wrong. The version of this in catpic matches "cat" followed optionally by "pic", "jpg", "gif", or "png". And then returns the optional part if it exists.
Regex can be a bit cryptic, but it's really just a very comprehensive pattern matching language, the ? character (the one at the end anyway) marks the previous entity as optional. In catpic this applies to the entire optional match section of space followed by one of the words, in this match the precious entity is the "c" of pic, so this will match either "llama pic" or "llama pi"

Copy link
Author

Choose a reason for hiding this comment

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

Oh yeah, thanks for pointing that out. I think I have fixed it.

$event->mark_handled;

my $http_request = $self->hub->http_client->GET(
"https://llama-as-a-service.vercel.app/llama_url"
Copy link
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!

}, sub ($self, $event) {
$event->mark_handled;

my $http_request = $self->hub->http_client->GET(
Copy link
Member

Choose a reason for hiding this comment

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

I would have kept the $http_future naming from the cat_pic responder here, makes it clearer that it's not just a simple client object and keeps it consistent with cat pic.

@@ -191,6 +191,32 @@ 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
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

);

return $http_request->on_done(sub($res)
{
Copy link
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?

# 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
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.

Copy link
Member

@marcbradshaw marcbradshaw left a comment

Choose a reason for hiding this comment

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

A couple of comments, 1 bug, and some error checking needed.

Synergy::Reactor::CatPic is growing to be more than just Cat pics again, and is increasingly misnamed, are we adopting Blake Freeman's animal categorisation system?

https://www.youtube.com/watch?v=qvagEsvHQSU&themeRefresh=1

@Zycrasion
Copy link
Author

i think i fixed everything

Copy link
Member

@marcbradshaw marcbradshaw left a comment

Choose a reason for hiding this comment

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

thanks for adding the 200 check, just one nit that should be real easy to fix up


return $http_request->on_done(sub($res)
{
$event->reply($res->content)
Copy link
Member

Choose a reason for hiding this comment

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

ditto error handling

return $http_future->on_done(sub($res)
{
if ($res->code == 200)
{
Copy link
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

Copy link
Member

@marcbradshaw marcbradshaw left a comment

Choose a reason for hiding this comment

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

thanks for adding the 200 check, just one nit that should be real easy to fix up

@Zycrasion
Copy link
Author

All brackets Should Be Fixed now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants