MCPcopy Create free account
hub / github.com/Xchristech2/Zenitsu-Bot / shipCommand

Function shipCommand

commands/ship.js:1–31  ·  view source on GitHub ↗
(sock, chatId, msg, groupMetadata)

Source from the content-addressed store, hash-verified

1async function shipCommand(sock, chatId, msg, groupMetadata) {
2 try {
3 // Get all participants from the group
4 const participants = await sock.groupMetadata(chatId);
5 const ps = participants.participants.map(v => v.id);
6
7 // Get two random participants
8 let firstUser, secondUser;
9
10 // Select first random user
11 firstUser = ps[Math.floor(Math.random() * ps.length)];
12
13 // Select second random user (different from first)
14 do {
15 secondUser = ps[Math.floor(Math.random() * ps.length)];
16 } while (secondUser === firstUser);
17
18 // Format the mentions
19 const formatMention = id => '@' + id.split('@')[0];
20
21 // Create and send the ship message
22 await sock.sendMessage(chatId, {
23 text: `${formatMention(firstUser)} ❤️ ${formatMention(secondUser)}\nCongratulations 💖🍻`,
24 mentions: [firstUser, secondUser]
25 });
26
27 } catch (error) {
28 console.error('Error in ship command:', error);
29 await sock.sendMessage(chatId, { text: '❌ Failed to ship! Make sure this is a group.' });
30 }
31}
32
33module.exports = shipCommand;

Callers

nothing calls this directly

Calls 1

formatMentionFunction · 0.85

Tested by

no test coverage detected