From f7ec4999f121cc54977fca251109d3d7d9a80ed4 Mon Sep 17 00:00:00 2001 From: itasli Date: Fri, 14 Oct 2022 12:03:57 +0200 Subject: [PATCH 1/2] add SetFooterIconf, SetImagef, SetThumbnailf and SetURLf --- discord/embed_builder.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/discord/embed_builder.go b/discord/embed_builder.go index 515179ad..fff7ea4d 100644 --- a/discord/embed_builder.go +++ b/discord/embed_builder.go @@ -122,6 +122,15 @@ func (b *EmbedBuilder) SetFooterIcon(iconURL string) *EmbedBuilder { return b } +// SetFooterIconf sets the footer icon of the EmbedBuilder +func (b *EmbedBuilder) SetFooterIconf(iconURL string, a ...any) *EmbedBuilder { + if b.Footer == nil { + b.Footer = &EmbedFooter{} + } + b.Footer.IconURL = fmt.Sprintf(iconURL, a...) + return b +} + // SetImage sets the image of the EmbedBuilder func (b *EmbedBuilder) SetImage(url string) *EmbedBuilder { if b.Image == nil { @@ -131,6 +140,15 @@ func (b *EmbedBuilder) SetImage(url string) *EmbedBuilder { return b } +// SetImagef sets the image of the EmbedBuilder with format +func (b *EmbedBuilder) SetImagef(url string, a ...any) *EmbedBuilder { + if b.Image == nil { + b.Image = &EmbedResource{} + } + b.Image.URL = fmt.Sprintf(url, a...) + return b +} + // SetThumbnail sets the thumbnail of the EmbedBuilder func (b *EmbedBuilder) SetThumbnail(url string) *EmbedBuilder { if b.Thumbnail == nil { @@ -140,12 +158,27 @@ func (b *EmbedBuilder) SetThumbnail(url string) *EmbedBuilder { return b } +// SetThumbnailf sets the thumbnail of the EmbedBuilder with format +func (b *EmbedBuilder) SetThumbnailf(url string, a ...any) *EmbedBuilder { + if b.Thumbnail == nil { + b.Thumbnail = &EmbedResource{} + } + b.Thumbnail.URL = fmt.Sprintf(url, a...) + return b +} + // SetURL sets the URL of the EmbedBuilder func (b *EmbedBuilder) SetURL(url string) *EmbedBuilder { b.URL = url return b } +// SetURLf sets the URL of the EmbedBuilder with format +func (b *EmbedBuilder) SetURLf(url string, a ...any) *EmbedBuilder { + b.URL = fmt.Sprintf(url, a...) + return b +} + // SetTimestamp sets the timestamp of the EmbedBuilder func (b *EmbedBuilder) SetTimestamp(time time.Time) *EmbedBuilder { b.Timestamp = &time From a771f50044db8e566d0e9682c1ef3e9b14164341 Mon Sep 17 00:00:00 2001 From: itasli Date: Fri, 14 Oct 2022 18:45:16 +0200 Subject: [PATCH 2/2] Update embed_builder.go --- discord/embed_builder.go | 44 +++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/discord/embed_builder.go b/discord/embed_builder.go index fff7ea4d..53f2b16a 100644 --- a/discord/embed_builder.go +++ b/discord/embed_builder.go @@ -34,8 +34,7 @@ func (b *EmbedBuilder) SetDescription(description string) *EmbedBuilder { // SetDescriptionf sets the description of the EmbedBuilder with format func (b *EmbedBuilder) SetDescriptionf(description string, a ...any) *EmbedBuilder { - b.Description = fmt.Sprintf(description, a...) - return b + return b.SetDescription(fmt.Sprintf(description, a...)) } // SetEmbedAuthor sets the author of the EmbedBuilder using an EmbedAuthor struct @@ -64,6 +63,11 @@ func (b *EmbedBuilder) SetAuthorName(name string) *EmbedBuilder { return b } +// SetAuthorNamef sets the author name of the EmbedBuilder with format +func (b *EmbedBuilder) SetAuthorNamef(name string, a ...any) *EmbedBuilder { + return b.SetAuthorName(fmt.Sprintf(name, a...)) +} + // SetAuthorURL sets the author URL of the EmbedBuilder func (b *EmbedBuilder) SetAuthorURL(url string) *EmbedBuilder { if b.Author == nil { @@ -73,6 +77,11 @@ func (b *EmbedBuilder) SetAuthorURL(url string) *EmbedBuilder { return b } +// SetAuthorURLf sets the author URL of the EmbedBuilder with format +func (b *EmbedBuilder) SetAuthorURLf(url string, a ...any) *EmbedBuilder { + return b.SetAuthorURL(fmt.Sprintf(url, a...)) +} + // SetAuthorIcon sets the author icon of the EmbedBuilder func (b *EmbedBuilder) SetAuthorIcon(iconURL string) *EmbedBuilder { if b.Author == nil { @@ -82,6 +91,11 @@ func (b *EmbedBuilder) SetAuthorIcon(iconURL string) *EmbedBuilder { return b } +// SetAuthorIconf sets the author icon of the EmbedBuilder with format +func (b *EmbedBuilder) SetAuthorIconf(iconURL string, a ...any) *EmbedBuilder { + return b.SetAuthorIcon(fmt.Sprintf(iconURL, a...)) +} + // SetColor sets the color of the EmbedBuilder func (b *EmbedBuilder) SetColor(color int) *EmbedBuilder { b.Color = color @@ -113,6 +127,11 @@ func (b *EmbedBuilder) SetFooterText(text string) *EmbedBuilder { return b } +// SetFooterText sets the footer text of the EmbedBuilder with format +func (b *EmbedBuilder) SetFooterTextf(text string, a ...any) *EmbedBuilder { + return b.SetFooterText(fmt.Sprintf(text, a...)) +} + // SetFooterIcon sets the footer icon of the EmbedBuilder func (b *EmbedBuilder) SetFooterIcon(iconURL string) *EmbedBuilder { if b.Footer == nil { @@ -124,11 +143,7 @@ func (b *EmbedBuilder) SetFooterIcon(iconURL string) *EmbedBuilder { // SetFooterIconf sets the footer icon of the EmbedBuilder func (b *EmbedBuilder) SetFooterIconf(iconURL string, a ...any) *EmbedBuilder { - if b.Footer == nil { - b.Footer = &EmbedFooter{} - } - b.Footer.IconURL = fmt.Sprintf(iconURL, a...) - return b + return b.SetFooterIcon(fmt.Sprintf(iconURL, a...)) } // SetImage sets the image of the EmbedBuilder @@ -142,11 +157,7 @@ func (b *EmbedBuilder) SetImage(url string) *EmbedBuilder { // SetImagef sets the image of the EmbedBuilder with format func (b *EmbedBuilder) SetImagef(url string, a ...any) *EmbedBuilder { - if b.Image == nil { - b.Image = &EmbedResource{} - } - b.Image.URL = fmt.Sprintf(url, a...) - return b + return b.SetImage(fmt.Sprintf(url, a...)) } // SetThumbnail sets the thumbnail of the EmbedBuilder @@ -160,11 +171,7 @@ func (b *EmbedBuilder) SetThumbnail(url string) *EmbedBuilder { // SetThumbnailf sets the thumbnail of the EmbedBuilder with format func (b *EmbedBuilder) SetThumbnailf(url string, a ...any) *EmbedBuilder { - if b.Thumbnail == nil { - b.Thumbnail = &EmbedResource{} - } - b.Thumbnail.URL = fmt.Sprintf(url, a...) - return b + return b.SetThumbnail(fmt.Sprintf(url, a...)) } // SetURL sets the URL of the EmbedBuilder @@ -175,8 +182,7 @@ func (b *EmbedBuilder) SetURL(url string) *EmbedBuilder { // SetURLf sets the URL of the EmbedBuilder with format func (b *EmbedBuilder) SetURLf(url string, a ...any) *EmbedBuilder { - b.URL = fmt.Sprintf(url, a...) - return b + return b.SetURL(fmt.Sprintf(url, a...)) } // SetTimestamp sets the timestamp of the EmbedBuilder