summaryrefslogtreecommitdiffstats
path: root/bridge/discord/handlers.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-03-21 21:27:17 +0100
committerGitHub <noreply@github.com>2020-03-21 21:27:17 +0100
commit281016a5014146387e38d268aa271d539fd562e8 (patch)
treeead89e88d5d22f24eab80bd6192570cb66b2b824 /bridge/discord/handlers.go
parentd4acdf2f896f46e78916ba34b3cb942e6b677d7b (diff)
downloadmatterbridge-msglm-281016a5014146387e38d268aa271d539fd562e8.tar.gz
matterbridge-msglm-281016a5014146387e38d268aa271d539fd562e8.tar.bz2
matterbridge-msglm-281016a5014146387e38d268aa271d539fd562e8.zip
Fix duplicate separator on empty description/url (discord). Fixes #1008 (#1035)
Make this work for all possible cases. Add tests
Diffstat (limited to 'bridge/discord/handlers.go')
-rw-r--r--bridge/discord/handlers.go32
1 files changed, 31 insertions, 1 deletions
diff --git a/bridge/discord/handlers.go b/bridge/discord/handlers.go
index 2313390e..1ce402c5 100644
--- a/bridge/discord/handlers.go
+++ b/bridge/discord/handlers.go
@@ -103,7 +103,7 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
// if we have embedded content add it to text
if b.GetBool("ShowEmbeds") && m.Message.Embeds != nil {
for _, embed := range m.Message.Embeds {
- rmsg.Text = rmsg.Text + "embed: " + embed.Title + " - " + embed.Description + " - " + embed.URL + "\n"
+ rmsg.Text += handleEmbed(embed)
}
}
@@ -192,3 +192,33 @@ func (b *Bdiscord) memberRemove(s *discordgo.Session, m *discordgo.GuildMemberRe
b.Log.Debugf("<= Message is %#v", rmsg)
b.Remote <- rmsg
}
+
+func handleEmbed(embed *discordgo.MessageEmbed) string {
+ var t []string
+ var result string
+
+ t = append(t, embed.Title)
+ t = append(t, embed.Description)
+ t = append(t, embed.URL)
+
+ i := 0
+ for _, e := range t {
+ if e == "" {
+ continue
+ }
+
+ i++
+ if i == 1 {
+ result += "embed: " + e
+ continue
+ }
+
+ result += " - " + e
+ }
+
+ if result != "" {
+ result += "\n"
+ }
+
+ return result
+}