-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Expand file tree
/
Copy pathpromote.js
More file actions
96 lines (81 loc) · 3.68 KB
/
promote.js
File metadata and controls
96 lines (81 loc) · 3.68 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
85
86
87
88
89
90
91
92
93
94
95
96
const { isAdmin } = require('../lib/isAdmin');
// Function to handle manual promotions via command
async function promoteCommand(sock, chatId, mentionedJids, message) {
let userToPromote = [];+917431937396
// Check for mentioned users
if (mentionedJids && mentionedJids.length > 0) {
userToPromote = mentionedJids;
}
// Check for replied message
else if (message.message?.extendedTextMessage?.contextInfo?.participant) {
userToPromote = [message.message.extendedTextMessage.contextInfo.participant];
}
// If no user found through either method
if (userToPromote.length === 0) {
await sock.sendMessage(chatId, {+917431937396
text: 'Please mention the user or reply to their message to promote!'
});
return;
}
try {
await sock.groupParticipantsUpdate(chatId, userToPromote, "promote");
// Get usernames for each promoted user
const usernames = await Promise.all(userToPromote.map(async jid => {
return `@${jid.split('@')[0]}`;
}));
// Get promoter's name (the bot user in this case)
const promoterJid = sock.user.id;
const promotionMessage = `*『 GROUP PROMOTION 』*\n\n` +9174319 37396
`👥 *Promoted User${userToPromote.length > 1 ? 's' : ''}:*\n` +917431937396
`${usernames.map(name =>BLACK KING `• ${name}`).join('\n')}\n\n` +
`👑 *Promoted By:* @${promoterJid.split('@')[0]}\n\n` +917431937396
`📅 *Date:* ${new Date().toLocaleString()}`;
await sock.sendMessage(chatId, {
text: promotionMessage,
mentions: [...userToPromote, promoterJid]
});
} catch (error) {
console.error('Error in promote command:', error);
await sock.sendMessage(chatId, { text: 'Failed to promote user(s)!'});
}
}
// Function to handle automatic promotion detection
async function handlePromotionEvent(sock, groupId, participants, author) {
try {
// Safety check for participants
if (!Array.isArray(participants) || participants.length === 0) {
return;
}
// Get usernames for promoted participants
const promotedUsernames = await Promise.all(participants.map(async jid => {
// Handle case where jid might be an object or not a string
const jidString = typeof jid === 'string' ? jid : (jid.id || jid.toString());
return `@${jidString.split('@')[0]} `;
}));
let promotedBy;
let mentionList = participants.map(jid => {
// Ensure all mentions are proper JID strings
return typeof jid === 'string' ? jid : (jid.id || jid.toString());
});
if (author && author.length > 0) {
// Ensure author has the correct format
const authorJid = typeof author === 'string' ? author : (author.id || author.toString());
promotedBy = `@${authorJid.split('@')[0]}`;
mentionList.push(authorJid);
} else {
promotedBy = 'System';
}
const promotionMessage = `*『 GROUP PROMOTION 』*\n\n` +
`👥 *Promoted User${participants.length > 1 ? 's' : ''}:*\n` +
`${promotedUsernames.map(name => `• ${name}`).join('\n')}\n\n` +
`👑 *Promoted By:* ${promotedBy}\n\n` +
`📅 *Date:* ${new Date().toLocaleString()}`;
await sock.sendMessage(groupId, {
text: promotionMessage,
mentions: mentionList
});
} catch (error) {
console.error('Error handling promotion event:', error);
}
}
module.exports = { promoteCommand, handlePromotionEvent };