diff --git a/src/bot.ts b/src/bot.ts index 7e583f7a8979cf7457ed8e497c4e1f46dc02b4de..102c0ae6cdd6a9b9103eafece64021f7c4514046 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); }; } }