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

Function handler

plugins/calc.js:47–79  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

45 description: 'Advanced calculator',
46 usage: '.calc <expression>',
47 async handler(sock, message, args, context) {
48 const { chatId, channelInfo } = context;
49 const expr = args.join(' ').trim();
50 if (!expr) {
51 return await sock.sendMessage(chatId, {
52 text: `🧮 *CALCULATOR*\n\n` +
53 `*Usage:* \`.calc <expression>\`\n\n` +
54 `*Examples:*\n` +
55 `• \`.calc 2 ** 10\` → 1024\n` +
56 `• \`.calc sqrt(144)\` → 12\n` +
57 `• \`.calc sin(pi / 2)\` → 1\n` +
58 `• \`.calc log(1000)\` → 3\n` +
59 `• \`.calc (3 + 4) * 2\` → 14\n` +
60 `• \`.calc pow(2, 8)\` → 256\n\n` +
61 `*Functions:* sqrt, cbrt, abs, sin, cos, tan, log, ln, floor, ceil, round, pow, min, max\n` +
62 `*Constants:* pi, e`,
63 ...channelInfo
64 }, { quoted: message });
65 }
66 try {
67 const result = safeMath(expr);
68 await sock.sendMessage(chatId, {
69 text: `🧮 *Calculator*\n\n📥 *Input:* \`${expr}\`\n📤 *Result:* \`${result}\``,
70 ...channelInfo
71 }, { quoted: message });
72 }
73 catch (error) {
74 await sock.sendMessage(chatId, {
75 text: `❌ *Error:* ${error.message}`,
76 ...channelInfo
77 }, { quoted: message });
78 }
79 }
80};

Callers

nothing calls this directly

Calls 1

safeMathFunction · 0.85

Tested by

no test coverage detected