File size: 22,878 Bytes
046b271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
const config = require('../config')
const { cmd, commands } = require('../command')
const { getBuffer, getGroupAdmins, getRandom, h2k, isUrl, Json, runtime, sleep, fetchJson} = require('../lib/functions')

cmd({
    pattern: "join",
    react: "πŸ“¬",
    alias: ["joinme","f_join"],
    desc: "To Join a Group from Invite link",
    category: "group",
    use: '.join < Group Link >',
    filename: __filename
},
async(conn, mek, m,{from, l, quoted, body, isCmd, command, args, q, isGroup, sender, senderNumber, botNumber2, botNumber, pushname, isMe, isOwner, groupMetadata, groupName, participants, groupAdmins, isBotAdmins, isCreator ,isDev, isAdmins, reply}) => {
try{
const msr = (await fetchJson('https://raw.githubusercontent.com/JawadYTX/KHAN-DATA/refs/heads/main/MSG/mreply.json')).replyMsg

if (!isCreator && !isDev && !isOwner && !isMe) return reply(msr.own_cmd)
if (!q) return reply("*Please write the Group Link πŸ–‡οΈ*")
 let result = args[0].split('https://chat.whatsapp.com/')[1]
 await conn.groupAcceptInvite(result)
     await conn.sendMessage(from , { text: `*Successfully Joined βœ…*`}, { quoted: mek } )
} catch (e) {
await conn.sendMessage(from, { react: { text: '❌', key: mek.key } })
console.log(e)
reply(`❌ *Error Accurated !!*\n\n${e}`)
}
} )

cmd({
    pattern: "tagadmins",
    react: "πŸ‘‘",
    alias: ["admin" ,"admin","tagadmin"],
    desc: "To Tag all Admins of the Group",
    category: "group",
    use: '.tagadmins [message]',
    filename: __filename
},
async (conn, mek, m, { from, participants, reply, isGroup, senderNumber, groupAdmins, prefix, command, args, body }) => {
    try {
        if (!isGroup) return reply("❌ This command can only be used in groups.");
        
        const botOwner = conn.user.id.split(":")[0]; // Extract bot owner's number
        const senderJid = senderNumber + "@s.whatsapp.net";

        // Ensure group metadata is fetched properly
        let groupInfo = await conn.groupMetadata(from).catch(() => null);
        if (!groupInfo) return reply("❌ Failed to fetch group information.");

        let groupName = groupInfo.subject || "Unknown Group";
        let admins = await getGroupAdmins(participants);
        let totalAdmins = admins ? admins.length : 0;
        if (totalAdmins === 0) return reply("❌ No admins found in this group.");

        let emojis = ['⚑', '✨', 'πŸŽ–οΈ', 'πŸ’Ž', 'πŸ”±', 'πŸ’—',  'β€β€πŸ©Ή', 'πŸ‘»', '🌟', 'πŸͺ„', 'πŸŽ‹', 'πŸͺΌ', '🍿', 'πŸ‘€', 'πŸ‘‘', 'πŸ¦‹', 'πŸ‹', '🌻', '🌸', 'πŸ”₯', 'πŸ‰', '🍧', '🍨', '🍦', 'πŸ§ƒ', 'πŸͺ€', '🎾', 'πŸͺ‡', '🎲', '🎑', '🧸', 'πŸŽ€', '🎈', '🩡', 'β™₯️', '🚩' , 'πŸ³οΈβ€πŸŒˆ', 'πŸ”ͺ', '🎏', '🫐', 'πŸ“', 'πŸ‡', '🐍', 'πŸͺ»', 'πŸͺΈ', 'πŸ’€'];
        let randomEmoji = emojis[Math.floor(Math.random() * emojis.length)];

        // Proper message extraction
        let message = body.slice(body.indexOf(command) + command.length).trim();
        if (!message) message = "ATTENTION ADMINS"; // Default message

        let teks = `*β–’ GROUP : ${groupName}*\n*β–’ ADMINS : ${totalAdmins}*\n*β–’ MESSAGE: ${message}*\n\nβ€Ž*β•­β”€β”€β”€βγ€Œ ADMINS MENTION 」❍*\n`;

        for (let admin of admins) {
            if (!admin) continue; // Prevent undefined errors
            teks += `*β”‚${randomEmoji} ᩧ𝆺ྀི𝅥* @${admin.split('@')[0]}\n`;
        }

       // teks += "└──βœͺ ALI ┃ MD βœͺ──";

        conn.sendMessage(from, { text: teks, mentions: admins }, { quoted: mek });

    } catch (e) {
        console.error("TagAdmins Error:", e);
        reply(`❌ *Error Occurred !!*\n\n${e.message || e}`);
    }
});

cmd({
    pattern: "invite",
    react: "πŸ–‡οΈ",
    alias: ["grouplink","glink"],
    desc: "To Get the Group Invite link",
    category: "group",
    use: '.invite',
    filename: __filename
},
async(conn, mek, m,{from, l, quoted, body, isCmd, command, args, q, isGroup, sender, senderNumber, botNumber2, botNumber, pushname, isMe, isOwner, groupMetadata, groupName, participants, groupAdmins, isBotAdmins, isCreator ,isDev, isAdmins, reply}) => {
try{
const msr = (await fetchJson('https://raw.githubusercontent.com/JawadYTX/KHAN-DATA/refs/heads/main/MSG/mreply.json')).replyMsg

if (!isGroup) return reply(msr.only_gp)
if (!isAdmins) { if (!isDev) return reply(msr.you_adm),{quoted:mek }} 
if (!isBotAdmins) return reply(msr.give_adm)
const code = await conn.groupInviteCode(from)

 await conn.sendMessage(from , { text: `*πŸ–‡οΈ Group Link*\n\nhttps://chat.whatsapp.com/${code}`}, { quoted: mek } )
} catch (e) {
await conn.sendMessage(from, { react: { text: '❌', key: mek.key } })
console.log(e)
reply(`❌ *Error Accurated !!*\n\n${e}`)
}
} )

cmd({
    pattern: "revoke",
    react: "πŸ–‡οΈ",
    alias: ["revokegrouplink","resetglink","revokelink","f_revoke"],
    desc: "To Reset the group link",
    category: "group",
    use: '.revoke',
    filename: __filename
},
async(conn, mek, m,{from, l, quoted, body, isCmd, command, args, q, isGroup, sender, senderNumber, botNumber2, botNumber, pushname, isMe, isOwner, groupMetadata, groupName, participants, groupAdmins, isBotAdmins, isCreator ,isDev, isAdmins, reply}) => {
try{
const msr = (await fetchJson('https://raw.githubusercontent.com/JawadYTX/KHAN-DATA/refs/heads/main/MSG/mreply.json')).replyMsg

if (!isGroup) return reply(msr.only_gp)
if (!isAdmins) { if (!isDev) return reply(msr.you_adm),{quoted:mek }} 
if (!isBotAdmins) return reply(msr.give_adm)
await conn.groupRevokeInvite(from)
 await conn.sendMessage(from , { text: `*Group link Reseted* β›”`}, { quoted: mek } )
} catch (e) {
await conn.sendMessage(from, { react: { text: '❌', key: mek.key } })
console.log(e)
reply(`❌ *Error Accurated !!*\n\n${e}`)
}
} )

cmd({
    pattern: "promote",
    react: "πŸ₯",
    alias: ["addadmin"],
    desc: "Promote a user to admin.",
    category: "group",
    filename: __filename
}, async (conn, mek, m, {
    from,
    quoted,
    isGroup,
    isAdmins,
    isOwner,
    participants,
    isBotAdmins,
    reply
}) => {
    try {
        if (!isGroup) return reply("❌ This command can only be used in groups.");
        if (!isAdmins && !isOwner) return reply("❌ Only group admins or the owner can use this command.");
        if (!isBotAdmins) return reply("❌ I need admin privileges to promote members.");

        // ➑️ Détecter le participant à promouvoir (en réponse ou mention)
        let target;
        if (m.quoted) {
            target = m.quoted.sender;
        } else if (m.mentionedJid && m.mentionedJid.length > 0) {
            target = m.mentionedJid[0];
        } else if (m.msg && m.msg.contextInfo && m.msg.contextInfo.mentionedJid && m.msg.contextInfo.mentionedJid.length > 0) {
            target = m.msg.contextInfo.mentionedJid[0];
        }

        if (!target) return reply("❌ Please mention or reply to a user to promote.");

        // ➑️ Vérifier si l'utilisateur est déjà admin
        const isAlreadyAdmin = participants.some(p => p.id === target && p.admin !== null);
        if (isAlreadyAdmin) return reply("❗ User is already an admin.");

        // ➑️ Promouvoir le participant
        await conn.groupParticipantsUpdate(from, [target], "promote")
            .catch(err => {
                console.error(`⚠️ Failed to promote ${target}:`, err);
                return reply("❌ An error occurred while promoting the participant.");
            });

        // ➑️ Extraire le tag à partir du JID
        const tag = target.split('@')[0];
        reply(`*_@${tag} Promoted Successfully_*`, { mentions: [target] });

    } catch (error) {
        console.error('Error while executing promote:', error);
        reply('❌ An error occurred while executing the command.');
    }
});

cmd({
    pattern: "demote",
    react: "πŸ₯",
    alias: ["removeadmin"],
    desc: "Demote a user from admin.",
    category: "group",
    filename: __filename
}, async (conn, mek, m, {
    from,
    quoted,
    isGroup,
    isAdmins,
    isOwner,
    participants,
    isBotAdmins,
    reply
}) => {
    try {
        if (!isGroup) return reply("❌ This command can only be used in groups.");
        if (!isAdmins && !isOwner) return reply("❌ Only group admins or the owner can use this command.");
        if (!isBotAdmins) return reply("❌ I need admin privileges to demote members.");

        // ➑️ Détecter le participant à rétrograder (en réponse ou mention)
        let target;
        if (m.quoted) {
            target = m.quoted.sender;
        } else if (m.mentionedJid && m.mentionedJid.length > 0) {
            target = m.mentionedJid[0];
        } else if (m.msg && m.msg.contextInfo && m.msg.contextInfo.mentionedJid && m.msg.contextInfo.mentionedJid.length > 0) {
            target = m.msg.contextInfo.mentionedJid[0];
        }

        if (!target) return reply("❌ Please mention or reply to a user to demote.");

        // ➑️ Vérifier si l'utilisateur est bien admin
        const isAdmin = participants.some(p => p.id === target && p.admin !== null);
        if (!isAdmin) return reply("❗ User is not an admin.");

        // ➑️ Rétrograder le participant
        await conn.groupParticipantsUpdate(from, [target], "demote")
            .catch(err => {
                console.error(`⚠️ Failed to demote ${target}:`, err);
                return reply("❌ An error occurred while demoting the participant.");
            });

        // ➑️ Extraire le tag à partir du JID
        const tag = target.split('@')[0];
        reply(`*_@${tag} Demoted Successfully_*`, { mentions: [target] });

    } catch (error) {
        console.error('Error while executing demote:', error);
        reply('❌ An error occurred while executing the command.');
    }
});


