Better NASA Image filter

This commit is contained in:
Daniel Odendahl Jr
2018-04-13 17:59:21 +00:00
parent 0d3948b58a
commit dbd4069903
4 changed files with 9 additions and 8 deletions
+1
View File
@@ -2,6 +2,7 @@
*.js text eol=lf
*.json text eol=lf
*.md text eol=lf
*.yml text eol=lf
# Configs and Stuff
.gitattributes text eol=lf
-3
View File
@@ -1,7 +1,4 @@
# Dependencies
node_modules/
package-lock.json
# Logs
logs/
*.log
+7 -4
View File
@@ -25,10 +25,13 @@ module.exports = class NASACommand extends Command {
try {
const { body } = await snekfetch
.get('https://images-api.nasa.gov/search')
.query({ q: query });
const filtered = body.collection.items.filter(item => item.data[0].media_type === 'image');
if (!filtered.length) return msg.say('Could not find any results.');
const data = filtered[Math.floor(Math.random() * filtered.length)];
.query({
q: query,
media_type: 'image'
});
const images = body.collection.items;
if (!images.length) return msg.say('Could not find any results.');
const data = images[Math.floor(Math.random() * images.length)];
return msg.say(shorten(data.data[0].description), { files: [data.links[0].href] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "72.0.0",
"version": "72.0.1",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {