diff --git a/README.md b/README.md index 518d5616..71fbc3de 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Xiao is a Discord bot coded in JavaScript with 300 commands, she is one of the most feature-filled bots out there, and formerly served over 10,000 servers with a uniquely devoted fanbase. -## Commands (294) +## Commands (295) ### Utility: * **prefix**: Shows or sets the command prefix. @@ -121,6 +121,7 @@ served over 10,000 servers with a uniquely devoted fanbase. * **danbooru**: Responds with an image from Danbooru, with optional query. * **deviantart**: Responds with an image from a DeviantArt section, with optional query. * **dictionary**: Defines a word. +* **flickr**: Searches Flickr for your query. * **forecast**: Responds with the seven-day forecast for a specific location. * **gelbooru**: Responds with an image from Gelbooru, with optional query. * **giphy**: Searches Giphy for your query. diff --git a/commands/search/flickr.js b/commands/search/flickr.js new file mode 100644 index 00000000..6d1e341d --- /dev/null +++ b/commands/search/flickr.js @@ -0,0 +1,41 @@ +const { Command } = require('discord.js-commando'); +const snekfetch = require('snekfetch'); +const { FLICKR_KEY } = process.env; + +module.exports = class FlickrCommand extends Command { + constructor(client) { + super(client, { + name: 'flickr', + aliases: ['flickr-image'], + 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 data = body.photos.photo[Math.floor(Math.random() * body.photos.photo.length)]; + return msg.say(`https://farm${data.farm}.staticflickr.com/${data.server}/${data.id}_${data.secret}.jpg`); + } catch (err) { + return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index fc3da668..bea92874 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "70.0.1", + "version": "70.1.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {