Jonell01 commited on
Commit
0c88c2f
·
verified ·
1 Parent(s): 1685408

Upload 5 files

Browse files
modules/events/adminNoti.js ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module.exports.config = {
2
+ name: "adminNoti",
3
+ eventType: [
4
+ "log:thread-admins",
5
+ "log:thread-name",
6
+ "log:user-nickname",
7
+ "log:thread-call",
8
+ "log:thread-icon",
9
+ "log:thread-color",
10
+ "log:link-status",
11
+ "log:magic-words",
12
+ "log:thread-approval-mode",
13
+ "log:thread-poll"
14
+ ],
15
+ version: "1.0.1",
16
+ credits: "Mirai Team & mod by Yan Maglinte",
17
+ description: "Group Information Update",
18
+ envConfig: {
19
+ autoUnsend: true,
20
+ sendNoti: true,
21
+ timeToUnsend: 10
22
+ }
23
+ };
24
+
25
+ module.exports.run = async function({ event, api, Threads, Users }) {
26
+ const { author, threadID, logMessageType, logMessageData, logMessageBody } = event;
27
+ const { setData, getData } = Threads;
28
+ const fs = require("fs");
29
+ const iconPath = __dirname + "/cache/emoji.json";
30
+ if (!fs.existsSync(iconPath)) fs.writeFileSync(iconPath, JSON.stringify({}));
31
+ if (author === threadID) return;
32
+
33
+ try {
34
+ let dataThread = (await getData(threadID)).threadInfo;
35
+
36
+ switch (logMessageType) {
37
+ case "log:thread-admins": {
38
+ if (logMessageData.ADMIN_EVENT === "add_admin") {
39
+ dataThread.adminIDs.push({ id: logMessageData.TARGET_ID });
40
+ api.sendMessage(`[ GROUP UPDATE ]\n❯ USER UPDATE ${Users.getNameUser(logMessageData.TARGET_ID)} Became a group admin`, threadID);
41
+ } else if (logMessageData.ADMIN_EVENT === "remove_admin") {
42
+ dataThread.adminIDs = dataThread.adminIDs.filter(item => item.id !== logMessageData.TARGET_ID);
43
+ api.sendMessage(`[ GROUP UPDATE ]\n❯ Remove user's admin position ${logMessageData.TARGET_ID}`, threadID);
44
+ }
45
+ break;
46
+ }
47
+ case "log:user-nickname": {
48
+ const { participant_id, nickname } = logMessageData;
49
+ if (participant_id && nickname) {
50
+ dataThread.nicknames = dataThread.nicknames || {};
51
+ dataThread.nicknames[participant_id] = nickname;
52
+ const participantName = await Users.getNameUser(participant_id);
53
+ const formattedNickname = nickname || "deleted nickname";
54
+ api.sendMessage(`[ GROUP ]\n❯ Updated nickname for ${participantName}: ${formattedNickname}.`, threadID);
55
+ }
56
+ break;
57
+ }
58
+ case "log:thread-name": {
59
+ dataThread.threadName = logMessageData.name || null;
60
+ api.sendMessage(`[ GROUP UPDATE ]\n❯ ${(dataThread.threadName) ? `Updated Group Name to: ${dataThread.threadName}` : 'Cleared the Group Name'}.`, threadID);
61
+ break;
62
+ }
63
+ case "log:thread-icon": {
64
+ const preIcon = JSON.parse(fs.readFileSync(iconPath));
65
+ dataThread.threadIcon = logMessageData.thread_icon || "👍";
66
+ if (global.configModule[this.config.name].sendNoti) {
67
+ api.sendMessage(`[ GROUP UPDATE ]\n❯ ${logMessageBody.replace("emoji", "icon")}\n❯ Original Emoji: ${preIcon[threadID] || "unknown"}`, threadID, async (error, info) => {
68
+ preIcon[threadID] = dataThread.threadIcon;
69
+ fs.writeFileSync(iconPath, JSON.stringify(preIcon));
70
+ if (global.configModule[this.config.name].autoUnsend) {
71
+ await new Promise(resolve => setTimeout(resolve, global.configModule[this.config.name].timeToUnsend * 1000));
72
+ return api.unsendMessage(info.messageID);
73
+ }
74
+ });
75
+ }
76
+ break;
77
+ }
78
+ case "log:thread-call": {
79
+ if (logMessageData.event === "group_call_started") {
80
+ const name = await Users.getNameUser(logMessageData.caller_id);
81
+ api.sendMessage(`[ GROUP UPDATE ]\n❯ ${name} STARTED A ${(logMessageData.video) ? 'VIDEO ' : ''}CALL.`, threadID);
82
+ } else if (logMessageData.event === "group_call_ended") {
83
+ const callDuration = logMessageData.call_duration;
84
+ const hours = Math.floor(callDuration / 3600);
85
+ const minutes = Math.floor((callDuration - (hours * 3600)) / 60);
86
+ const seconds = callDuration - (hours * 3600) - (minutes * 60);
87
+ const timeFormat = `${hours}:${minutes}:${seconds}`;
88
+ api.sendMessage(`[ GROUP UPDATE ]\n❯ ${(logMessageData.video) ? 'Video' : ''} call has ended.\n❯ Call duration: ${timeFormat}`, threadID);
89
+ } else if (logMessageData.joining_user) {
90
+ const name = await Users.getNameUser(logMessageData.joining_user);
91
+ api.sendMessage(`❯ [ GROUP UPDATE ]\n❯ ${name} Joined the ${(logMessageData.group_call_type == '1') ? 'Video' : ''} call.`, threadID);
92
+ }
93
+ break;
94
+ }
95
+ case "log:link-status": {
96
+ api.sendMessage(logMessageBody, threadID);
97
+ break;
98
+ }
99
+ case "log:magic-words": {
100
+ api.sendMessage(`» [ GROUP UPDATE ] Theme ${logMessageData.magic_word} added effect: ${logMessageData.theme_name}\nEmoij: ${logMessageData.emoji_effect || "No emoji "}\nTotal ${logMessageData.new_magic_word_count} word effect added`, threadID)
101
+ break;
102
+ }
103
+ case "log:thread-poll": {
104
+ const obj = JSON.parse(logMessageData.question_json);
105
+ if (logMessageData.event_type === "question_creation" || logMessageData.event_type === "update_vote") {
106
+ api.sendMessage(logMessageBody, threadID);
107
+ }
108
+ break;
109
+ }
110
+ case "log:thread-approval-mode": {
111
+ api.sendMessage(logMessageBody, threadID);
112
+ break;
113
+ }
114
+ case "log:thread-color": {
115
+ dataThread.threadColor = logMessageData.thread_color || "🌤";
116
+ if (global.configModule[this.config.name].sendNoti) {
117
+ api.sendMessage(`[ GROUP UPDATE ]\n❯ ${logMessageBody.replace("Theme", "color")}`, threadID, async (error, info) => {
118
+ if (global.configModule[this.config.name].autoUnsend) {
119
+ await new Promise(resolve => setTimeout(resolve, global.configModule[this.config.name].timeToUnsend * 1000));
120
+ return api.unsendMessage(info.messageID);
121
+ }
122
+ });
123
+ }
124
+ break;
125
+ }
126
+ }
127
+
128
+ await setData(threadID, { threadInfo: dataThread });
129
+ } catch (error) {
130
+ console.log(error);
131
+ }
132
+ };
modules/events/join.js ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module.exports.config = {
2
+ name: "join",
3
+ eventType: ['log:subscribe'],
4
+ version: "1.0.0",
5
+ credits: "Jonell Magallanes",
6
+ description: "GROUP UPDATE NOTIFICATION"
7
+ };
8
+
9
+ module.exports.run = function({ api, event }) {
10
+ if (event.logMessageType === "log:subscribe") {
11
+ if (event.logMessageData.addedParticipants.some(i => i.userFbId == api.getCurrentUserID())) {
12
+ api.changeNickname(`${global.config.BOTNAME} • [ ${global.config.PREFIX} ]`, event.threadID, api.getCurrentUserID());
13
+ return api.shareContact(`✅ 𝗕𝗼𝘁 𝗖𝗼𝗻𝗻𝗲𝗰𝘁𝗲𝗱\n━━━━━━━━━━━━━━━━━━\n${global.config.BOTNAME} Bot connected successfully!\nType "${global.config.PREFIX}help" to view all commands\n\nContact: ${global.config.OWNER}`, api.getCurrentUserID(), event.threadID);
14
+ } else {
15
+ const { threadID } = event;
16
+ api.getThreadInfo(threadID, async (err, threadInfo) => {
17
+ if (err) return console.error(err);
18
+
19
+ let { threadName, participantIDs } = threadInfo;
20
+ var tn = threadName || "Unnamed group";
21
+ let addedParticipants = event.logMessageData.addedParticipants;
22
+
23
+ for (let newParticipant of addedParticipants) {
24
+ let userID = newParticipant.userFbId;
25
+ api.getUserInfo(parseInt(userID), (err, data) => {
26
+ if (err) return console.error(err);
27
+
28
+ var obj = Object.keys(data);
29
+ var userName = data[obj].name.replace("@", "");
30
+
31
+ if (userID !== api.getCurrentUserID()) {
32
+ api.shareContact(`Hello ${userName}!\nWelcome to ${tn}\nYou're the ${participantIDs.length}th member on this group. Enjoy!`, newParticipant.userFbId, event.threadID);
33
+ }
34
+ });
35
+ }
36
+ });
37
+ }
38
+ }
39
+ };
modules/events/joinNoti.jsb ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module.exports.config = {
2
+ name: "join",
3
+ eventType: ['log:subscribe'],
4
+ version: "1.0.0",
5
+ credits: "Mirai-Team", // FIXED BY YAN MAGLINTE
6
+ description: "GROUP UPDATE NOTIFICATION"
7
+ };
8
+
9
+ const ADMIN = 'YOUR_NAME';
10
+ const FB_LINK = 'YOUR_FACEBOOK_LINK';
11
+
12
+ const fs = require('fs-extra');
13
+ const { loadImage, createCanvas, registerFont } = require("canvas");
14
+ const request = require('request');
15
+ //const { join } = require('path');
16
+ const axios = require('axios');
17
+ const jimp = require("jimp")
18
+ const fontlink = 'https://drive.google.com/u/0/uc?id=1ZwFqYB-x6S9MjPfYm3t3SP1joohGl4iw&export=download'
19
+ let PRFX = `${global.config.PREFIX}`;
20
+
21
+ module.exports.circle = async (image) => {
22
+ image = await jimp.read(image);
23
+ image.circle();
24
+ return await image.getBufferAsync("image/png");
25
+ }
26
+
27
+ let suffix;
28
+
29
+ module.exports.run = async function({ api, event, Users }) {
30
+ var fullYear = global.client.getTime("fullYear");
31
+ var getHours = await global.client.getTime("hours");
32
+ var session = `${getHours < 3 ? "midnight" : getHours < 8 ? "Early morning" : getHours < 12 ? "noon" : getHours < 17 ? "afternoon" : getHours < 23 ? "evening" : "midnight"}`
33
+ const moment = require("moment-timezone");
34
+ var thu = moment.tz('Asia/Manila').format('dddd');
35
+ if (thu == 'Sunday') thu = 'Sunday'
36
+ if (thu == 'Monday') thu = 'Monday'
37
+ if (thu == 'Tuesday') thu = 'Tuesday'
38
+ if (thu == 'Wednesday') thu = 'Wednesday'
39
+ if (thu == "Thursday") thu = 'Thursday'
40
+ if (thu == 'Friday') thu = 'Friday'
41
+ if (thu == 'Saturday') thu = 'Saturday'
42
+ const time = moment.tz("Asia/Manila").format("HH:mm:ss - DD/MM/YYYY");
43
+ const hours = moment.tz("Asia/Manila").format("HH");
44
+ const { commands } = global.client;
45
+ const { threadID } = event;
46
+ let threadInfo = await api.getThreadInfo(event.threadID);
47
+ let threadName = threadInfo.threadName;
48
+ if (!event.logMessageData.addedParticipants || !Array.isArray(event.logMessageData.addedParticipants)) {
49
+ return;
50
+ }
51
+ if (event.logMessageData.addedParticipants && Array.isArray(event.logMessageData.addedParticipants) && event.logMessageData.addedParticipants.some(i => i.userFbId == api.getCurrentUserID())) {
52
+ //api.changeNickname(`𝗕𝗢𝗧 ${(!global.config.BOTNAME) ? "Buddy" : global.config.BOTNAME}`, threadID, api.getCurrentUserID());
53
+
54
+ let gifUrl = 'https://i.imgur.com/4HMupHz.gif';
55
+ let gifPath = __dirname + '/cache/join/join.gif';
56
+
57
+ axios.get(gifUrl, { responseType: 'arraybuffer' })
58
+ .then(response => {
59
+ fs.writeFileSync(gifPath, response.data);
60
+ return api.sendMessage("Hey There!", event.threadID, () => api.sendMessage({ body: `✅ Group Connection in ${threadName} at ${session} success! \n\n➭ Current Commands: ${commands.size}\n➭ Bot Prefix: ${global.config.PREFIX}\n➭ Version: ${global.config.version}\n➭ Admin: ‹${ADMIN}›\n➭ Facebook: ‹${FB_LINK}›\n➭ Use ${PRFX}help to view command details\n➭ Added bot at: ⟨ ${time} ⟩〈 ${thu} 〉`, attachment: fs.createReadStream(gifPath)}, threadID));
61
+ })
62
+ .catch(error => {
63
+ console.error(error);
64
+ });
65
+ }
66
+ else {
67
+ try {
68
+ if (!fs.existsSync(__dirname + `/cache/font/Semi.ttf`)) {
69
+ let getfont = (await axios.get(fontlink, { responseType: "arraybuffer" })).data;
70
+ fs.writeFileSync(__dirname + `/cache/font/Semi.ttf`, Buffer.from(getfont, "utf-8"));
71
+ };
72
+ const { createReadStream, existsSync, mkdirSync, readdirSync } = global.nodemodule["fs-extra"];
73
+ let { threadName, participantIDs } = await api.getThreadInfo(threadID);
74
+ const threadData = global.data.threadData.get(parseInt(threadID)) || {};
75
+ var mentions = [], nameArray = [], memLength = [], iduser = [], i = 0;
76
+ var abx = [];
77
+ for (id in event.logMessageData.addedParticipants) {
78
+ const userName = event.logMessageData.addedParticipants[id].fullName; iduser.push(event.logMessageData.addedParticipants[id].userFbId.toString());
79
+ nameArray.push(userName);
80
+ mentions.push({ tag: userName, id: event.senderID });
81
+ memLength.push(participantIDs.length - i++);
82
+ console.log(userName)
83
+ }
84
+ // console.log(event.logMessageData.addedParticipants)
85
+ var id = [];
86
+ for (let o = 0; o < event.logMessageData.addedParticipants.length; o++) {
87
+ let pathImg = __dirname + `/cache/join/${o}.png`;
88
+ let pathAva = __dirname + `/cache/join/avt.png`;
89
+ let avtAnime = (await axios.get(encodeURI(
90
+ `https://graph.facebook.com/${event.logMessageData.addedParticipants[o].userFbId}/picture?height=720&width=720&access_token=6628568379%7Cc1e620fa708a1d5696fb991c1bde5662`), { responseType: "arraybuffer" })).data;
91
+ var ok = [
92
+ 'https://i.imgur.com/dDSh0wc.jpeg',
93
+ 'https://i.imgur.com/UucSRWJ.jpeg',
94
+ 'https://i.imgur.com/OYzHKNE.jpeg',
95
+ 'https://i.imgur.com/V5L9dPi.jpeg',
96
+ 'https://i.imgur.com/M7HEAMA.jpeg'
97
+ ]
98
+ let background = (await axios.get(encodeURI(`${ok[Math.floor(Math.random() * ok.length)]}`), { responseType: "arraybuffer", })).data;
99
+ fs.writeFileSync(pathAva, Buffer.from(avtAnime, "utf-8"));
100
+ fs.writeFileSync(pathImg, Buffer.from(background, "utf-8"));
101
+ var avatar = await this.circle(pathAva);
102
+ let baseImage = await loadImage(pathImg);
103
+ let baseAva = await loadImage(avatar);
104
+ registerFont(__dirname + `/cache/font/Semi.ttf`, {
105
+ family: "Semi"
106
+ });
107
+ let canvas = createCanvas(1902, 1082);
108
+ console.log(canvas.width, canvas.height)
109
+ let ctx = canvas.getContext("2d");
110
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
111
+ ctx.drawImage(baseImage, 0, 0, canvas.width, canvas.height);
112
+ ctx.drawImage(baseAva, canvas.width / 2 - 188, canvas.height / 2 - 375, 375, 355);
113
+ ctx.fillStyle = "#FFF";
114
+ ctx.textAlign = "center";
115
+ ctx.font = `155px Semi`;
116
+ ctx.fillText(`${event.logMessageData.addedParticipants[o].fullName}`, canvas.width / 2 + 20, canvas.height / 2 + 100);
117
+ ctx.save();
118
+ ctx.font = `75px Semi`;
119
+ ctx.fillText(`Welcome to ${threadName}`, canvas.width / 2 - 15, canvas.height / 2 + 235)
120
+ const number = participantIDs.length - o;
121
+
122
+ if (number === 11 || number === 12 || number === 13) {
123
+ suffix = "th";
124
+ } else {
125
+ const lastDigit = number % 10;
126
+ switch (lastDigit) {
127
+ case 1:
128
+ suffix = "st";
129
+ break;
130
+ case 2:
131
+ suffix = "nd";
132
+ break;
133
+ case 3:
134
+ suffix = "rd";
135
+ break;
136
+ default:
137
+ suffix = "th";
138
+ break;
139
+ }
140
+ }
141
+
142
+ ctx.fillText(`You are the ${number}${suffix} member of this group`, canvas.width / 2 - 15, canvas.height / 2 + 350);
143
+ ctx.restore();
144
+ const imageBuffer = canvas.toBuffer();
145
+ fs.writeFileSync(pathImg, imageBuffer);
146
+ abx.push(fs.createReadStream(__dirname + `/cache/join/${o}.png`))
147
+ }
148
+ memLength.sort((a, b) => a - b);
149
+ (typeof threadData.customJoin == "undefined") ? msg = `🌟 Welcome new member {name} to the group {threadName}\n→ URL Profile:\nhttps://www.facebook.com/profile.php?id={iduser}\n→ {type} are the group's {soThanhVien}${suffix} member\n→ Added to the group by: {author}\n→ Added by facebook link: https://www.facebook.com/profile.php?id={uidAuthor}\n─────────────────\n[ {time} - {thu} ]` : msg = threadData.customJoin;
150
+ var nameAuthor = await Users.getNameUser(event.author)
151
+ msg = msg
152
+ .replace(/\{iduser}/g, iduser.join(', '))
153
+ .replace(/\{name}/g, nameArray.join(', '))
154
+ .replace(/\{type}/g, (memLength.length > 1) ? 'You' : 'You')
155
+ .replace(/\{soThanhVien}/g, memLength.join(', '))
156
+ .replace(/\{threadName}/g, threadName)
157
+ .replace(/\{author}/g, nameAuthor)
158
+ .replace(/\{uidAuthor}/g, event.author)
159
+ .replace(/\{buoi}/g, session)
160
+ .replace(/\{time}/g, time)
161
+ .replace(/\{thu}/g, thu);
162
+
163
+ var formPush = { body: msg, attachment: abx, mentions }
164
+ api.sendMessage(formPush, threadID);
165
+ for (let ii = 0; ii < parseInt(id.length); ii++) {
166
+ fs.unlinkSync(__dirname + `/cache/join/${ii}.png`)
167
+ }
168
+ } catch (e) { return console.log(e) };
169
+ }
170
+ }
modules/events/leave.js ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module.exports.config = {
2
+ name: "leave",
3
+ eventType: ['log:unsubscribe'],
4
+ version: "1.0.0",
5
+ credits: "Jonell Magallanes",
6
+ description: "GROUP LEAVE NOTIFICATION"
7
+ };
8
+
9
+ module.exports.run = async function({ api, event }) {
10
+ if (event.logMessageType === "log:unsubscribe") {
11
+ if (event.logMessageData.leftParticipantFbId == api.getCurrentUserID()) return;
12
+
13
+ try {
14
+ let { threadName, participantIDs } = await api.getThreadInfo(event.threadID);
15
+ const type = (event.author == event.logMessageData.leftParticipantFbId) ? "left the group." : "kicked by Admin of the group";
16
+ let name = (await api.getUserInfo(event.logMessageData.leftParticipantFbId))[event.logMessageData.leftParticipantFbId].name;
17
+
18
+ api.shareContact(`${name} has been ${type}\nMember’s left: ${participantIDs.length}`, event.logMessageData.leftParticipantFbId, event.threadID);
19
+ } catch (err) {
20
+ console.error("ERROR: ", err);
21
+ }
22
+ }
23
+ };
modules/events/leaveNoti.js.temp ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module.exports.config = {
2
+ name: "leave",
3
+ eventType: ["log:unsubscribe"],
4
+ version: "1.0.0",
5
+ credits: "Mirai Team & Mod by Yan Maglinte", // Added canvas
6
+ description: "Notifies bots or people leaving the group",
7
+ dependencies: {
8
+ "fs-extra": "",
9
+ "path": ""
10
+ }
11
+ };
12
+
13
+ const axios = require('axios');
14
+ const { createCanvas, loadImage, registerFont } = require('canvas');
15
+ const fs = require('fs-extra');
16
+ const path = require('path');
17
+ const jimp = require("jimp");
18
+
19
+ let backgrounds = [
20
+ "https://i.imgur.com/MnAwD8U.jpg",
21
+ "https://i.imgur.com/tSkuyIu.jpg"
22
+ ];
23
+ let fontlink = 'https://drive.google.com/u/0/uc?id=1ZwFqYB-x6S9MjPfYm3t3SP1joohGl4iw&export=download';
24
+
25
+ module.exports.run = async function({ api, event, Users, Threads }) {
26
+ const leftParticipantFbId = event.logMessageData.leftParticipantFbId;
27
+ const name = global.data.userName.get(leftParticipantFbId) || await Users.getNameUser(leftParticipantFbId);
28
+ const type = (event.author == leftParticipantFbId) ? "left by itself" : "been kicked by the administrator";
29
+ const Yan = (event.author == leftParticipantFbId) ? "left by itself" : "has been kicked by the administrator";
30
+
31
+ let fontPath = path.join(__dirname, "cache", "font.ttf");
32
+ let font = (await axios.get(fontlink, { responseType: 'arraybuffer' })).data;
33
+ fs.writeFileSync(fontPath, font);
34
+ registerFont(fontPath, { family: 'CustomFont' });
35
+
36
+ let randomBackground = backgrounds[Math.floor(Math.random() * backgrounds.length)];
37
+ let background = await loadImage(randomBackground);
38
+
39
+ let avatarUrl = `https://graph.facebook.com/${leftParticipantFbId}/picture?height=720&width=720&access_token=6628568379%7Cc1e620fa708a1d5696fb991c1bde5662`;
40
+ let avatarPath = path.join(__dirname, "cache/leave/leave.png");
41
+ let avatarData = (await axios.get(avatarUrl, { responseType: 'arraybuffer' })).data;
42
+ fs.writeFileSync(avatarPath, avatarData);
43
+ let avatar = await jimp.read(avatarPath);
44
+ avatar.circle();
45
+ let roundAvatar = await avatar.getBufferAsync('image/png');
46
+ let roundAvatarImg = await loadImage(roundAvatar);
47
+
48
+ const canvas = createCanvas(1280, 720);
49
+ const ctx = canvas.getContext('2d');
50
+ const yandeva = name.length > 10 ? name.slice(0, 10) + "..." : name;
51
+
52
+ ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
53
+ ctx.drawImage(roundAvatarImg, canvas.width / 2 - 500, canvas.height / 2 - 200, 420, 420);
54
+ ctx.font = '100px CustomFont';
55
+ ctx.fillStyle = '#FFF';
56
+ ctx.fillText(yandeva, canvas.width / 2 - 60, canvas.height / 2 + 90);
57
+
58
+ ctx.font = '40px CustomFont';
59
+ ctx.fillText(Yan, canvas.width / 2 - 50, canvas.height / 2 + 140);
60
+
61
+ let finalImage = canvas.toBuffer();
62
+ fs.writeFileSync(path.join(__dirname, 'cache/leave/leave.png'), finalImage);
63
+
64
+ const formPush = {
65
+ body: `💥${name} has ${type} from the group`,
66
+ attachment: fs.createReadStream(path.join(__dirname, 'cache/leave/leave.png'))
67
+ };
68
+
69
+ return api.sendMessage(formPush, event.threadID);
70
+ }