| 29 | ownerOnly: true, |
| 30 | |
| 31 | async handler(sock: any, message: any, args: any, context: BotContext) { |
| 32 | const { chatId, channelInfo } = context; |
| 33 | |
| 34 | if (!args[0] || !['on', 'off'].includes(args[0])) { |
| 35 | await sock.sendMessage(chatId, { |
| 36 | text: '*Usage:*\n.autoreact on/off', |
| 37 | ...channelInfo |
| 38 | }, { quoted: message }); |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | AUTO_REACT_MESSAGES = args[0] === 'on'; |
| 43 | await store.saveSetting('global', 'autoReaction', { enabled: AUTO_REACT_MESSAGES }); |
| 44 | |
| 45 | await sock.sendMessage(chatId, { |
| 46 | text: AUTO_REACT_MESSAGES ? '*✅ Auto-react enabled*' : '*❌ Auto-react disabled*', |
| 47 | ...channelInfo |
| 48 | }, { quoted: message }); |
| 49 | |
| 50 | if (sock.__autoReactAttached) return; |
| 51 | |
| 52 | sock.ev.on('messages.upsert', async ({ messages }: any) => { |
| 53 | if (!AUTO_REACT_MESSAGES) return; |
| 54 | |
| 55 | for (const m of messages) { |
| 56 | if (!m?.message) continue; |
| 57 | if (m.key.fromMe) continue; |
| 58 | |
| 59 | const text = |
| 60 | m.message.conversation || |
| 61 | m.message.extendedTextMessage?.text || |
| 62 | ''; |
| 63 | |
| 64 | if (!text) continue; |
| 65 | if (/^[!#.$%^&*+=?<>]/.test(text)) continue; |
| 66 | |
| 67 | const now = Date.now(); |
| 68 | if (now - lastReactedTime < 2000) continue; |
| 69 | |
| 70 | await sock.sendMessage(m.key.remoteJid, { |
| 71 | react: { |
| 72 | text: random(autoEmojis), |
| 73 | key: m.key |
| 74 | } |
| 75 | }); |
| 76 | |
| 77 | lastReactedTime = now; |
| 78 | } |
| 79 | }); |
| 80 | |
| 81 | sock.__autoReactAttached = true; |
| 82 | } |
| 83 | }; |