Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdds "clipart me" command that returns clipart images from the openclipart API #1183
Conversation
|
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
|
@technicalpickles thanks for this. I will update and resubmit as its on package. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

desmondmorris commentedOct 10, 2013
No description provided.