Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/notif/discord.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ Allow sending notifications to your Discord channel.
```

| Name | Default | Description |
|--------------------|------------------------------------|-----------------------------------------------------------------------------------------------------------|
| ------------------ | ---------------------------------- | --------------------------------------------------------------------------------------------------------- |
| `webhookURL` | | Discord [incoming webhook URL](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) |
| `webhookURLFile` | | Use content of secret file as webhook URL if `webhookURL` is not defined |
| `mentions` | | List of users or roles to notify |
| `renderFields` | `true` | Render [field objects](https://discordjs.guide/popular-topics/embeds.html) |
| `renderFields` | `true` | Render embed and [field objects](https://discordjs.guide/popular-topics/embeds.html) |
| `timeout` | `10s` | Timeout specifies a time limit for the request to be made |
| `templateBody`[^1] | See [below](#default-templatebody) | [Notification template](../faq.md#notification-template) for message body |

Expand Down
23 changes: 12 additions & 11 deletions internal/notif/discord/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ func (c *Client) Send(entry model.NotifEntry) error {
}
content.WriteString(string(body))

var fields []EmbedField
var embeds []Embed
if *c.cfg.RenderFields {
fields = []EmbedField{
fields := []EmbedField{
{
Name: "Hostname",
Value: c.meta.Hostname,
Expand Down Expand Up @@ -99,14 +99,7 @@ func (c *Client) Send(entry model.NotifEntry) error {
Value: entry.Image.HubLink,
})
}
}

dataBuf := new(bytes.Buffer)
if err := json.NewEncoder(dataBuf).Encode(Message{
Content: content.String(),
Username: c.meta.Name,
AvatarURL: c.meta.Logo,
Embeds: []Embed{
embeds = []Embed{
{
Author: EmbedAuthor{
Name: c.meta.Name,
Expand All @@ -118,7 +111,15 @@ func (c *Client) Send(entry model.NotifEntry) error {
Text: fmt.Sprintf("%s © %d %s %s", c.meta.Author, time.Now().Year(), c.meta.Name, c.meta.Version),
},
},
},
}
}

dataBuf := new(bytes.Buffer)
if err := json.NewEncoder(dataBuf).Encode(Message{
Content: content.String(),
Username: c.meta.Name,
AvatarURL: c.meta.Logo,
Embeds: embeds,
}); err != nil {
return err
}
Expand Down