MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / handler

Function handler

plugins/poll.js:9–47  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

7 groupOnly: true,
8 adminOnly: true,
9 async handler(sock, message, args, context) {
10 const chatId = context.chatId || message.key.remoteJid;
11 const channelInfo = context.channelInfo || {};
12 const fullText = args.join(' ');
13 const parts = fullText.split('|').map((p) => p.trim()).filter(Boolean);
14 if (parts.length < 3) {
15 return await sock.sendMessage(chatId, {
16 text: `*📊 CREATE A POLL*\n\n` +
17 `*Usage:*\n\`.poll <Question> | <Option1> | <Option2> | ...\`\n\n` +
18 `*Example:*\n\`.poll Favourite color? | Red | Blue | Green | Yellow\`\n\n` +
19 `_Minimum 2 options. Maximum 12 options._`,
20 ...channelInfo
21 }, { quoted: message });
22 }
23 const question = parts[0];
24 const options = parts.slice(1);
25 if (options.length > 12) {
26 return await sock.sendMessage(chatId, {
27 text: '❌ Maximum 12 options allowed.',
28 ...channelInfo
29 }, { quoted: message });
30 }
31 try {
32 await sock.sendMessage(chatId, {
33 poll: {
34 name: question,
35 values: options,
36 selectableCount: 1
37 }
38 });
39 }
40 catch (e) {
41 console.error('[POLL] Error sending poll:', e.message);
42 await sock.sendMessage(chatId, {
43 text: '❌ Failed to create poll. Please try again.',
44 ...channelInfo
45 }, { quoted: message });
46 }
47 }
48};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected