From 9b43fcf54b106e7a9d667c0cc395fb052b9f33d8 Mon Sep 17 00:00:00 2001 From: Will Hunt <will@half-shot.uk> Date: Thu, 22 Feb 2018 17:57:53 +0100 Subject: [PATCH] Fix #57, filter out webhook messages from us. (#91) * Fix #57, filter out webhook messages from us. * chan => msg.channel * Cast to <Discord.TextChannel>, silly. * Wrap await * %$&!? whitespace --- src/bot.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/bot.ts b/src/bot.ts index b028601..ed68684 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -524,7 +524,7 @@ export class DiscordBot { }); } - private OnMessage(msg: Discord.Message) { + private async OnMessage(msg: Discord.Message) { const indexOfMsg = this.sentMessages.indexOf(msg.id); if (indexOfMsg !== -1) { log.verbose("DiscordBot", "Got repeated message, ignoring."); @@ -535,6 +535,16 @@ export class DiscordBot { // We don't support double bridging. return; } + // Issue #57: Detect webhooks + if (msg.webhookID != null) { + const webhook = (await (<Discord.TextChannel> msg.channel).fetchWebhooks()) + .filterArray((h) => h.name === "_matrix").pop(); + if (webhook != null && msg.webhookID === webhook.id) { + // Filter out our own webhook messages. + return; + } + } + // Update presence because sometimes discord misses people. this.UpdateUser(msg.author).then(() => { return this.GetRoomIdsFromChannel(msg.channel).catch((err) => { -- GitLab