API-XX commited on
Commit
8b2ea03
Β·
verified Β·
1 Parent(s): 7b8e879

Upload group.js

Browse files
Files changed (1) hide show
  1. group.js +262 -0
group.js ADDED
@@ -0,0 +1,262 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const moment = require("moment-timezone")
2
+ const chalk = require("chalk")
3
+ const fs = require('fs-extra')
4
+ const util = require("util")
5
+ const {
6
+ getRandom,
7
+ getGroupAdmins,
8
+ sleep
9
+ } = require("../lib/myfunc");
10
+
11
+ //Function update member
12
+ module.exports = async (conn, anu) => {
13
+ var jeda = false;
14
+ if (jeda) return console.log("spam welcome active");
15
+ jeda = true;
16
+ try {
17
+ const {
18
+ id,
19
+ participants,
20
+ action
21
+ } = anu;
22
+
23
+
24
+ if (action === "demote") {
25
+ let members = conn.chats[id].metadata.participants
26
+ await members.forEach(participant => {
27
+ if (participant.id === participants[0]) {
28
+ participant.admin = null;
29
+ }
30
+ });
31
+ let nana = members.filter(v => v.id === participants[0])
32
+ console.log(nana)
33
+ } else if (action === "promote") {
34
+ let members = conn.chats[id].metadata.participants
35
+ await members.forEach(participant => {
36
+ if (participant.id === participants[0]) {
37
+ participant.admin = 'admin'
38
+ }
39
+ });
40
+ let nana = members.filter(v => v.id === participants[0])
41
+ console.log(nana)
42
+ }
43
+
44
+
45
+
46
+ if (anu.participants[0].includes('@lid')) return console.log(chalk.magenta('log 1'))
47
+ if ((action == "remove" || action == "promote" || action == "demote") &&
48
+ anu.participants[0].split("@")[0].includes(conn.user.id.split(":")[0])
49
+ )
50
+ return console.log(chalk.magenta('log 2'))
51
+ const myGroup = Object.keys(db.data.chats);
52
+ const from = anu.id
53
+ const botNumber = conn.user.jid;
54
+ const groupMetadata = ((conn.chats[from] || {}).metadata || await conn.groupMetadata(from).catch(_ => null)) || {}
55
+ const groupName = groupMetadata.subject || [];
56
+ const groupLength = groupMetadata.participants.length;
57
+ const sender = conn.decodeJid(anu.participants[0])
58
+ if (sender.includes('_')) return log('log 3')
59
+ const senderNumber = sender.split("@")[0];
60
+ const groupMembers = groupMetadata.participants || [];
61
+ const groupAdmins = getGroupAdmins(groupMembers) || [];
62
+ const groupDesc = groupMetadata.desc || [];
63
+ const groupOwner = groupMetadata.owner || [];
64
+ const user =
65
+ groupMembers.find((u) => conn.decodeJid(u.id) === sender) || {};
66
+ const bot =
67
+ groupMembers.find((u) => conn.decodeJid(u.id) == conn.user.jid) || {};
68
+
69
+ const isRAdmin = (user && user.admin == "superadmin") || false;
70
+ const isAdmin = isRAdmin || (user && user.admin == "admin") || false;
71
+ const isBotAdmin = (bot && bot.admin == "admin") || false; // Are you Admin?
72
+ const pushname = await conn.getName(sender);
73
+ const oneMem = anu.participants.length === 1;
74
+ const itsMe = sender === botNumber;
75
+ const timeWib = moment.tz("Asia/Jakarta").format("HH:mm");
76
+ const chat = global.db.data.chats[id];
77
+ const add = action == "add";
78
+ const remove = action == "remove";
79
+ const memb = groupMetadata.participants.length
80
+ const isBanchat = myGroup.includes(from) ?
81
+ db.data.chats[from].banchat :
82
+ false;
83
+ if (isBanchat) {
84
+ return console.log(chalk.magenta('log 4'))
85
+ }
86
+ let m = {
87
+ chat: from,
88
+ pushname: pushname,
89
+ sender: sender,
90
+ };
91
+
92
+ if (!chat) return console.log(chalk.magenta('log 5'))
93
+ let sBye = chat.sBye;
94
+ let sWelcome = chat.sWelcome;
95
+
96
+ if (add && oneMem)
97
+ console.log(
98
+ chalk.magenta("[GROUP UPDATE]"),
99
+ chalk.green(`${pushname} has joined from g`),
100
+ chalk.magenta(`${groupName}`)
101
+ );
102
+ if (remove && oneMem)
103
+ console.log(
104
+ chalk.magenta("[GROUP UPDATE]"),
105
+ chalk.green(`${pushname} has left the gc`),
106
+ chalk.magenta(`${groupName}`)
107
+ );
108
+
109
+
110
+ let kickon = db.data.kickon[from];
111
+ if (add && kickon && kickon.includes(senderNumber)) {
112
+ let teks = `@user is not allowed to enter
113
+ because he has left this group before,
114
+ and has also been marked as a bad user`;
115
+ let text = teks.replace("user", await conn.getName(sender));
116
+
117
+ await conn.sendMessage(
118
+ from, {
119
+ text,
120
+ mentions: [sender],
121
+ contextInfo: {
122
+ mentionedJid: [sender]
123
+ }
124
+ },
125
+
126
+ );
127
+ if (!isBotAdmin)
128
+ return conn.sendMessage(
129
+ from, {
130
+ text: `Failed to eject @${senderNumber} from the group because the bot is not an admin`,
131
+ contextInfo: {
132
+ mentionedJid: [sender]
133
+ },
134
+ },
135
+
136
+ );
137
+ if (isBotAdmin)
138
+ return conn.groupParticipantsUpdate(from, [sender], "remove");
139
+ }
140
+ let welcome = 'https://telegra.ph/file/5bedca1f745b1649ecf0b.jpg'
141
+ let goodbye = 'https://telegra.ph/file/c9b18fcfa9df16f13fd51.jpg'
142
+ if (action == "add") {
143
+ var link = welcome;
144
+ } else {
145
+ var link = goodbye;
146
+ }
147
+
148
+ const botRun = global.db.data.others['runtime']
149
+ const botTime = botRun ? (new Date - botRun.runtime) : "Not detected"
150
+ const runTime = clockString(botTime)
151
+ let mimetype = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
152
+
153
+ let contextInfo = {
154
+ forwardingScore: 1,
155
+ isForwarded: true,
156
+ mentionedJid: [sender],
157
+ forwardednewsletterMessageInfo: {
158
+ newsletterJid,
159
+ serverMessageId: 100,
160
+ newsletterName
161
+ },
162
+ externalAdReply: {
163
+ showAdAttribution: false,
164
+ title: `${action == "add"? 'W E L C O M E': 'G O O D B Y E'}`,
165
+ body: `BY 𝐁𝐋𝐔𝐄 πƒπ„πŒπŽπ`,
166
+ sourceUrl: global.myUrl,
167
+ mediaType: 1,
168
+ renderLargerThumbnail: true,
169
+ thumbnailUrl: link,
170
+ }
171
+ }
172
+
173
+
174
+
175
+
176
+ switch (action) {
177
+
178
+ case "add": {
179
+ if (!chat.welcome) return
180
+ let teks = `*Hello @user*
181
+ *welcome to group* ${groupName}
182
+ *Description : \n@desc*
183
+ ${sWelcome}`;
184
+ const welcomeText = (chat.sWelcome || teks)
185
+ .replace("user", await conn.getName(sender))
186
+ .replace("@desc", groupDesc.toString() || "unknow")
187
+ .replace("@subject", groupName);
188
+ if (chat.welcome && !itsMe && oneMem) conn.sendMessage(
189
+ from, {
190
+ document: fs.readFileSync('./package.json'),
191
+ caption: welcomeText,
192
+ fileName: copyright,
193
+ mimetype,
194
+ pageCount: 100,
195
+ fileLength: 999999999999,
196
+ contextInfo
197
+ }
198
+ );
199
+
200
+
201
+ }
202
+ break;
203
+
204
+ case "remove": {
205
+ if (!chat.welcome) return
206
+ let teks = `Goodbye @user
207
+ ${sBye}`;
208
+ const byeText = (chat.sBye || teks)
209
+ .replace("user", await conn.getName(sender))
210
+ .replace("@desc", groupDesc.toString() || "unknow")
211
+ .replace("@subject", groupName);
212
+ if (chat.welcome && !itsMe && oneMem) conn.sendMessage(
213
+ from, {
214
+ document: fs.readFileSync('./package.json'),
215
+ caption: byeText,
216
+ fileName: copyright,
217
+ mimetype,
218
+ pageCount: 100,
219
+ fileLength: 999999999999,
220
+ contextInfo
221
+ }
222
+ );
223
+ }
224
+ break
225
+
226
+
227
+
228
+
229
+ }
230
+
231
+ await sleep(5000);
232
+ jeda = false;
233
+ } catch (err) {
234
+
235
+ jeda = false;
236
+ console.log(err);
237
+ let e = String(err);
238
+ if (e.includes("this.isZero")) {
239
+ return;
240
+ }
241
+ if (e.includes("rate-overlimit")) {
242
+ return;
243
+ }
244
+ if (e.includes("connection Closed")) {
245
+ return;
246
+ }
247
+ if (e.includes("Timed Out")) {
248
+ return;
249
+ }
250
+ console.log(chalk.white("GROUP :"), chalk.green(e));
251
+
252
+ let text = `${util.format(anu)}
253
+
254
+ ${util.format(groupMetadata)}
255
+
256
+ ${util.format(err)}`
257
+ conn.sendMessage(ownerBot, {
258
+ text
259
+ })
260
+
261
+ }
262
+ };