Fix meme descriptions and thumbnails

This commit is contained in:
Daniel Odendahl Jr
2018-10-04 22:01:21 +00:00
parent 303b4481b3
commit 751c4bf980
2 changed files with 15 additions and 3 deletions
+14 -2
View File
@@ -54,11 +54,23 @@ module.exports = class KnowYourMemeCommand extends Command {
async fetchMeme(location) {
const { text } = await request.get(`https://knowyourmeme.com${location}`);
const $ = cheerio.load(text);
const thumbnail = $('a[class="photo left wide"]').first().attr('href')
|| $('a[class="photo left "]').first().attr('href')
|| null;
return {
name: $('h1').first().text().trim(),
url: `https://knowyourmeme.com${location}`,
description: $('.bodycopy').children().eq(1).text(),
thumbnail: $('a[class="photo left wide"]').first().attr('href') || null
description: this.getMemeDescription($),
thumbnail
};
}
getMemeDescription($) {
const children = $('.bodycopy').first().children();
for (let i = 0; i < children.length; i++) {
const child = children.eq(i);
if (child.text() === 'About') return children.eq(i + 1).text();
}
return null;
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "92.2.0",
"version": "92.2.1",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {