-
Notifications
You must be signed in to change notification settings - Fork 2
/
damvinhhung.js
74 lines (72 loc) · 2.51 KB
/
damvinhhung.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
62
63
64
65
66
67
68
69
70
71
72
73
74
module.exports.config = {
name: "damvinhhung",
version: "1.0.1",
hasPermssion: 0,
credits: "Nguyễn Quang Minh",
description: "Comment trên youtube của Đàm Vĩnh Hưng",
commandCategory: "edit-img",
usages: "[text]",
cooldowns: 10,
dependencies: {
"canvas":"",
"axios":"",
"fs-extra":""
}
};
module.exports.wrapText = (ctx, text, maxWidth) => {
return new Promise(resolve => {
if (ctx.measureText(text).width < maxWidth) return resolve([text]);
if (ctx.measureText('W').width > maxWidth) return resolve(null);
const words = text.split(' ');
const lines = [];
let line = '';
while (words.length > 0) {
let split = false;
while (ctx.measureText(words[0]).width >= maxWidth) {
const temp = words[0];
words[0] = temp.slice(0, -1);
if (split) words[1] = `${temp.slice(-1)}${words[1]}`;
else {
split = true;
words.splice(1, 0, temp.slice(-1));
}
}
if (ctx.measureText(`${line}${words[0]}`).width < maxWidth) line += `${words.shift()} `;
else {
lines.push(line.trim());
line = '';
}
if (words.length === 0) lines.push(line.trim());
}
return resolve(lines);
});
}
module.exports.run = async function({ api, event, args }) {
let { senderID, threadID, messageID } = event;
const { loadImage, createCanvas } = require("canvas");
const fs = global.nodemodule["fs-extra"];
const axios = global.nodemodule["axios"];
let pathImg = __dirname + '/cache/damvinhung.png';
var text = args.join(" ");
if (!text) return api.sendMessage("Nhập nội dung comment", threadID, messageID);
let getPorn = (await axios.get(`https://i.ibb.co/nsFjd2S/image.png`, { responseType: 'arraybuffer' })).data;
fs.writeFileSync(pathImg, Buffer.from(getPorn, 'utf-8'));
let baseImage = await loadImage(pathImg);
let canvas = createCanvas(baseImage.width, baseImage.height);
let ctx = canvas.getContext("2d");
ctx.drawImage(baseImage, 0, 0, canvas.width, canvas.height);
ctx.font = "400 14px Roboto";
ctx.fillStyle = "#030303";
ctx.textAlign = "start";
let fontSize = 80;
while (ctx.measureText(text).width > 1200) {
fontSize--;
ctx.font = `400 ${fontSize}px Roboto`;
}
const lines = await this.wrapText(ctx, text, 350);
ctx.fillText(lines.join('\n'), 93,91);//comment
ctx.beginPath();
const imageBuffer = canvas.toBuffer();
fs.writeFileSync(pathImg, imageBuffer);
return api.sendMessage({ attachment: fs.createReadStream(pathImg) }, threadID, () => fs.unlinkSync(pathImg), messageID);
}