-
Notifications
You must be signed in to change notification settings - Fork 1
/
user_query.go
53 lines (45 loc) · 1.23 KB
/
user_query.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
package api
import (
"fmt"
"github.com/BOOMfinity/bfcord/api/builders"
"github.com/valyala/fasthttp"
"github.com/BOOMfinity/bfcord/discord"
"github.com/andersfylling/snowflake/v5"
)
type UserQuery struct {
client *Client
emptyOptions[discord.UserQuery]
id snowflake.ID
}
func (u UserQuery) Get() (user *discord.User, err error) {
req := u.client.New(true)
req.SetRequestURI(fmt.Sprintf("%v/users/%v", FullApiUrl, u.id))
err = u.client.DoResult(req, &user)
return
}
func (u UserQuery) Send() (bld discord.CreateMessageBuilder, err error) {
channel, err := u.CreateDM()
if err != nil {
return nil, err
}
return builders.NewCreateMessageBuilder(channel.ID), nil
}
func (u UserQuery) ID() snowflake.ID {
return u.id
}
func (u UserQuery) CreateDM() (channel *discord.Channel, err error) {
req := u.client.New(true)
req.SetRequestURI(fmt.Sprintf("%v/users/@me/channels", FullApiUrl))
req.SetBodyString(fmt.Sprintf(`{"recipient_id": %v}`, u.id))
req.Header.SetMethod(fasthttp.MethodPost)
err = u.client.DoResult(req, &channel)
return
}
func NewUserQuery(client *Client, id snowflake.ID) *UserQuery {
data := &UserQuery{
id: id,
client: client,
}
data.emptyOptions = emptyOptions[discord.UserQuery]{data: data}
return data
}