Get the random anime wallpaper
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const axios = require('axios')
const cheerio = require("cheerio");
if(context.params.event.content.startsWith("!wallpaper")) {
const { data } = await axios("https://wall.alphacoders.com/by_category.php?id=3&name=Anime+Wallpapers&page=" + Math.floor(Math.random() * (500 - 1) + 1), {
headers: {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
}
})
let $ = cheerio.load(data)
let images = []
$('div.thumb-container-big').each(function() {
$ = cheerio.load($(this).html())
const name = $('div.thumb-container div.thumb-info a').text()
let image = $('img.img-responsive').attr('src')
if (!image) return;
else image = image.split("/")
image.push(image.pop().match(/(?<=-)\d+.(.*?)+/g)[0])
let object = {
resolution: $('div.thumb-container div.thumb-info span').text(),
image: image ? image.join("/") : false,
anime: name ? name.replace("Anime", "") : "Unknown"
}
images.push(object)
})
const random = images[Math.floor(Math.random()*images.length)]
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: context.params.event.channel_id,
content: ``,
embed: {
title: random.anime,
image: { url: random.image },
description: `Click here to download image in **[${random.resolution}](${random.image})** resolutions`,
color: 0xffc0cb
}
})
}