cmd({
    pattern: "taggp",
    react: "πŸ”Š",
    alias: ["tggp","djtaggp"],
    desc: "To Tag all Members for Message",
    category: "group",
    use: '.tag Hi',
    filename: __filename
},
async(conn, mek, m,{from, l, quoted, body, isCmd, command, mentionByTag , args, q, isGroup, sender, senderNumber, botNumber2, botNumber, pushname, isMe, isOwner, groupMetadata, groupName, participants, groupAdmins, isBotAdmins, isCreator ,isDev, isAdmins, reply}) => {
try{
		if ( !m.quoted ) return reply('*Please mention a message* ℹ️')
		if(!q) return reply('*Please add a Group Jid* ℹ️')
		//if ( q == "120363174739054837@g.us" ) { if ( !isDev ) return reply("❌ *Acai wage ! You can send Tag messages to Official Support Group*") }
		let teks = `${m.quoted.msg}`
        conn.sendMessage(q, { text: teks, mentions: participants.map(a => a.id) }, { quoted: mek })
                
} catch (e) {
await conn.sendMessage(from, { react: { text: '❌', key: mek.key } })
console.log(e)
reply(`❌ *Error Accurated !!*\n\n${e}`)
}
} )

cmd({
    pattern: "gginfo",
    desc: "Get group information.",
    category: "group",
    filename: __filename,
}, async (conn, mek, m, {
    from,
    isGroup,
    isAdmins,
    isOwner,
    isBotAdmins,
    reply
}) => {
    try {
        // Ensure the command is used in a group
        if (!isGroup) return reply("*`[❌]`This command can only be used in groups.*");

        // Only admins or the owner can use this command
        if (!isAdmins && !isOwner) return reply("*`[❌]`Only admins and the owner can use this command.*");

        // Ensure the bot has admin privileges
        if (!isBotAdmins) return reply("*`[❌]`I need admin privileges to execute this command.*");

        // Get group metadata
        const groupMetadata = await conn.groupMetadata(from);
        const groupName = groupMetadata.subject;
        const memberCount = groupMetadata.participants.length;

        // Get group creator
        let creator = groupMetadata.owner ? `@${groupMetadata.owner.split('@')[0]}` : 'Unknown';

        // Get list of admins
        const groupAdmins = groupMetadata.participants
            .filter(member => member.admin)
            .map((admin, index) => `${index + 1}. @${admin.id.split('@')[0]}`)
            .join("\n") || "No admins found";

        // Get creation date (convert from timestamp)
        const creationDate = groupMetadata.creation 
            ? new Date(groupMetadata.creation * 1000).toLocaleString('en-US', {
                weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit'
            }) 
            : 'Unknown';

        // Format the output message
        const message = `
β•­β”€β”€β”€β”€γ€Œ *GROUP INFO* 」────◆
β”‚ 🏷️ *Ι’Κ€α΄α΄œα΄˜ ɴᴀᴍᴇ:* ${groupName}  
β”‚ πŸ†” *Ι’Κ€α΄α΄œα΄˜ Ιͺα΄…:* ${from}  
β”‚ πŸ‘₯ *α΄›α΄α΄›α΄€ΚŸ ᴍᴇᴍʙᴇʀs:* ${memberCount}  
β”‚ πŸ‘¨πŸ»β€πŸ’» *ᴄʀᴇᴀᴛᴏʀ:* ${creator}  
β”‚ πŸ“… *ᴄʀᴇᴀᴛᴇᴅ ᴏɴ:* ${creationDate}  
β”‚ πŸ‘‘ *ᴀᴅᴍΙͺΙ΄s:*  
β”‚ ${groupAdmins}  
╰────────────────────◆`;

        // Send the group information with mentions
        await conn.sendMessage(from, {
            text: message,
            mentions: groupMetadata.participants
                .filter(member => member.admin)
                .map(admin => admin.id)
        }, { quoted: mek });

    } catch (error) {
        console.error("Error in ginfo command:", error);
        reply("❌ An error occurred while retrieving the group information.");
    }
});

cmd({
    pattern: "tagall",
    react: "πŸ“‘",
    alias: ["gc_tagall"],
    desc: "To Tag all Members",
    category: "group",
    use: '.tagall [message]',
    filename: __filename
},
async (conn, mek, m, { from, participants, reply, isGroup, senderNumber, groupAdmins, prefix, command, args, body }) => {
    try {
        if (!isGroup) return reply("*πŸ“› α΄›ΚœΙͺs ᴄᴏᴍᴍᴀɴᴅ α΄„α΄€Ι΄ ᴏɴʟʏ ʙᴇ ᴜsᴇᴅ ΙͺΙ΄ Ι’Κ€α΄α΄œα΄˜s.*");
        
        const botOwner = conn.user.id.split(":")[0]; // Extract bot owner's number
        const senderJid = senderNumber + "@s.whatsapp.net";

        if (!groupAdmins.includes(senderJid) && senderNumber !== botOwner) {
            return reply("*πŸ“› σɴℓʏ gΚ€Οƒα΄œα΄˜ Ξ±βˆ‚ΠΌΞΉΙ΄s ΟƒΚ€ Ρ‚Π½Ρ” σωɴєʀ α΄„Ξ±Ι΄ ᴜsΡ” Ρ‚Π½ΞΉΡ• α΄„ΟƒΠΌΠΌΞ±Ι΄βˆ‚.*");
        }

        // Ensure group metadata is fetched properly
        let groupInfo = await conn.groupMetadata(from).catch(() => null);
        if (!groupInfo) return reply("❌ Failed to fetch group information.");

        let groupName = groupInfo.subject || "Unknown Group";
        let totalMembers = participants ? participants.length : 0;
        if (totalMembers === 0) return reply("❌ No members found in this group.");

        let emojis = ['⚑', '✨', 'πŸŽ–οΈ', 'πŸ’Ž', 'πŸ”±', 'πŸ’—',  'β€β€πŸ©Ή', 'πŸ‘»', '🌟', 'πŸͺ„', 'πŸŽ‹', 'πŸͺΌ', '🍿', 'πŸ‘€', 'πŸ‘‘', 'πŸ¦‹', 'πŸ‹', '🌻', '🌸', 'πŸ”₯', 'πŸ‰', '🍧', '🍨', '🍦', 'πŸ§ƒ', 'πŸͺ€', '🎾', 'πŸͺ‡', '🎲', '🎑', '🧸', 'πŸŽ€', '🎈', '🩡', 'β™₯️', '🚩' , 'πŸ³οΈβ€πŸŒˆ', 'πŸ”ͺ', '🎏', '🫐', 'πŸ“', 'πŸ‡', '🐍', 'πŸͺ»', 'πŸͺΈ', 'πŸ’€'];
        let randomEmoji = emojis[Math.floor(Math.random() * emojis.length)];

        // Proper message extraction
        let message = body.slice(body.indexOf(command) + command.length).trim();
        if (!message) message = "ATTENTION EVERYONE"; // Default message

        let teks = `*β–’ GROUP : ${groupName}*\n*β–’ MEMBERS : ${totalMembers}*\n*β–’ MESSAGE : ${message}*\n\n*β•­β”ˆβ”€γ€Œ \`𓆩ုαͺ³πŒπ„ππ“πˆπŽππ’α€Ύαͺ³π“†ͺ\` γ€β”ˆβ*\n`;

        for (let mem of participants) {
            if (!mem.id) continue; // Prevent undefined errors
            teks += `*β”‚${randomEmoji} ᩧ𝆺ྀི𝅥* @${mem.id.split('@')[0]}\n`;
	}

        conn.sendMessage(from, { text: teks, mentions: participants.map(a => a.id) }, { quoted: mek });

    } catch (e) {
        console.error("TagAll Error:", e);
        reply(`❌ *Error Occurred !!*\n\n${e.message || e}`);
    }
});

