The Wayback Machine - https://web.archive.org/web/20200916051355/https://github.com/github/hubot-scripts/pull/1183
Skip to content
This repository has been archived by the owner. It is now read-only.

Adds "clipart me" command that returns clipart images from the openclipart API #1183

Closed
wants to merge 2 commits into from

Conversation

@desmondmorris
Copy link
Contributor

desmondmorris commented Oct 10, 2013

No description provided.

@technicalpickles
Copy link
Member

technicalpickles commented Oct 10, 2013

We are actually moving away from adding scripts to repository in favor of separate npm packages per scripts. See #1113 for details, and let us know if you have any questions about getting going with that!

# hubot clipart me <query> - Queries openclipart for <query> and returns a random result.

module.exports = (robot) ->
robot.respond /(clipart)( me)? (.*)/i, (msg) ->

This comment has been minimized.

@technicalpickles

technicalpickles Oct 10, 2013

Member

It's probably not worth capturing (clipart), since you don't use it. Nor is the optional me used. That means you could refactor to:

/clipart(?: me)? (.*)/

And then you'd be able to use msg.match[1] below.

msg.http('http://openclipart.org/search/json/')
.query(q)
.get() (err, res, body) ->
data = JSON.parse(body)

This comment has been minimized.

@technicalpickles

technicalpickles Oct 10, 2013

Member

Might want to check that res.statusCode is 200, and that there isn't an err before trying to parse.

clipartMe = (msg, query, cb) ->
q = query: query

msg.http('http://openclipart.org/search/json/')

This comment has been minimized.

@technicalpickles

technicalpickles Oct 10, 2013

Member

You can call robot.http, if it's simpler. You wouldn't need to pass a msg, since you don't use it in this method anyways. That would mean this would need to be defined under the modules.export = (robot) -> block.

This comment has been minimized.

@desmondmorris

desmondmorris Oct 18, 2013

Author Contributor

I am refactoring this now. I think I need to stick with the msg object though as I need to use its "random" method.

This comment has been minimized.

@technicalpickles

technicalpickles Oct 18, 2013

Member

Ah, missed that. It's probably fine then. Or alternatively, you could return all the art from this callback, and let the thing consuming it call msg.random.

This comment has been minimized.

@desmondmorris

desmondmorris Oct 18, 2013

Author Contributor

yah thats probably a smarter approach. good call

@desmondmorris
Copy link
Contributor Author

desmondmorris commented Oct 18, 2013

@technicalpickles thanks for this. I will update and resubmit as its on package.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.