-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreply.go
More file actions
99 lines (85 loc) · 2.76 KB
/
Copy pathreply.go
File metadata and controls
99 lines (85 loc) · 2.76 KB
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
package strut
import "github.com/disgoorg/disgo/discord"
// Reply is one response, built once and sent through whichever surface the
// command was invoked on.
type Reply struct {
Content string
Embeds []discord.Embed
Components []discord.LayoutComponent
Files []*discord.File
Ephemeral bool
// Reference replies to the invoking message. Prefix commands only.
Reference bool
AllowedMentions *discord.AllowedMentions
// v2 marks a reply using the newer layout components, which Discord
// requires a flag for.
v2 bool
// err collects failures from the builder, surfaced when the reply is sent.
err error
}
// Content returns a Reply carrying text.
func Content(s string) Reply { return Reply{Content: s} }
// Embeds returns a Reply carrying embeds.
func Embeds(e ...discord.Embed) Reply { return Reply{Embeds: e} }
// WithContent sets the text.
func (r Reply) WithContent(s string) Reply { r.Content = s; return r }
// WithEmbeds appends embeds.
func (r Reply) WithEmbeds(e ...discord.Embed) Reply {
r.Embeds = append(r.Embeds, e...)
return r
}
// WithComponents appends component rows.
func (r Reply) WithComponents(c ...discord.LayoutComponent) Reply {
r.Components = append(r.Components, c...)
return r
}
// WithFiles appends attachments.
func (r Reply) WithFiles(f ...*discord.File) Reply {
r.Files = append(r.Files, f...)
return r
}
// AsEphemeral makes the reply visible only to the invoker. Ignored by prefix
// commands, which have no ephemeral messages.
func (r Reply) AsEphemeral() Reply { r.Ephemeral = true; return r }
// AsReply replies to the invoking message. Prefix commands only.
func (r Reply) AsReply() Reply { r.Reference = true; return r }
// WithAllowedMentions overrides the framework default.
func (r Reply) WithAllowedMentions(a *discord.AllowedMentions) Reply {
r.AllowedMentions = a
return r
}
// toCreate converts to an interaction response.
func (r Reply) toCreate() discord.MessageCreate {
m := discord.MessageCreate{
Content: r.Content,
Embeds: r.Embeds,
Components: r.Components,
Files: r.Files,
AllowedMentions: r.AllowedMentions,
}
if r.Ephemeral {
m.Flags = m.Flags.Add(discord.MessageFlagEphemeral)
}
if r.v2 {
// Content and embeds are not allowed alongside layout components.
m.Content, m.Embeds = "", nil
m.Flags = m.Flags.Add(discord.MessageFlagIsComponentsV2)
}
return m
}
// toUpdate converts to a message edit.
func (r Reply) toUpdate() discord.MessageUpdate {
u := discord.MessageUpdate{
Content: &r.Content,
Embeds: &r.Embeds,
Components: &r.Components,
Files: r.Files,
AllowedMentions: r.AllowedMentions,
}
if r.v2 {
u.Content, u.Embeds = nil, nil
flags := discord.MessageFlagIsComponentsV2
u.Flags = &flags
}
return u
}