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

Function handler

plugins/reverse.ts:11–40  ·  view source on GitHub ↗
(sock: any, message: any, args: any, context: BotContext)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected