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

Method monitoredHandler

lib/commandHandler.ts:107–139  ·  view source on GitHub ↗
(sock: any, message: any, ...args: any[])

Source from the content-addressed store, hash-verified

105 });
106
107 const monitoredHandler = async (sock: any, message: any, ...args: any[]) => {
108 const s = this.stats.get(cmdKey);
109
110 if (this.disabledCommands.has(cmdKey)) {
111 return await sock.sendMessage(message.key.remoteJid, {
112 text: `🚫 The command *${cmdKey}* is currently disabled.`
113 }, { quoted: message });
114 }
115
116 const userId = message.key.participant || message.key.remoteJid;
117 const now = Date.now();
118 const cooldownKey = `${userId}_${cmdKey}`;
119
120 if (this.cooldowns.has(cooldownKey)) {
121 const expirationTime = this.cooldowns.get(cooldownKey) + (plugin.cooldown || 3000);
122 if (now < expirationTime) return;
123 }
124
125 this.cooldowns.set(cooldownKey, now);
126 const start = process.hrtime.bigint();
127
128 try {
129 s.calls++;
130 return await handler(sock, message, ...args);
131 } catch(err: any) {
132 s.errors++;
133 throw err;
134 } finally {
135 const end = process.hrtime.bigint();
136 s.totalTime += (end - start);
137 s.avgMs = Number(s.totalTime / BigInt(s.calls || 1)) / 1_000_000;
138 }
139 };
140
141 this.commands.set(cmdKey, {
142 ...plugin,

Callers

nothing calls this directly

Calls 1

handlerFunction · 0.50

Tested by

no test coverage detected