File size: 858 Bytes
5c7d800 97c414f 5c7d800 97c414f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
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 }; |