Antidepressant or Tolkien? Command

This commit is contained in:
Dragon Fire
2020-06-09 14:56:04 -04:00
parent 22898caa91
commit 392d80980e
5 changed files with 194 additions and 4 deletions
+2 -2
View File
@@ -24,9 +24,9 @@ module.exports = class AiFoodCommand extends Command {
try {
const { text } = await request.get('https://thissnackdoesnotexist.com/');
const $ = cheerio.load(text);
const img = $('div[class="Absolute-Center"]').first().attr('style').match(/background-image:url\((.+)\);/i)[1];
const img = $('div[class="Absolute-Center"]').first().attr('style').match(/background-image:url\((.+)\);/i);
const name = $('h1[class="snack-description"]').first().text();
return msg.say(`AI-Generated Food: ${name}`, { files: [{ attachment: img, name: 'ai-food.jpg' }] });
return msg.say(`AI-Generated Food: ${name}`, img ? { files: [{ attachment: img, name: 'ai-food.jpg' }] } : {});
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}