-
Notifications
You must be signed in to change notification settings - Fork 21
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
9636995
c63d874
d25a5ef
3d44d46
d80bd0c
be5910a
daa6f52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,6 +191,54 @@ 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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_request = $self->hub->http_client->GET( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
"https://llama-as-a-service.vercel.app/llama_url" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you create this API just for this task? cool! |
||
); | ||
|
||
return $http_request->on_done(sub($res) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
$event->reply($res->content) | ||
}); | ||
}; | ||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto error handling |
||
}); | ||
}; | ||
|
||
responder cat_pic => { | ||
exclusive => 1, | ||
targeted => 1, | ||
|
There was a problem hiding this comment.
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