|
import axios from 'axios'; |
|
|
|
class SendWaifuRandom { |
|
constructor() { |
|
} |
|
async sendWaifuPics() { |
|
const LIST_SFW_JPG = ["neko", "waifu", "megumin"]; |
|
const waifuApi = "https://api.waifu.pics/sfw"; |
|
const waifuCategory = LIST_SFW_JPG[Math.floor(Math.random() * LIST_SFW_JPG.length)]; |
|
const waifuParam = `${waifuApi}/${waifuCategory}`; |
|
|
|
try { |
|
const response = await axios.get(waifuParam); |
|
|
|
if (response.status !== 200) { |
|
return "Sorry, there was an error processing your request. Please try again later"; |
|
} |
|
|
|
const dataWaifu = response.data; |
|
const waifuImageUrl = dataWaifu.url; |
|
|
|
if (waifuImageUrl) { |
|
return waifuImageUrl; |
|
} else { |
|
return "Not found waifu"; |
|
} |
|
} catch (error) { |
|
return `Error request ${error.message}`; |
|
} |
|
} |
|
} |
|
|
|
export { SendWaifuRandom }; |