Skip to content

Commit

Permalink
refactor: Move mentions to footnote
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-roesch committed Aug 27, 2024
1 parent b89344e commit b15addb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions common/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const maxRetries = 3
type DiscordClient struct {
webhookUrl string
mentions DiscordMentions
mentionPrefix string
mentionSuffix string
info *log.Logger
error *log.Logger
}
Expand All @@ -31,20 +31,24 @@ type DiscordMentions struct {
func CreateDiscordClient(webhook string, mentions DiscordMentions) DiscordClient {
infoLog, errorLog := CreateLoggers("main")

mentionPrefix := ""
mentionSuffix := ""
for _, role := range mentions.Roles {
mentionPrefix += fmt.Sprintf("<@&%s> ", role)
mentionSuffix += fmt.Sprintf("<@&%s> ", role)
}
for _, user := range mentions.Users {
mentionPrefix += fmt.Sprintf("<@%s> ", user)
mentionSuffix += fmt.Sprintf("<@%s> ", user)
}

if mentionSuffix != "" {
mentionSuffix = fmt.Sprintf("\n-# %s", mentionSuffix)
}

mentions.Parse = make([]string, 0)

return DiscordClient{
webhookUrl: fmt.Sprintf("%s/%s", webhookBaseUrl, webhook),
mentions: mentions,
mentionPrefix: mentionPrefix,
mentionSuffix: mentionSuffix,
info: infoLog,
error: errorLog,
}
Expand All @@ -58,7 +62,7 @@ func (discord *DiscordClient) trySend(text, name, avatar string, embed interface
body := map[string]interface{}{
"username": name,
"avatar_url": fmt.Sprintf("%s/%s.png", avatarBaseUrl, avatar),
"content": fmt.Sprintf("%s%s", discord.mentionPrefix, text),
"content": fmt.Sprintf("%s%s", text, discord.mentionSuffix),
"allowed_mentions": discord.mentions,
}

Expand Down

0 comments on commit b15addb

Please sign in to comment.