diff --git a/.env.example b/.env.example index b40b2c4a..0fa9239a 100644 --- a/.env.example +++ b/.env.example @@ -54,6 +54,7 @@ TMDB_KEY= TUMBLR_KEY= TWITTER_KEY= TWITTER_SECRET= +UNSPLASH_KEY= USPS_USERID= WATTPAD_KEY= WEBSTER_KEY= diff --git a/README.md b/README.md index ca10f9ff..f9d9c92f 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,7 @@ API. All are free unless otherwise stated. * `TMDB_KEY` can be obtained by [following these instructions at the TMDB website](https://www.themoviedb.org/documentation/api). Read the "How do I apply for an API key?" section. * `TUMBLR_KEY` can be obtained at the [Tumblr developer portal](https://www.tumblr.com/oauth/apps). * `TWITTER_KEY` and `TWITTER_SECRET` can be obtained at the [Twitter developer portal](https://developer.twitter.com/en/apps). +* `UNSPLASH_KEY` can be obtained at the [Unsplash developer portal](https://unsplash.com/developers). * `USPS_USERID` can be obtained at the [Web Tools API Portal](https://www.usps.com/business/web-tools-apis/). * `WATTPAD_KEY` can be obtained at the [Wattpad developer portal](https://www.wattpad.com/developer/docs/api). * `WEBSTER_KEY` can be obtained by [going to the Dictionary API website](https://dictionaryapi.com/). Find the "GET STARTED USING OUR API" section. @@ -226,7 +227,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 471 +Total: 472 ### Utility: @@ -457,6 +458,7 @@ Total: 471 * **safebooru:** Responds with an image from Safebooru, with optional query. * **stack-overflow:** Searches Stack Overflow for your query. * **steam:** Searches Steam for your query. +* **stock-photo:** Searches for stock photos based on your query. * **stocks:** Responds with the current stocks for a company. * **tenor:** Searches Tenor for your query. * **tumblr:** Responds with information on a Tumblr blog. @@ -1447,6 +1449,8 @@ here. * genie-rules ([Image](https://www.reddit.com/r/MemeTemplatesOfficial/comments/bht9o6/i_made_an_hd_high_quality_version_of_the_4_rules/)) - [UNDERTALE](https://undertale.com/) * temmie (Original Game) +- [Unsplash](https://unsplash.com/) + * stock-photo ([API](https://unsplash.com/developers)) - [Urban Dictionary](https://www.urbandictionary.com/) * urban ([API](https://github.com/zdict/zdict/wiki/Urban-dictionary-API-documentation)) - [USPS](https://www.usps.com/) diff --git a/commands/search/stock-photo.js b/commands/search/stock-photo.js new file mode 100644 index 00000000..a22e4f07 --- /dev/null +++ b/commands/search/stock-photo.js @@ -0,0 +1,57 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); +const { MessageEmbed } = require('discord.js'); +const { shorten } = require('../../util/Util'); +const { UNSPLASH_KEY } = process.env; + +module.exports = class StockPhotoCommand extends Command { + constructor(client) { + super(client, { + name: 'stock-photo', + aliases: ['unsplash', 'stock-image', 'stock-img'], + group: 'search', + memberName: 'stock-photo', + description: 'Searches for stock photos based on your query.', + clientPermissions: ['EMBED_LINKS'], + credit: [ + { + name: 'Unsplash', + url: 'https://unsplash.com/', + reason: 'API', + reasonURL: 'https://unsplash.com/developers' + } + ], + args: [ + { + key: 'query', + prompt: 'What image would you like to search for?', + type: 'string' + } + ] + }); + } + + async run(msg, { query }) { + try { + const { body } = await request + .get('https://api.unsplash.com/photos/random') + .set({ Authorization: `Client-ID ${UNSPLASH_KEY}` }) + .query({ + query, + content_filter: msg.channel.nsfw ? 'low' : 'high' + }); + if (!body) return msg.say('Could not find any results.'); + const embed = new MessageEmbed() + .setTitle(body.description ? shorten(body.description, 256) : 'Unnamed Image') + .setURL(body.links.download) + .setColor(body.color) + .setAuthor(body.user.name || body.user.username, undefined, body.user.links.html) + .setImage(body.urls.raw) + .setFooter(`Photo by ${body.user.name || body.user.username} on Unsplash`) + .setTimestamp(new Date(body.updated_at)); + return msg.embed(embed); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 1f860a3c..e6741fcd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "116.14.0", + "version": "116.15.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {