diff --git a/src/bot.ts b/src/bot.ts index fc8b34f44c49b8c9d39540d71db39b8e73654acc..07c33b75cb03647f93cb7d5ebbf6454b5602d415 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -291,6 +291,7 @@ export class DiscordBot { try { MetricPeg.get.registerRequest(msg.id); await this.waitUnlock(msg.channel); + this.clientFactory.bindMetricsToChannel(msg.channel as Discord.TextChannel); this.discordMessageQueue[msg.channel.id] = (async () => { await (this.discordMessageQueue[msg.channel.id] || Promise.resolve()); try { diff --git a/src/clientfactory.ts b/src/clientfactory.ts index 22ded344c65d527239db79d357ea56324f4c08a1..1b2adcfb706231d74d0667c0612962b2208d55c6 100644 --- a/src/clientfactory.ts +++ b/src/clientfactory.ts @@ -110,10 +110,17 @@ export class DiscordClientFactory { } public bindMetricsToChannel(channel: TextChannel) { + // tslint:disable-next-line:no-any + const flexChan = channel as any; + if (flexChan._xmet_send !== undefined) { + return; + } + // Prefix the real functions with _xmet_ + flexChan._xmet_send = channel.send; // tslint:disable-next-line:only-arrow-functions channel.send = function() { MetricPeg.get.remoteCall("channel.send"); - return channel.send.apply(channel, arguments); + return flexChan._xmet_send.apply(channel, arguments); }; } }