Skip to content

Commit 3f2c867

Browse files
committed
Remove github embeds for showcase messages
1 parent 1efe02b commit 3f2c867

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/discord/message_handling.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ func HandleIncomingMessage(ctx context.Context, dbConn db.ConnOrTx, msg *Message
9292
return nil
9393
}
9494

95+
var githubRegex = regexp.MustCompile(`^(https:\/\/)?(www\.|gist\.)?github.com`)
96+
9597
func cleanUpShowcase(ctx context.Context, dbConn db.ConnOrTx, msg *Message) (bool, error) {
9698
if msg.ChannelID != config.Config.Discord.ShowcaseChannelID {
9799
return false, nil
@@ -121,6 +123,24 @@ func cleanUpShowcase(ctx context.Context, dbConn db.ConnOrTx, msg *Message) (boo
121123
}
122124

123125
return true, nil
126+
} else {
127+
if len(msg.Embeds) > 0 {
128+
// NOTE(asaf): Remove embeds if all of them are github
129+
allGithub := true
130+
for _, e := range msg.Embeds {
131+
if !(e.Type != nil && *e.Type == "link" && e.Url != nil && githubRegex.Match([]byte(*e.Url))) {
132+
allGithub = false
133+
break
134+
}
135+
}
136+
137+
if !allGithub {
138+
_, err := EditMessage(ctx, msg.ChannelID, msg.ID, `{ "flags": 4 }`) // 4 = SUPPRESS_EMBEDS
139+
if err != nil {
140+
return false, oops.New(err, "Failed to remove embeds from showcase message")
141+
}
142+
}
143+
}
124144
}
125145

126146
return false, nil

0 commit comments

Comments
 (0)