From 8c87b9463d591f118bb76a2f2ec4f6eb9e27309e Mon Sep 17 00:00:00 2001 From: James Nylen Date: Mon, 7 Jan 2019 14:26:21 -0500 Subject: [PATCH] Discord: Only require one webhook Fixes #674. --- bridge/discord/discord.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index 16ce8c05..a9c508c7 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -152,7 +152,8 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) { msg.Text = "_" + msg.Text + "_" } - // use initial webhook + // use initial webhook configured for the entire Discord account + isGlobalWebhook := true wID := b.webhookID wToken := b.webhookToken @@ -161,6 +162,7 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) { if ci, ok := b.channelInfoMap[msg.Channel+b.Account]; ok { if ci.Options.WebhookURL != "" { wID, wToken = b.splitURL(ci.Options.WebhookURL) + isGlobalWebhook = false } } b.channelsMutex.RUnlock() @@ -189,6 +191,18 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) { if len(msg.Username) > 32 { msg.Username = msg.Username[0:32] } + // if we have a global webhook for this Discord account, use it, but + // first set its channel to the message channel + // TODO: this isn't necessary if the last message from this webhook was + // sent to the current channel + if isGlobalWebhook { + b.Log.Debugf("Setting webhook channel to \"%s\"", msg.Channel) + _, err := b.c.WebhookEdit(wID, "", "", channelID) + if err != nil { + b.Log.Errorf("Could not set webhook channel: %v", err) + return "", err + } + } err := b.c.WebhookExecute( wID, wToken,