Make embed title and therefore whole embed optional

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2022-12-06 13:22:14 +01:00
parent 0250b5c8e4
commit e376c9205c
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5
3 changed files with 30 additions and 21 deletions

View file

@ -20,6 +20,11 @@ func ptrTime(v time.Time) *time.Time { return &v }
//nolint:gocognit,gocyclo // This function compares two structs and needs the complexity
func isDiscordMessageEmbedEqual(a, b *discordgo.MessageEmbed) bool {
if a == nil || b == nil {
// If one of them is nil, don't do the in-depth analysis
return a == b
}
checks := [][2]interface{}{
// Base-Struct
{a.Type, b.Type},

View file

@ -5,12 +5,13 @@ import (
"strings"
"time"
"github.com/Luzifer/go_helpers/v2/env"
"github.com/Luzifer/go_helpers/v2/str"
"github.com/bwmarrin/discordgo"
"github.com/pkg/errors"
"github.com/robfig/cron/v3"
log "github.com/sirupsen/logrus"
"github.com/Luzifer/go_helpers/v2/env"
"github.com/Luzifer/go_helpers/v2/str"
)
/*
@ -59,25 +60,28 @@ func (m modReactionRole) Setup() error {
// @attr content optional string "" Message content to post above the embed
contentString := m.attrs.MustString("content", ptrStringEmpty)
msgEmbed := &discordgo.MessageEmbed{
// @attr embed_color optional int64 "0x2ECC71" Integer / HEX representation of the color for the embed
Color: int(m.attrs.MustInt64("embed_color", ptrInt64(streamScheduleDefaultColor))),
// @attr embed_description optional string "" Description for the embed block
Description: strings.TrimSpace(m.attrs.MustString("embed_description", ptrStringEmpty)),
Timestamp: time.Now().Format(time.RFC3339),
// @attr embed_title required string "" Title of the embed
Title: m.attrs.MustString("embed_title", nil),
Type: discordgo.EmbedTypeRich,
}
var msgEmbed *discordgo.MessageEmbed
// @attr embed_title optional string "" Title of the embed (embed will not be added when title is missing)
if title := m.attrs.MustString("embed_title", ptrStringEmpty); title != "" {
msgEmbed = &discordgo.MessageEmbed{
// @attr embed_color optional int64 "0x2ECC71" Integer / HEX representation of the color for the embed
Color: int(m.attrs.MustInt64("embed_color", ptrInt64(streamScheduleDefaultColor))),
// @attr embed_description optional string "" Description for the embed block
Description: strings.TrimSpace(m.attrs.MustString("embed_description", ptrStringEmpty)),
Timestamp: time.Now().Format(time.RFC3339),
Title: title,
Type: discordgo.EmbedTypeRich,
}
if m.attrs.MustString("embed_thumbnail_url", ptrStringEmpty) != "" {
msgEmbed.Thumbnail = &discordgo.MessageEmbedThumbnail{
// @attr embed_thumbnail_url optional string "" Publically hosted image URL to use as thumbnail
URL: m.attrs.MustString("embed_thumbnail_url", ptrStringEmpty),
// @attr embed_thumbnail_width optional int64 "" Width of the thumbnail
Width: int(m.attrs.MustInt64("embed_thumbnail_width", ptrInt64Zero)),
// @attr embed_thumbnail_height optional int64 "" Height of the thumbnail
Height: int(m.attrs.MustInt64("embed_thumbnail_height", ptrInt64Zero)),
if m.attrs.MustString("embed_thumbnail_url", ptrStringEmpty) != "" {
msgEmbed.Thumbnail = &discordgo.MessageEmbedThumbnail{
// @attr embed_thumbnail_url optional string "" Publically hosted image URL to use as thumbnail
URL: m.attrs.MustString("embed_thumbnail_url", ptrStringEmpty),
// @attr embed_thumbnail_width optional int64 "" Width of the thumbnail
Width: int(m.attrs.MustInt64("embed_thumbnail_width", ptrInt64Zero)),
// @attr embed_thumbnail_height optional int64 "" Height of the thumbnail
Height: int(m.attrs.MustInt64("embed_thumbnail_height", ptrInt64Zero)),
}
}
}

View file

@ -121,7 +121,6 @@ Creates a post with pre-set reactions and assigns roles on reaction
| Attribute | Req. | Type | Default Value | Description |
| --------- | :--: | ---- | ------------- | ----------- |
| `discord_channel_id` | ✅ | string | | ID of the Discord channel to post the message to |
| `embed_title` | ✅ | string | | Title of the embed |
| `reaction_roles` | ✅ | []string | | List of strings in format `emote=role-id[:set]`. `emote` equals an unicode emote (✅) or a custom emote in form `:<emote-name>:<emote-id>`. `role-id` is the integer ID of the guilds role to add with this emote. If `:set` is added at the end, the role will only be added but not removed when the reaction is removed. |
| `content` | | string | | Message content to post above the embed |
| `embed_color` | | int64 | `0x2ECC71` | Integer / HEX representation of the color for the embed |
@ -129,6 +128,7 @@ Creates a post with pre-set reactions and assigns roles on reaction
| `embed_thumbnail_height` | | int64 | | Height of the thumbnail |
| `embed_thumbnail_url` | | string | | Publically hosted image URL to use as thumbnail |
| `embed_thumbnail_width` | | int64 | | Width of the thumbnail |
| `embed_title` | | string | | Title of the embed (embed will not be added when title is missing) |
## Type: `schedule`