/
embed.go
120 lines (104 loc) · 2.59 KB
/
embed.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package embed
import "time"
// Embed describes some rich content for a Discord message.
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"`
}
// Builder allows to add rich embedded content to Discord messages.
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
}
type builder struct {
title string
description string
url string
timestamp *time.Time
color int
footer *Footer
image *Image
thumbnail *Thumbnail
author *Author
fields []Field
}
func (e *builder) Title(t string) Builder {
e.title = t
return e
}
func (e *builder) Description(d string) Builder {
e.description = d
return e
}
func (e *builder) URL(u string) Builder {
e.url = u
return e
}
func (e *builder) Timestamp(t time.Time) Builder {
e.timestamp = &t
return e
}
func (e *builder) Color(c int) Builder {
e.color = c
return e
}
func (e *builder) Footer(f *Footer) Builder {
e.footer = f
return e
}
func (e *builder) Image(i *Image) Builder {
e.image = i
return e
}
func (e *builder) Thumbnail(t *Thumbnail) Builder {
e.thumbnail = t
return e
}
func (e *builder) Author(a *Author) Builder {
e.author = a
return e
}
func (e *builder) Fields(fields ...*Field) Builder {
for i := 0; i < len(fields); i++ {
e.fields = append(e.fields, *fields[i])
}
return e
}
func (e *builder) Build() *Embed {
return &Embed{
Title: e.title,
Description: e.description,
URL: e.url,
Timestamp: e.timestamp,
Color: e.color,
Footer: e.footer,
Image: e.image,
Thumbnail: e.thumbnail,
Author: e.author,
Fields: e.fields,
}
}
// New returns a builder to create embeds.
func New() Builder {
return &builder{}
}