cmd({
    pattern: "add",
    alias: ["aja"],
    react: "βž•",
    desc: "Adds a user to the group.",
    category: "group",
    filename: __filename,
    use: '<number>',
},           
async (conn, mek, m, { from, args, q, isGroup, senderNumber, botNumber, reply }) => {
    try {
        if (!isGroup) return reply("*πŸ“› This command can only be used in groups.*");

        // Extract bot owner's number
        const botOwner = conn.user.id.split(":")[0];

        // Restrict command usage to the bot owner only
        if (senderNumber !== botOwner) {
            return reply("*πŸ“› Only the bot owner can use this command.*");
        }

        // Ensure the bot is an admin
        if (!isBotAdmins) return reply("*πŸ“› I need to be an admin to add users.*");

        // Validate user input
        if (!q || isNaN(q)) return reply("*πŸ“› Please provide a valid phone number to add.*");
        
        const userToAdd = `${q}@s.whatsapp.net`;

        // Attempt to add the user to the group
        let response = await conn.groupParticipantsUpdate(from, [userToAdd], "add");

        // Check if the user was successfully added
        if (response[0].status === 200) {
            reply(`βœ… User *${q}* has been added to the group.`);
        } else {
            reply("❌ Failed to add user. Make sure the number is correct and they are not already in the group.");
        }
    } catch (e) {
        console.error("Error adding user:", e);
        reply("❌ An error occurred while adding the user. Please try again.");
    }
});

cmd({
    pattern: "updategdesc",
    alias: ["upgdesc", "gdesc"],
    react: "πŸ“œ",
    desc: "Change the group description.",
    category: "group",
    filename: __filename
},           
async (conn, mek, m, { from, isGroup, isAdmins, isBotAdmins, args, q, reply }) => {
    try {
        if (!isGroup) return reply("*πŸ“› This command can only be used in groups.*");
        if (!isAdmins) return reply("*❌ Only group admins can use this command.*");
        if (!isBotAdmins) return reply("❌ I need to be an admin to update the group description.");
        if (!q) return reply("*❌ Please provide a new group description.*");

        await conn.groupUpdateDescription(from, q);
        reply("*βœ… Group description has been updated.*");
    } catch (e) {
        console.error("Error updating group description:", e);
        reply("❌ Failed to update the group description. Please try again.");
    }
});

cmd({
    pattern: "updategname",
    alias: ["upgname", "gname"],
    react: "πŸ“",
    desc: "Change the group name.",
    category: "group",
    filename: __filename
},           
async (conn, mek, m, { from, isGroup, isAdmins, isBotAdmins, args, q, reply }) => {
    try {
        if (!isGroup) return reply("*πŸ“› This command can only be used in groups.*");
        if (!isAdmins) return reply("❌ Only group admins can use this command.");
        if (!isBotAdmins) return reply("*πŸ“› I need to be an admin to update the group name.*");
        if (!q) return reply("*⁉️ Please provide a new group name.*");

        await conn.groupUpdateSubject(from, q);
        reply(`βœ… Group name has been updated to: *${q}*`);
    } catch (e) {
        console.error("Error updating group name:", e);
        reply("❌ Failed to update the group name. Please try again.");
    }
});


cmd({
    pattern: "lockgc",
    alias: ["lock"],
    react: "πŸ”’",
    desc: "Lock the group (Prevents new members from joining).",
    category: "group",
    filename: __filename
},           
async (conn, mek, m, { from, isGroup, isAdmins, isBotAdmins, reply }) => {
    try {
        if (!isGroup) return reply("❌ This command can only be used in groups.");
        if (!isAdmins) return reply("*πŸ“› Only group admins can use this command.*");
        if (!isBotAdmins) return reply("*πŸ“› I need to be an admin to lock the group.*");

        await conn.groupSettingUpdate(from, "locked");
        reply("*βœ… Group has been locked. New members cannot join.*");
    } catch (e) {
        console.error("Error locking group:", e);
        reply("❌ Failed to lock the group. Please try again.");
    }
});

