-
Notifications
You must be signed in to change notification settings - Fork 2
/
mikey.js
61 lines (51 loc) · 2.53 KB
/
mikey.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
module.exports.config = {
name: "mikey",
version: "1.0.0",
hasPermssion: 0,
credits: "Nguyễn Quang Minh",
description: "Cú đá hạt nhân của mi cây 😎",
commandCategory: "Edit-img",
usages: "[tag]",
cooldowns: 5
};
module.exports.onLoad = () => {
const fs = require("fs-extra");
const request = require("request");
const dirMaterial = __dirname + `/cache/canvas/`;
if (!fs.existsSync(dirMaterial + "canvas")) fs.mkdirSync(dirMaterial, { recursive: true });
if (!fs.existsSync(dirMaterial + "cmgs.png")) request("https://i.ibb.co/9Y20Mwd/image.png").pipe(fs.createWriteStream(dirMaterial + "kick.png"));
}
async function makeImage({ one, two }) {
const axios = require("axios");
const fs = require("fs-extra");
const path = require("path");
const jimp = require("jimp");
const __root = path.resolve(__dirname, "cache", "canvas");
let point_image = await jimp.read(__root + "/kick.png");
let pathImg = __root + `/kick_${one}.png`;
let avatarOne = __root + `/avt_${one}.png`;
let getAvatarOne = (await axios.get(`https://graph.facebook.com/${one}/picture?width=512&height=512&access_token=EAAOdaGArpzQBAELcjcePnGu6eZBY9dZC22ctL8eCpdFAbvh0HxyioGQZBoVPHZALdwRLJ4zmwgyMfVbhQsWfHjIcBfa9LCieayY9LKrBggtbWDq2XZCJ9ZCeByNbkg2jKSNFhvgAlD2A3EyWm4vYcEfrZCNX8rvxf3YXFqv3fm0lZBR8ZB5ZC5VXykin8tAYsN4MJY4cm4y2olob7ZBndvVGCWrZBGdIvwCbToIZD`, { responseType: 'arraybuffer' })).data;
fs.writeFileSync(avatarOne, Buffer.from(getAvatarOne, 'utf-8'));
let circleOne = await jimp.read(await circle(avatarOne));
point_image.composite(circleOne.resize(105, 105), 688, 98)
let raw = await point_image.getBufferAsync("image/png");
fs.writeFileSync(pathImg, raw);
fs.unlinkSync(avatarOne);
return pathImg;
}
async function circle(image) {
const jimp = require("jimp");
image = await jimp.read(image);
image.circle();
return await image.getBufferAsync("image/png");
}
module.exports.run = async function ({ event, api, args, client }) {
const fs = require("fs-extra");
let { threadID, messageID, senderID } = event;
var mention = Object.keys(event.mentions)[0];
if (!mention) return api.sendMessage("Vui lòng tag 1 người", threadID, messageID);
else {
var one = mention;
return makeImage({ one }).then(path => api.sendMessage({ body: event.mentions[mention].replace("@", "") + " chết cmm chưa 😎", attachment: fs.createReadStream(path) }, threadID, () => fs.unlinkSync(path), messageID));
}
}