Flickr Command

This commit is contained in:
Daniel Odendahl Jr
2017-09-16 02:20:13 +00:00
parent 1c9ac56831
commit b32cf4c2d9
2 changed files with 41 additions and 1 deletions
+40
View File
@@ -0,0 +1,40 @@
const Command = require('../../structures/Command');
const snekfetch = require('snekfetch');
const { FLICKR_KEY } = process.env;
module.exports = class FlickrCommand extends Command {
constructor(client) {
super(client, {
name: 'flickr',
group: 'search',
memberName: 'flickr',
description: 'Searches Flickr for your query.',
args: [
{
key: 'query',
prompt: 'What photo would you like to search for?',
type: 'string'
}
]
});
}
async run(msg, { query }) {
try {
const { body } = await snekfetch
.get('https://api.flickr.com/services/rest/')
.query({
api_key: FLICKR_KEY,
format: 'json',
method: 'flickr.photos.search',
text: query,
nojsoncallback: true
});
if (!body.photos.photo.length) return msg.say('Could not find any results.');
const photo = body.photos.photo[Math.floor(Math.random() * body.photos.photo.length)];
return msg.say(`https://farm${photo.farm}.staticflickr.com/${photo.server}/${photo.id}_${photo.secret}.jpg`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "39.0.1",
"version": "39.1.0",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {