Imgur Command

This commit is contained in:
Daniel Odendahl Jr
2017-09-29 21:41:12 +00:00
parent b30d6a94f9
commit a5040e63f1
2 changed files with 37 additions and 1 deletions
+36
View File
@@ -0,0 +1,36 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const { IMGUR_KEY } = process.env;
module.exports = class ImgurCommand extends Command {
constructor(client) {
super(client, {
name: 'imgur',
aliases: ['imgur-image'],
group: 'search',
memberName: 'imgur',
description: 'Searches Imgur for your query.',
args: [
{
key: 'query',
prompt: 'What image would you like to search for?',
type: 'string'
}
]
});
}
async run(msg, { query }) {
try {
const { body } = await snekfetch
.get('https://api.imgur.com/3/gallery/search')
.query({ q: query })
.set({ Authorization: `Client-ID ${IMGUR_KEY}` });
const images = msg.channel.nsfw ? body.data : body.data.filter(image => !image.nsfw);
if (!images.length) return msg.say('Could not find any results.');
return msg.say(images[Math.floor(Math.random() * images.length)].images[0].link);
} 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": "43.0.0",
"version": "43.1.0",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {