mirror of
https://github.com/Luzifer/discord-community.git
synced 2024-12-20 10:21:22 +00:00
Make embed title and therefore whole embed optional
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
0250b5c8e4
commit
e376c9205c
3 changed files with 30 additions and 21 deletions
|
@ -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
|
//nolint:gocognit,gocyclo // This function compares two structs and needs the complexity
|
||||||
func isDiscordMessageEmbedEqual(a, b *discordgo.MessageEmbed) bool {
|
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{}{
|
checks := [][2]interface{}{
|
||||||
// Base-Struct
|
// Base-Struct
|
||||||
{a.Type, b.Type},
|
{a.Type, b.Type},
|
||||||
|
|
|
@ -5,12 +5,13 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Luzifer/go_helpers/v2/env"
|
|
||||||
"github.com/Luzifer/go_helpers/v2/str"
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
log "github.com/sirupsen/logrus"
|
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
|
// @attr content optional string "" Message content to post above the embed
|
||||||
contentString := m.attrs.MustString("content", ptrStringEmpty)
|
contentString := m.attrs.MustString("content", ptrStringEmpty)
|
||||||
|
|
||||||
msgEmbed := &discordgo.MessageEmbed{
|
var msgEmbed *discordgo.MessageEmbed
|
||||||
// @attr embed_color optional int64 "0x2ECC71" Integer / HEX representation of the color for the embed
|
// @attr embed_title optional string "" Title of the embed (embed will not be added when title is missing)
|
||||||
Color: int(m.attrs.MustInt64("embed_color", ptrInt64(streamScheduleDefaultColor))),
|
if title := m.attrs.MustString("embed_title", ptrStringEmpty); title != "" {
|
||||||
// @attr embed_description optional string "" Description for the embed block
|
msgEmbed = &discordgo.MessageEmbed{
|
||||||
Description: strings.TrimSpace(m.attrs.MustString("embed_description", ptrStringEmpty)),
|
// @attr embed_color optional int64 "0x2ECC71" Integer / HEX representation of the color for the embed
|
||||||
Timestamp: time.Now().Format(time.RFC3339),
|
Color: int(m.attrs.MustInt64("embed_color", ptrInt64(streamScheduleDefaultColor))),
|
||||||
// @attr embed_title required string "" Title of the embed
|
// @attr embed_description optional string "" Description for the embed block
|
||||||
Title: m.attrs.MustString("embed_title", nil),
|
Description: strings.TrimSpace(m.attrs.MustString("embed_description", ptrStringEmpty)),
|
||||||
Type: discordgo.EmbedTypeRich,
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
}
|
Title: title,
|
||||||
|
Type: discordgo.EmbedTypeRich,
|
||||||
|
}
|
||||||
|
|
||||||
if m.attrs.MustString("embed_thumbnail_url", ptrStringEmpty) != "" {
|
if m.attrs.MustString("embed_thumbnail_url", ptrStringEmpty) != "" {
|
||||||
msgEmbed.Thumbnail = &discordgo.MessageEmbedThumbnail{
|
msgEmbed.Thumbnail = &discordgo.MessageEmbedThumbnail{
|
||||||
// @attr embed_thumbnail_url optional string "" Publically hosted image URL to use as thumbnail
|
// @attr embed_thumbnail_url optional string "" Publically hosted image URL to use as thumbnail
|
||||||
URL: m.attrs.MustString("embed_thumbnail_url", ptrStringEmpty),
|
URL: m.attrs.MustString("embed_thumbnail_url", ptrStringEmpty),
|
||||||
// @attr embed_thumbnail_width optional int64 "" Width of the thumbnail
|
// @attr embed_thumbnail_width optional int64 "" Width of the thumbnail
|
||||||
Width: int(m.attrs.MustInt64("embed_thumbnail_width", ptrInt64Zero)),
|
Width: int(m.attrs.MustInt64("embed_thumbnail_width", ptrInt64Zero)),
|
||||||
// @attr embed_thumbnail_height optional int64 "" Height of the thumbnail
|
// @attr embed_thumbnail_height optional int64 "" Height of the thumbnail
|
||||||
Height: int(m.attrs.MustInt64("embed_thumbnail_height", ptrInt64Zero)),
|
Height: int(m.attrs.MustInt64("embed_thumbnail_height", ptrInt64Zero)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,6 @@ Creates a post with pre-set reactions and assigns roles on reaction
|
||||||
| Attribute | Req. | Type | Default Value | Description |
|
| Attribute | Req. | Type | Default Value | Description |
|
||||||
| --------- | :--: | ---- | ------------- | ----------- |
|
| --------- | :--: | ---- | ------------- | ----------- |
|
||||||
| `discord_channel_id` | ✅ | string | | ID of the Discord channel to post the message to |
|
| `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. |
|
| `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 |
|
| `content` | | string | | Message content to post above the embed |
|
||||||
| `embed_color` | | int64 | `0x2ECC71` | Integer / HEX representation of the color for 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_height` | | int64 | | Height of the thumbnail |
|
||||||
| `embed_thumbnail_url` | | string | | Publically hosted image URL to use as thumbnail |
|
| `embed_thumbnail_url` | | string | | Publically hosted image URL to use as thumbnail |
|
||||||
| `embed_thumbnail_width` | | int64 | | Width of the 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`
|
## Type: `schedule`
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue