/
message_helpers.go
136 lines (109 loc) · 2.81 KB
/
message_helpers.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
package bot
import (
"context"
"fmt"
"io"
"path"
"github.com/diamondburned/arikawa/v3/api"
"github.com/diamondburned/arikawa/v3/discord"
"github.com/diamondburned/arikawa/v3/utils/json/option"
"github.com/diamondburned/arikawa/v3/utils/sendpart"
)
func (b *Bot) reply(m discord.Message, content string) error {
if content == "" {
panic("bot: blank content given to Reply")
}
_, err := b.state.SendMessageReply(m.ChannelID, content, m.ID)
return err
}
func (b *Bot) sendImage(ctx context.Context, chID discord.ChannelID, content string, image string) error {
cachedImage, err := b.imageCache.Get(ctx, image)
if err != nil {
return err
}
rawName := path.Base(image)
files := make([]sendpart.File, 0)
files = append(files, sendpart.File{
Name: rawName,
Reader: cachedImage,
})
_, err = b.state.SendMessageComplex(
chID,
api.SendMessageData{
Content: content,
Files: files,
},
)
if err != nil {
return err
}
return nil
}
func respondError(msg string) *api.InteractionResponseData {
if msg == "" {
panic("bot: blank string given to respondError")
}
msg = "❌ " + msg
return &api.InteractionResponseData{
Content: option.NewNullableString(msg),
Flags: discord.EphemeralMessage,
}
}
func respondErrorf(msg string, args ...interface{}) *api.InteractionResponseData {
if msg == "" {
panic("bot: blank string given to respondErrorf")
}
msg = fmt.Sprintf(msg, args...)
return respondError(msg)
}
func respondSilent(msg string) *api.InteractionResponseData {
if msg == "" {
panic("bot: blank string given to respondSilent")
}
return &api.InteractionResponseData{
Content: option.NewNullableString(msg),
Flags: discord.EphemeralMessage,
}
}
func respondSilentf(msg string, args ...any) *api.InteractionResponseData {
msg = fmt.Sprintf(msg, args...)
return respondSilent(msg)
}
func respond(msg string) *api.InteractionResponseData {
if msg == "" {
panic("bot: blank string given to respond")
}
return &api.InteractionResponseData{
Content: option.NewNullableString(msg),
}
}
func respondf(msg string, args ...interface{}) *api.InteractionResponseData {
if msg == "" {
panic("bot: blank string given to respondf")
}
msg = fmt.Sprintf(msg, args...)
return &api.InteractionResponseData{
Content: option.NewNullableString(msg),
}
}
func respondEmbeds(embeds ...discord.Embed) *api.InteractionResponseData {
if len(embeds) == 0 {
panic("bot: no embeds were given to respondEmbeds")
}
return &api.InteractionResponseData{
Embeds: &embeds,
}
}
func respondImage(name string, image io.Reader) *api.InteractionResponseData {
if image == nil {
panic("bot: nil reader given to respondImage")
}
files := make([]sendpart.File, 0)
files = append(files, sendpart.File{
Name: name,
Reader: image,
})
return &api.InteractionResponseData{
Files: files,
}
}