bot-eye-leak/src/handlers/jokeTask.js

24 lines
694 B
JavaScript

const fetch = require('node-fetch')
class JokeTask {
async getRandomAnimation({ replyWithAnimation }) {
const page = Math.floor(Math.random() * 100)
return Promise.resolve(
await fetch(`https://developerslife.ru/top/${page}?json=true`)
)
.then(res => res.json())
.then(data => {
const index = Number(Math.floor(Math.random() * data.result.length))
// eslint-disable-next-line security/detect-object-injection
const { videoURL: sendGif, description: caption } = data.result[index]
return replyWithAnimation(sendGif, {
caption,
parse_mode: 'HTML'
})
})
.catch(err => console.error('!joke ', err.message))
}
}
module.exports = new JokeTask()