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

Function handler

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

Source from the content-addressed store, hash-verified

6 description: 'Reverse any text',
7 usage: '.reverse <text>',
8 async handler(sock, message, args, context) {
9 const chatId = context.chatId || message.key.remoteJid;
10 const textToReverse = args?.join(' ')?.trim();
11 if (!textToReverse) {
12 return await sock.sendMessage(chatId, { text: 'Please provide text to reverse.\nExample: .reverse Hello World' }, { quoted: message });
13 }
14 try {
15 const apiUrl = `https://discardapi.dpdns.org/api/tools/reverse?apikey=guru&text=${encodeURIComponent(textToReverse)}`;
16 const { data } = await axios.get(apiUrl, { timeout: 10000 });
17 if (!data?.status || !data.result) {
18 return await sock.sendMessage(chatId, { text: '❌ Failed to reverse the text.' }, { quoted: message });
19 }
20 const reply = `*Reversed:* ${data.result}`;
21 await sock.sendMessage(chatId, { text: reply }, { quoted: message });
22 }
23 catch (error) {
24 console.error('Reverse plugin error:', error);
25 if (error.code === 'ECONNABORTED') {
26 await sock.sendMessage(chatId, { text: '❌ Request timed out. Please try again.' }, { quoted: message });
27 }
28 else {
29 await sock.sendMessage(chatId, { text: '❌ Failed to reverse the text.' }, { quoted: message });
30 }
31 }
32 }
33};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected