-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinteraction-response-builder.go
139 lines (114 loc) · 3.09 KB
/
interaction-response-builder.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package corde
import (
"fmt"
"io"
)
// RespB is an InteractionRespData builder
type RespB struct {
resp *InteractionRespData
}
// NewResp Returns a new response builder
func NewResp() *RespB {
return &RespB{resp: &InteractionRespData{}}
}
// Embedder returns an Embed
type Embedder interface {
Embed() Embed
}
// InteractionRespData implements InteractionResponder
func (r *RespB) InteractionRespData() *InteractionRespData { return r.resp }
// Content adds the content to the InteractionRespData
func (r *RespB) Content(s string) *RespB {
r.resp.Content = s
return r
}
// Contentf adds the content to the InteractionRespData
func (r *RespB) Contentf(s string, args ...any) *RespB {
r.resp.Content = fmt.Sprintf(s, args...)
return r
}
// TTS adds the tts to the InteractionRespData
func (r *RespB) TTS(tts bool) *RespB {
r.resp.TTS = tts
return r
}
// Embeds adds embeds to the InteractionRespData
func (r *RespB) Embeds(e ...Embedder) *RespB {
for _, eb := range e {
r.resp.Embeds = append(r.resp.Embeds, eb.Embed())
}
return r
}
// AllowedMentions adds the allowed mentions to the InteractionRespData
func (r *RespB) AllowedMentions(a *AllowedMentions) *RespB {
r.resp.AllowedMentions = a
return r
}
// Flags adds the flags to the InteractionRespData
func (r *RespB) Flags(i IntResponseFlags) *RespB {
r.resp.Flags = i
return r
}
// Ephemeral adds the ephemeral flag to the InteractionRespData
func (r *RespB) Ephemeral() *RespB {
r.resp.Flags = RESPONSE_FLAGS_EPHEMERAL
return r
}
// Components adds components to the InteractionRespData
func (b *RespB) Components(c ...Component) *RespB {
if b.resp.Components == nil {
b.resp.Components = []Component{}
}
b.resp.Components = append(b.resp.Components, c...)
return b
}
// ActionRow adds an action row to the InteractionRespData
func (b *RespB) ActionRow(c ...Component) *RespB {
if b.resp.Components == nil {
b.resp.Components = []Component{}
}
b.resp.Components = append(b.resp.Components,
Component{
Type: COMPONENT_ACTION_ROW,
Components: c,
})
return b
}
// Attachments adds attachments to the InteractionRespData
func (b *RespB) Attachments(a ...Attachment) *RespB {
if b.resp.Attachments == nil {
b.resp.Attachments = []Attachment{}
}
b.resp.Attachments = append(b.resp.Attachments, a...)
return b
}
// Attachement adds an attachment to the InteractionRespData
func (b *RespB) Attachment(body io.Reader, filename string) *RespB {
if b.resp.Attachments == nil {
b.resp.Attachments = []Attachment{}
}
b.resp.Attachments = append(b.resp.Attachments, Attachment{
Body: body,
Filename: filename,
})
return b
}
// Choice adds a choice to the InteractionRespData
func (b *RespB) Choice(name string, value any) *RespB {
if b.resp.Choices == nil {
b.resp.Choices = []Choice[any]{}
}
b.resp.Choices = append(b.resp.Choices, Choice[any]{
Name: name,
Value: value,
})
return b
}
// Choices adds choices to the InteractionRespData
func (b *RespB) Choices(c ...Choice[any]) *RespB {
if b.resp.Choices == nil {
b.resp.Choices = []Choice[any]{}
}
b.resp.Choices = append(b.resp.Choices, c...)
return b
}