summaryrefslogtreecommitdiffstats
path: root/bridge/discord
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-12-31 16:59:47 +0100
committerGitHub <noreply@github.com>2020-12-31 16:59:47 +0100
commit19d47784bde7f5d8cfc06f868350ed6ac69c8a21 (patch)
tree74aba773ce82e7db12182c3554d62e9602b84f95 /bridge/discord
parentb89102c5fcb96c5c40ca3d2ed673b6deefe92e64 (diff)
downloadmatterbridge-msglm-19d47784bde7f5d8cfc06f868350ed6ac69c8a21.tar.gz
matterbridge-msglm-19d47784bde7f5d8cfc06f868350ed6ac69c8a21.tar.bz2
matterbridge-msglm-19d47784bde7f5d8cfc06f868350ed6ac69c8a21.zip
Add threading support with token (discord) (#1342)
Webhooks don't support the threading yet, so this is token only. In discord you can reply on each message of a thread, but this is not possible in mattermost (so some changes added there to make sure we always answer on the rootID of the thread). Also needs some more testing with slack. update : It now also uses the token when replying to a thread (even if webhooks are enabled), until webhooks have support for threads.
Diffstat (limited to 'bridge/discord')
-rw-r--r--bridge/discord/discord.go17
-rw-r--r--bridge/discord/handlers.go5
2 files changed, 20 insertions, 2 deletions
diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go
index d63006a7..c8b810c6 100644
--- a/bridge/discord/discord.go
+++ b/bridge/discord/discord.go
@@ -244,7 +244,7 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) {
// Use webhook to send the message
useWebhooks := b.shouldMessageUseWebhooks(&msg)
- if useWebhooks && msg.Event != config.EventMsgDelete {
+ if useWebhooks && msg.Event != config.EventMsgDelete && msg.ParentID == "" {
return b.handleEventWebhook(&msg, channelID)
}
@@ -287,11 +287,24 @@ func (b *Bdiscord) handleEventBotUser(msg *config.Message, channelID string) (st
return msg.ID, err
}
+ m := discordgo.MessageSend{
+ Content: msg.Username + msg.Text,
+ }
+
+ if msg.ParentID != "" && msg.ParentID != "msg-parent-not-found" {
+ m.Reference = &discordgo.MessageReference{
+ MessageID: msg.ParentID,
+ ChannelID: channelID,
+ GuildID: b.guildID,
+ }
+ }
+
// Post normal message
- res, err := b.c.ChannelMessageSend(channelID, msg.Username+msg.Text)
+ res, err := b.c.ChannelMessageSendComplex(channelID, &m)
if err != nil {
return "", err
}
+
return res.ID, nil
}
diff --git a/bridge/discord/handlers.go b/bridge/discord/handlers.go
index 370b8912..d2b38538 100644
--- a/bridge/discord/handlers.go
+++ b/bridge/discord/handlers.go
@@ -127,6 +127,11 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
// Replace emotes
rmsg.Text = replaceEmotes(rmsg.Text)
+ // Add our parent id if it exists
+ if m.MessageReference != nil {
+ rmsg.ParentID = m.MessageReference.MessageID
+ }
+
b.Log.Debugf("<= Sending message from %s on %s to gateway", m.Author.Username, b.Account)
b.Log.Debugf("<= Message is %#v", rmsg)
b.Remote <- rmsg