mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-21 21:33:22 +01:00
Use a list of users or roles to mention for Discord notifier (#188)
This commit is contained in:
@@ -9,19 +9,24 @@ Allow to send notifications to your Discord channel.
|
|||||||
notif:
|
notif:
|
||||||
discord:
|
discord:
|
||||||
webhookURL: https://discordapp.com/api/webhooks/1234567890/Abcd-eFgh-iJklmNo_pqr
|
webhookURL: https://discordapp.com/api/webhooks/1234567890/Abcd-eFgh-iJklmNo_pqr
|
||||||
mention: here
|
mentions:
|
||||||
|
- "@here"
|
||||||
|
- "@everyone"
|
||||||
|
- "<@124>"
|
||||||
|
- "<@125>"
|
||||||
|
- "<@&200>"
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! abstract "Environment variables"
|
!!! abstract "Environment variables"
|
||||||
* `DIUN_NOTIF_DISCORD_WEBHOOK`
|
* `DIUN_NOTIF_DISCORD_WEBHOOK`
|
||||||
* `DIUN_NOTIF_DISCORD_MENTION`
|
* `DIUN_NOTIF_DISCORD_MENTIONS`
|
||||||
* `DIUN_NOTIF_DISCORD_TIMEOUT`
|
* `DIUN_NOTIF_DISCORD_TIMEOUT`
|
||||||
|
|
||||||
| Name | Default | Description |
|
| Name | Default | Description |
|
||||||
|--------------------|---------------|---------------|
|
|--------------------|---------------|---------------|
|
||||||
| `webhookURL`[^1] | | Discord [incoming webhook URL](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) |
|
| `webhookURL`[^1] | | Discord [incoming webhook URL](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) |
|
||||||
| `mention` | | Mention to directly notify a user, multiple users or roles in messages (eg. `here`) |
|
| `mentions` | | List of users or roles to notify |
|
||||||
| `timeout` | `10s` | Timeout specifies a time limit for the request to be made |
|
| `timeout` | `10s` | Timeout specifies a time limit for the request to be made |
|
||||||
|
|
||||||
## Sample
|
## Sample
|
||||||
|
|||||||
@@ -62,7 +62,13 @@ func TestLoadFile(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Discord: &model.NotifDiscord{
|
Discord: &model.NotifDiscord{
|
||||||
WebhookURL: "https://discordapp.com/api/webhooks/1234567890/Abcd-eFgh-iJklmNo_pqr",
|
WebhookURL: "https://discordapp.com/api/webhooks/1234567890/Abcd-eFgh-iJklmNo_pqr",
|
||||||
Mention: "here",
|
Mentions: []string{
|
||||||
|
"@here",
|
||||||
|
"@everyone",
|
||||||
|
"<@124>",
|
||||||
|
"<@125>",
|
||||||
|
"<@&200>",
|
||||||
|
},
|
||||||
Timeout: utl.NewDuration(10 * time.Second),
|
Timeout: utl.NewDuration(10 * time.Second),
|
||||||
},
|
},
|
||||||
Gotify: &model.NotifGotify{
|
Gotify: &model.NotifGotify{
|
||||||
|
|||||||
@@ -15,7 +15,12 @@ notif:
|
|||||||
queue: queue
|
queue: queue
|
||||||
discord:
|
discord:
|
||||||
webhookURL: https://discordapp.com/api/webhooks/1234567890/Abcd-eFgh-iJklmNo_pqr
|
webhookURL: https://discordapp.com/api/webhooks/1234567890/Abcd-eFgh-iJklmNo_pqr
|
||||||
mention: here
|
mentions:
|
||||||
|
- "@here"
|
||||||
|
- "@everyone"
|
||||||
|
- "<@124>"
|
||||||
|
- "<@125>"
|
||||||
|
- "<@&200>"
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
gotify:
|
gotify:
|
||||||
endpoint: http://gotify.foo.com
|
endpoint: http://gotify.foo.com
|
||||||
|
|||||||
@@ -15,7 +15,12 @@ notif:
|
|||||||
queue: queue
|
queue: queue
|
||||||
discord:
|
discord:
|
||||||
webhookURL: https://discordapp.com/api/webhooks/1234567890/Abcd-eFgh-iJklmNo_pqr
|
webhookURL: https://discordapp.com/api/webhooks/1234567890/Abcd-eFgh-iJklmNo_pqr
|
||||||
mention: here
|
mentions:
|
||||||
|
- "@here"
|
||||||
|
- "@everyone"
|
||||||
|
- "<@124>"
|
||||||
|
- "<@125>"
|
||||||
|
- "<@&200>"
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
gotify:
|
gotify:
|
||||||
endpoint: http://gotify.foo.com
|
endpoint: http://gotify.foo.com
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
// NotifDiscord holds Discord notification configuration details
|
// NotifDiscord holds Discord notification configuration details
|
||||||
type NotifDiscord struct {
|
type NotifDiscord struct {
|
||||||
WebhookURL string `yaml:"webhookURL,omitempty" json:"webhookURL,omitempty" validate:"required"`
|
WebhookURL string `yaml:"webhookURL,omitempty" json:"webhookURL,omitempty" validate:"required"`
|
||||||
Mention string `yaml:"mention,omitempty" json:"mention,omitempty"`
|
Mentions []string `yaml:"mentions,omitempty" json:"mentions,omitempty"`
|
||||||
Timeout *time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" validate:"required"`
|
Timeout *time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,8 +44,10 @@ func (c *Client) Send(entry model.NotifEntry) error {
|
|||||||
Timeout: *c.cfg.Timeout,
|
Timeout: *c.cfg.Timeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c.cfg.Mention) > 0 {
|
if len(c.cfg.Mentions) > 0 {
|
||||||
content.WriteString(fmt.Sprintf("@%s ", c.cfg.Mention))
|
for _, mention := range c.cfg.Mentions {
|
||||||
|
content.WriteString(fmt.Sprintf("%s ", mention))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if entry.Status == model.ImageStatusNew {
|
if entry.Status == model.ImageStatusNew {
|
||||||
content.WriteString(fmt.Sprintf("New image %s has been added", entry.Image.String()))
|
content.WriteString(fmt.Sprintf("New image %s has been added", entry.Image.String()))
|
||||||
|
|||||||
Reference in New Issue
Block a user