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

Function complimentCommand

commands/compliment.js:34–89  ·  view source on GitHub ↗
(sock, chatId, message)

Source from the content-addressed store, hash-verified

32];
33
34async function complimentCommand(sock, chatId, message) {
35 try {
36 if (!message || !chatId) {
37 console.log('Invalid message or chatId:', { message, chatId });
38 return;
39 }
40
41 let userToCompliment;
42
43 // Check for mentioned users
44 if (message.message?.extendedTextMessage?.contextInfo?.mentionedJid?.length > 0) {
45 userToCompliment = message.message.extendedTextMessage.contextInfo.mentionedJid[0];
46 }
47 // Check for replied message
48 else if (message.message?.extendedTextMessage?.contextInfo?.participant) {
49 userToCompliment = message.message.extendedTextMessage.contextInfo.participant;
50 }
51
52 if (!userToCompliment) {
53 await sock.sendMessage(chatId, {
54 text: 'Please mention someone or reply to their message to compliment them!'
55 });
56 return;
57 }
58
59 const compliment = compliments[Math.floor(Math.random() * compliments.length)];
60
61 // Add delay to avoid rate limiting
62 await new Promise(resolve => setTimeout(resolve, 1000));
63
64 await sock.sendMessage(chatId, {
65 text: `Hey @${userToCompliment.split('@')[0]}, ${compliment}`,
66 mentions: [userToCompliment]
67 });
68 } catch (error) {
69 console.error('Error in compliment command:', error);
70 if (error.data === 429) {
71 await new Promise(resolve => setTimeout(resolve, 2000));
72 try {
73 await sock.sendMessage(chatId, {
74 text: 'Please try again in a few seconds.'
75 });
76 } catch (retryError) {
77 console.error('Error sending retry message:', retryError);
78 }
79 } else {
80 try {
81 await sock.sendMessage(chatId, {
82 text: 'An error occurred while sending the compliment.'
83 });
84 } catch (sendError) {
85 console.error('Error sending error message:', sendError);
86 }
87 }
88 }
89}
90
91module.exports = { complimentCommand };

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected