(sock: any, message: any, args: any, context: BotContext)
| 9 | usage: '.string <text>', |
| 10 | |
| 11 | async handler(sock: any, message: any, args: any, context: BotContext) { |
| 12 | const chatId = context.chatId || message.key.remoteJid; |
| 13 | const textInput = args?.join(' ')?.trim(); |
| 14 | |
| 15 | if (!textInput) { |
| 16 | return await sock.sendMessage(chatId, { text: '*Provide some text to analyze.*\nExample: .string What is AI' }, { quoted: message }); |
| 17 | } |
| 18 | |
| 19 | try { |
| 20 | const apiUrl = `https://discardapi.dpdns.org/api/tools/string?apikey=guru&text=${encodeURIComponent(textInput)}`; |
| 21 | const { data } = await axios.get(apiUrl, { timeout: 10000 }); |
| 22 | |
| 23 | if (!data?.status) { |
| 24 | return await sock.sendMessage(chatId, { text: '❌ Failed to analyze text.' }, { quoted: message }); |
| 25 | } |
| 26 | |
| 27 | const reply = |
| 28 | `📝 *Text Analysis*\n\n` + |
| 29 | `✏️ Text: ${textInput}\n` + |
| 30 | `🔠 Letters: ${data.letters}\n` + |
| 31 | `🔢 Characters (including spaces): ${data.length}\n` + |
| 32 | `📄 Words: ${data.words}\n\n` + |
| 33 | `💡 Tip: Keep your text concise for better readability!`; |
| 34 | |
| 35 | await sock.sendMessage(chatId, { text: reply }, { quoted: message }); |
| 36 | |
| 37 | } catch(error: any) { |
| 38 | console.error('String plugin error:', error); |
| 39 | |
| 40 | if (error.code === 'ECONNABORTED') { |
| 41 | await sock.sendMessage(chatId, { text: '❌ Request timed out. Please try again later.' }, { quoted: message }); |
| 42 | } else { |
| 43 | await sock.sendMessage(chatId, { text: '❌ Failed to fetch text information.' }, { quoted: message }); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected