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

Function handler

plugins/string.js:8–37  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected