-
Notifications
You must be signed in to change notification settings - Fork 2
/
dogfact.js
32 lines (31 loc) · 1.14 KB
/
dogfact.js
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
module.exports.config = {
name: "dogfact",
version: "1.0.0",
hasPermision: 0,
credit: "Nguyễn Quang Minh",
description: "dog fact",
commandCategory: "info",
usages: "",
cooldowns: 0,
};
module.exports.run = async function({api, event, args, utils, Users, Threads}) {
try {
let axios = require('axios');
let fs = require("fs-extra");
let request = require("request");
let {threadID, senderID, messageID} = event;
const res = await axios.get(`https://some-random-api.ml/animal/dog`);
console.log(res.data);
var data = res.data;
let callback = function() {
return api.sendMessage({
body:`===🐶Dog fact🐶===\n\nFact: ${data.fact}`,
attachment: fs.createReadStream(__dirname + `/cache/image.png`)
}, event.threadID, () => fs.unlinkSync(__dirname + `/cache/image.png`), event.messageID);
};
return request(encodeURI(data.image)).pipe(fs.createWriteStream(__dirname + `/cache/image.png`)).on("close", callback);
} catch (err) {
console.log(err)
return api.sendMessage(`Đã xảy ra lỗi`, event.threadID)
}
}