cmd({
    pattern: "mute",
    alias: ["groupmute"],
    react: "πŸ”‡",
    desc: "Mute the group (Only admins can send messages).",
    category: "group",
    filename: __filename
},           
async (conn, mek, m, { from, isGroup, senderNumber, isAdmins, isBotAdmins, reply }) => {
    try {
        if (!isGroup) return reply("❌ This command can only be used in groups.");
        if (!isAdmins) return reply("*πŸ“› ᴏɴʟʏ Ι’Κ€α΄α΄œα΄˜ ᴀᴅᴍΙͺΙ΄s α΄„α΄€Ι΄ ᴜsᴇ α΄›ΚœΙͺs ᴄᴏᴍᴍᴀɴᴅ.*");
        if (!isBotAdmins) return reply("*πŸ“› ɴᴇᴇᴅ ᴛᴏ ʙᴇ α΄€Ι΄ ᴀᴅᴍΙͺΙ΄ ᴛᴏ α΄œΙ΄α΄α΄œα΄›α΄‡ α΄›Κœα΄‡ Ι’Κ€α΄α΄œα΄˜*");

        await conn.groupSettingUpdate(from, "announcement");
        reply("*gΚ€Οƒα΄œΟ ΠΌα΄œΡ‚Ρ”βˆ‚ sα΄œα΄„α΄„Ρ”Ρ•Ρ•fα΄œβ„“β„“ΡƒπŸ”*");
    } catch (e) {
        console.error("Error muting group:", e);
        reply("❌ Failed to mute the group. Please try again.");
    }
});

cmd({
    pattern: "unmute",
    alias: ["groupunmute"],
    react: "πŸ”Š",
    desc: "Unmute the group (Everyone can send messages).",
    category: "group",
    filename: __filename
},           
async (conn, mek, m, { from, isGroup, senderNumber, isAdmins, isBotAdmins, reply }) => {
    try {
        if (!isGroup) return reply("❌ This command can only be used in groups.");
        if (!isAdmins) return reply("*πŸ“› ᴏɴʟʏ Ι’Κ€α΄α΄œα΄˜ ᴀᴅᴍΙͺΙ΄s α΄„α΄€Ι΄ ᴜsᴇ α΄›ΚœΙͺs ᴄᴏᴍᴍᴀɴᴅ.*");
        if (!isBotAdmins) return reply("*πŸ“› ɴᴇᴇᴅ ᴛᴏ ʙᴇ α΄€Ι΄ ᴀᴅᴍΙͺΙ΄ ᴛᴏ α΄œΙ΄α΄α΄œα΄›α΄‡ α΄›Κœα΄‡ Ι’Κ€α΄α΄œα΄˜*");

        await conn.groupSettingUpdate(from, "not_announcement");
        reply("*gΚ€Οƒα΄œΟ α΄œΙ΄ΠΌΟ…Ρ‚Ρ”βˆ‚ sα΄œα΄„α΄„Ρ”Ρ•Ρ•fα΄œβ„“β„“ΡƒπŸ”“*");
    } catch (e) {
        console.error("Error unmuting group:", e);
        reply("❌ Failed to unmute the group. Please try again.");
    }
});

cmd({
    pattern: "unlockgc",
    alias: ["unlock"],
    react: "πŸ”“",
    desc: "Unlock the group (Allows new members to join).",
    category: "group",
    filename: __filename
},           
async (conn, mek, m, { from, isGroup, isAdmins, isBotAdmins, reply }) => {
    try {
        if (!isGroup) return reply("❌ This command can only be used in groups.");
        if (!isAdmins) return reply("*πŸ“› Only group admins can use this command.*");
        if (!isBotAdmins) return reply("*πŸ“› I need to be an admin to unlock the group.*");

        await conn.groupSettingUpdate(from, "unlocked");
        reply("βœ… Group has been unlocked. New members can now join.");
    } catch (e) {
        console.error("Error unlocking group:", e);
        reply("❌ Failed to unlock the group. Please try again.");
    }
});