embed

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2018 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package embed contains builders to create Discord rich messages.

Here is an example of how to create a complex embed :

e := embed.New().
	Author(
		embed.NewAuthor().
			Name("author name").
			IconURL("http://example.org/icon.png").
			Build(),
	).
	Title("title").
	Description("description").
	Color(0x3277ce).
	Fields(
		embed.NewField().Name("field 1").Value("value 1").Build(),
		embed.NewField().Name("field 2").Value("value 2").Build(),
	Footer(embed.NewFooter().Text("footer").Build()).
	Build()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Author

type Author struct {
	Name         string `json:"name,omitempty"`
	URL          string `json:"url,omitempty"`
	IconURL      string `json:"icon_url,omitempty"`
	ProxyIconURL string `json:"proxy_icon_url,omitempty"`
}

Author is the embedded author in a Discord message.

type AuthorBuilder

type AuthorBuilder interface {
	Name(n string) AuthorBuilder
	URL(url string) AuthorBuilder
	IconURL(url string) AuthorBuilder
	Build() *Author
}

AuthorBuilder creates authors for messages with rich embedded content.

func NewAuthor

func NewAuthor() AuthorBuilder

NewAuthor returns a builder to create authors.

type Builder

type Builder interface {
	Title(t string) Builder
	Description(t string) Builder
	URL(u string) Builder
	Timestamp(t time.Time) Builder
	Color(c int) Builder
	Footer(f *Footer) Builder
	Image(i *Image) Builder
	Thumbnail(i *Thumbnail) Builder
	Author(i *Author) Builder
	Fields(fields ...*Field) Builder
	Build() *Embed
}

Builder allows to add rich embedded content to Discord messages.

func New

func New() Builder

New returns a builder to create embeds.

type Embed

type Embed struct {
	Title       string     `json:"title,omitempty"`
	Type        string     `json:"type,omitempty"` // Type of embed (always "rich" for webhook embeds).
	Description string     `json:"description,omitempty"`
	URL         string     `json:"url,omitempty"`
	Timestamp   *time.Time `json:"timestamp,omitempty"`
	Color       int        `json:"color,omitempty"`
	Footer      *Footer    `json:"footer,omitempty"`
	Image       *Image     `json:"image,omitempty"`
	Thumbnail   *Thumbnail `json:"thumbnail,omitempty"`
	Video       *Video     `json:"video,omitempty"`
	Provider    *Provider  `json:"provider,omitempty"`
	Author      *Author    `json:"author,omitempty"`
	Fields      []Field    `json:"fields,omitempty"`
}

Embed describes some rich content for a Discord message.

type Field

type Field struct {
	Name   string `json:"name,omitempty"`
	Value  string `json:"value,omitempty"`
	Inline bool   `json:"inline,omitempty"`
}

Field is an embedded field in a Discord message.

type FieldBuilder

type FieldBuilder interface {
	Name(url string) FieldBuilder
	Value(v string) FieldBuilder
	Inline(yes bool) FieldBuilder
	Build() *Field
}

FieldBuilder creates fields for messages with rich embedded content.

func NewField

func NewField() FieldBuilder

NewField returns a builder to create fields.

type Footer struct {
	Text         string `json:"text,omitempty"`
	IconURL      string `json:"icon_url,omitempty"`
	ProxyIconURL string `json:"proxy_icon_url,omitempty"`
}

Footer is a embedded footer in a Discord message.

type FooterBuilder

type FooterBuilder interface {
	Text(t string) FooterBuilder
	Icon(url string) FooterBuilder
	ProxyIcon(url string) FooterBuilder
	Build() *Footer
}

FooterBuilder creates footers for messages with rich embedded content.

func NewFooter

func NewFooter() FooterBuilder

NewFooter returns a builder to create footers.

type Image

type Image struct {
	URL      string `json:"url,omitempty"`       // Source url of image (only supports http(s) and attachments).
	ProxyURL string `json:"proxy_url,omitempty"` // A proxied url of the image.
	Height   int    `json:"height,omitempty"`
	Width    int    `json:"width,omitempty"`
}

Image is an embedded image in a Discord Message.

func NewImage

func NewImage(url string) *Image

NewImage creates an embedded image from its source URL. Supported formats are JPEG, PNG, WebP and GIF.

type Provider

type Provider struct {
	Name string `json:"name,omitempty"`
	URL  string `json:"url,omitempty"`
}

type Thumbnail

type Thumbnail struct {
	URL      string `json:"url,omitempty"`
	ProxyURL string `json:"proxy_url,omitempty"`
	Height   int    `json:"height,omitempty"`
	Width    int    `json:"width,omitempty"`
}

Thumbnail is an embedded thumbnail in a Discord Message.

func NewThumbnail

func NewThumbnail(url string) *Thumbnail

NewThumbnail creates an embedded thumbnail from its source URL. Supported formats are JPEG, PNG, WebP and GIF.

type Video

type Video struct {
	URL    string `json:"url,omitempty"`
	Height int    `json:"height,omitempty"`
	Width  int    `json:"width,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL