forked from Keithkeizzah/KEITH-MD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroupEvents.js
More file actions
84 lines (75 loc) · 3.4 KB
/
groupEvents.js
File metadata and controls
84 lines (75 loc) · 3.4 KB
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
75
76
77
78
79
80
81
82
83
84
const events = process.env.EVENTS || 'false';
const botname = process.env.BOTNAME || 'KEITH-MD';
const getContextInfo = (m) => {
return {
mentionedJid: [m.sender],
forwardingScore: 999,
isForwarded: true,
forwardedNewsletterMessageInfo: {
newsletterJid: '120363266249040649@newsletter',
newsletterName: 'Keith Support',
serverMessageId: 143
}
};
};
const Events = async (client, keizzah) => {
const Myself = await client.decodeJid(client.user.id);
try {
let metadata = await client.groupMetadata(keizzah.id);
let participants = keizzah.participants;
let desc = metadata.desc || "No Description";
let groupMembersCount = metadata.participants.length;
for (let num of participants) {
let dpuser;
try {
dpuser = await client.profilePictureUrl(num, "image");
} catch {
dpuser = "https://i.imgur.com/iEWHnOH.jpeg";
}
if (keizzah.action === "add") {
let userName = num;
let Welcometext = `Hey @${userName.split("@")[0]} 👋\n\nWelcome to ${metadata.subject}.\n\nYou are now ${groupMembersCount} members in this group🙏.\n\nPlease read the group description to avoid being removed:\n${desc}\n\n*Regards keithkeizzah*.\n\nPowered by ${botname}.`;
if (events === 'true') {
await client.sendMessage(keizzah.id, {
image: { url: dpuser },
caption: Welcometext,
mentions: [num],
contextInfo: getContextInfo({sender: Myself})
});
}
} else if (keizzah.action === "remove") {
let userName2 = num;
let Lefttext = `Goodbye to this idiot another fallen soldier @${userName2.split("@")[0]}!You will be remembered. We are now ${groupMembersCount} members in this group😭.`;
if (events === 'true') {
await client.sendMessage(keizzah.id, {
image: { url: dpuser },
caption: Lefttext,
mentions: [num],
contextInfo: getContextInfo({sender: Myself})
});
}
} else if (keizzah.action === "demote" && events === 'true') {
await client.sendMessage(
keizzah.id,
{
text: `@${(keizzah.author).split("@")[0]}, has demoted @${(keizzah.participants[0]).split("@")[0]} from admin 👀`,
mentions: [keizzah.author, keizzah.participants[0]],
contextInfo: getContextInfo({sender: Myself})
}
);
} else if (keizzah.action === "promote" && events === 'true') {
await client.sendMessage(
keizzah.id,
{
text: `@${(keizzah.author).split("@")[0]} has promoted @${(keizzah.participants[0]).split("@")[0]} to admin. 👀`,
mentions: [keizzah.author, keizzah.participants[0]],
contextInfo: getContextInfo({sender: Myself})
}
);
}
}
} catch (err) {
console.log(err);
}
};
module.exports = Events;