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

Method monitoredHandler

lib/commandHandler.js:89–119  ·  view source on GitHub ↗
(sock, message, ...args)

Source from the content-addressed store, hash-verified

87 avgMs: 0
88 });
89 const monitoredHandler = async (sock, message, ...args) => {
90 const s = this.stats.get(cmdKey);
91 if (this.disabledCommands.has(cmdKey)) {
92 return await sock.sendMessage(message.key.remoteJid, {
93 text: `🚫 The command *${cmdKey}* is currently disabled.`
94 }, { quoted: message });
95 }
96 const userId = message.key.participant || message.key.remoteJid;
97 const now = Date.now();
98 const cooldownKey = `${userId}_${cmdKey}`;
99 if (this.cooldowns.has(cooldownKey)) {
100 const expirationTime = this.cooldowns.get(cooldownKey) + (plugin.cooldown || 3000);
101 if (now < expirationTime)
102 return;
103 }
104 this.cooldowns.set(cooldownKey, now);
105 const start = process.hrtime.bigint();
106 try {
107 s.calls++;
108 return await handler(sock, message, ...args);
109 }
110 catch (err) {
111 s.errors++;
112 throw err;
113 }
114 finally {
115 const end = process.hrtime.bigint();
116 s.totalTime += (end - start);
117 s.avgMs = Number(s.totalTime / BigInt(s.calls || 1)) / 1000000;
118 }
119 };
120 this.commands.set(cmdKey, {
121 ...plugin,
122 command,

Callers

nothing calls this directly

Calls 1

handlerFunction · 0.50

Tested by

no test coverage detected