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